DataFlash and Buffers

Newbie here, and not an electronics whiz, either, so please bear with me!

I’ve got an Arduino paired up with an Atmel DataFlash chip from SparkFun and wish to toggle from buffer 1 to buffer 2 to allow for the slight delay in writing the buffer contents to the assigned page. I noticed a post back in 2008 where someone had a problem with buffer 2 not working, and I’m wondering if this is a common hardware problem or if there’s a simple software command that I’m not implementing.

  for (int p=0; p<=9; p=p+2)              // 10 pages to store 2560 numbers (4095 pages will hold 2M numbers)
  {
    for (int i=0; i<=183; i=i+2)        
    {
      frontPosition = analogRead(frontPotPin)/4;    // read position data
      dflash.Buffer_Write_Byte(1,i,frontPosition);   //write position value to buffer #1 address i 
    }
    dflash.Buffer_To_Page(1,p);          //write buffer 1 contents to page "p"
    
    for (int i=0; i<=183; i=i+2)         
    {
      frontPosition = analogRead(frontPotPin)/4;    // read position data
      dflash.Buffer_Write_Byte(2,i,frontPosition);   //write position value to buffer #2 address i 
    }
    dflash.Buffer_To_Page(2,p+1);          //write buffer 2 contents to page "p"
  }

I’ve been running this routine within my main program with success for buffer 1, but I’m not succeeding in writing nor reading to or from buffer 2 (different code for reading the DataFlash chip).

Anyone got time to give a helping hand?

Hi, this (write to buffer 2 while buffer 1 is busy) can't work.

From the datasheet section "7.2 Buffer to Main Memory Page Program with Built-in Erase" :

Both the erase and the programming of the page are internally self-timed and should take place in a maximum time of tEP. During this time, the status register and the RDY/BUSY pin will indicate that the part is busy.

While the dataflash is busy shuffling the data from buffer 1 into the flashrom it can do nothing else.

Eberhard

Thanks for the tip. I was under the impression that the Buffer-to-Page write process was "internally" managed and would allow one buffer to dump its contents while I accessed the other. I could change my strategy and use something else (Arduino RAM?) as a temporary buffer while the DataFlash chip was doing its thing.

BTW, my goal is to have a seamless record of the input from one of my analog pins. Currently, there's a disruption when the DataFlash chip is writing the buffer contents to the assigned page.

While the dataflash is busy shuffling the data from buffer 1 into the flashrom it can do nothing else.

Not exactly. Atmel app note AN-4 says

NOTE: While the state machine is busy transferring data from one buffer to the main memory page, the other buffer may be read from or written to.

The way I read it, you should be able to use the other buffer even while the flash (and therefore the status bit) is busy.

If this was not the case, it would be pretty pointless to have two buffers.

-j

It took me a few hours to come to the same thought: why are there two buffers if you can't use them that way?

This means I return to my original question: how does one execute this back-and-forth use of the two buffers? I haven't seen any examples of code that use this method. Has anyone out there tried this yet?

how does one execute this back-and-forth use of the two buffers?

My guess is you fill up a buffer, initiate a buffer -> flash write, begin filling up the other buffer, keeping an eye on the status bit before initiating the next buffer -> flash write.

i.e., ignore the busy bit for host/buffer operations - you only care about the status for operations involving flash.

time for me to go pull out that shield or breakout or whatever it was I put together to prototype with the dataflash. I've got another project coming up that I think will need it.

-j

Ah, therein lies the rub. You mention initiating a buffer-to-flash write and then begin filling up the other buffer. My code indeed does this. However, I don't have a clue as to how to track the status bit before initiating the next buffer-to-flash write.

BTW, to keep things in perspective, I'm using the dataflash library available for the Arduino, and I'm not so good at lower-level stuff, especially not C++ stuff. I'm just a determined hobbyist trying to push these things as fast as they can go.

And doing a search through past posts, I dug up a related comment...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259507201/4

I think one of my past searches uncovered this post and led me down the path of using a DataFlash chip in the first place...

Two ways to do it: first, with hardware - there's a ready/busy pin. Hook it up and do a digitalRead() on it.

Second, using the library on the playground, there's a function called Read_DF_status(). Check bit 7 of the byte it returns. If that bit is 1 the device is ready for the next operation. e.g.

if (Read_DF_status() & 0x80)
{
    // ready to issue net write operation
}

-j

Now that's useful info.

After doing further digging, I came across these items:

define Buf1Write 0x84 // Buffer 1 write

define Buf2Write 0x87 // Buffer 2 write

These are within the "dataflash.h" file contained in the DataFlash library for the Arduino. I've no idea how to implement these elements, but following your "Read_DF_status" tip might lead me down the path of enlightenment when it comes to using these tidbits.