Go Down

Topic: AT45DB dataflash library problems with timer2 interrupt (Read 1 time) previous topic - next topic

Coding Badly

Sorry if it came across the wrong way but I really do need help.


Excellent.  In that case please answer the question in Reply #1.

fbriggs4

I misunderstood your question the first time, hopefully this answers you properly. This is the complete sketch with the interrupt handler included.

Code: [Select]


#include <dataflash.h>

int page = 0;
int buffer = 1;
char messageline[60] = "#This is a test string for the flash memory";
char readFlash[60];
Dataflash dflash;
int i = 0;
volatile int seconds = 0; //used to keep time


SIGNAL(TIMER2_OVF_vect){
  seconds++;
}


void setup(){
  //Setup TIMER2
  TCCR2A = 0x00;
  TCCR2B = (1<<CS22)|(1<<CS21)|(1<<CS20); //Set CLK/1024 or overflow interrupt every 8s
  ASSR = (1<<AS2); //Enable asynchronous operation, 32kHz xtal needed
  TIMSK2 = (1<<TOIE2); //Enable the timer 2 interrupt. If this is disabled the sketch works properly

  sei(); //Enable global interrupts
   
  pinMode(A3, OUTPUT); //Flash VCC
  digitalWrite(A3, HIGH); //powers the flash memory up
  delay(4000);
 
  Serial.begin(9600);
  Serial.println("starting the sketch now");
  dflash.init(); //initialize the memory (pins are defined in dataflash.cpp
}

void loop(){
  writeData();
  readData();
  page++;
   
  delay(1000); //keep it from running so quickly in testing
}


void writeData(){
  Serial.print("I am writing page ");
  Serial.println(page);
  i = 0;
  while (i < 60){
    dflash.Buffer_Write_Byte(1, i, messageline[i]);  //write to buffer 1, 1 byte at a time
    i++;
  }
 
  dflash.Buffer_To_Page(1, page); //write the buffer to the memory on page: page
}

void readData(){
  Serial.print("reading page ");
  Serial.println(page);
  dflash.Page_To_Buffer(page, buffer);//copy page to the buffer
 
  i = 0;
  while(i < 60){
    readFlash[i] = dflash.Buffer_Read_Byte(buffer, i); //read the buffer
    i++;
  }
  Serial.println(' ');
  Serial.println(readFlash); //print what was read from the buffer
}



Coding Badly



Coding Badly


Are you getting a compiler error with the dataflash library?  Something about[font=Courier New] WConstants.h [/font]not found.

Go Up