BlockoS / arduino-dataflash

Support for Atmel Dataflash for the Arduino
http://blockos.github.com/arduino-dataflash
23 stars 14 forks source link

Problem with pageRead() #15

Open battosai30 opened 8 years ago

battosai30 commented 8 years ago

Hi,

I'm working on porting your library to Energia (MSP430 Arduino like IDE). Another point : it's a version E (not a D but what are the differences ?)

After very few changements, seems to be OK except one point : pageRead() does not work reading page 0.And I can't explain why ... It's ok this other pages or using pageToBuffer()+bufferRead().

BlockoS commented 8 years ago

I quickly looked at the dataflash e version datasheet. It seems they added some new continuons read modes, and maybe they fixed chip erase... It also seems that page 0 is split in 2. I'll check it in more details tomorrow. I misread it. It's sector 0 not page 0 that is split in 2.

BlockoS commented 8 years ago

I can't see why reading page 0 fails with pageRead... The only difference with the pageToBuffer+bufferRead combo is the active wait. Maybe this may help:

dataflash.waitUntilReady(); // Just to be sure. Maybe this should be added at the begging of pageRead
dataflash.pageRead(0, 0); 
for(size_t i=0; i<PAGE_SIZE; i++) // page/buffer size accessors should be added to the API...
{
    data = SPI.transfer(0xff);
}
dataflash.end();

Unfortunately I don't have any version E dataflash.

battosai30 commented 8 years ago

Thank you very much :)

You were right : dataflash.waitUntilReady() solved the problem. Another point : I noticed at the samed time that it works if the pageRead() loop is preceded by

Serial.print("The test = "); dataflash.pageToBuffer(0, 1);
dataflash.bufferRead(1, 0); Serial.print(SPI.transfer(0xff)); Serial.print(SPI.transfer(0xff)); Serial.println("");

To adapt you're library to msp430 I removed lines about Atmel SPI registers (could it cause that ?).

battosai30 commented 8 years ago

But the strange fact stay "why only on page 0??". If I write and read on pages 1 to XXX => no problem If I write and read on pages 0 to XXX => problem

BlockoS commented 8 years ago

The Atmel SPI register stuffs are just here to flush any pending interrupts during initialization and to quickly setup SPI registers when we call begin() (in case of multiple SPI devices).

Have you tried doing a pageRead on let's say the second page, then on page 0 ? I think page 0 fails because of some internal state stuffs. I didn't anything in the datasheet about some specific behaviours concerning page 0. A way to verify this will be to issue a pageToBuffer followed by a pageRead on the same page, and a pageToBuffer with a pageRead on 2 different pages. If the first one fails and the second one succeds, this may mean that changing to a different page blocks until the operation on the current page is finished.

I feel ashamed because I realized that this issue is linked to the now 5 years old issue #5

battosai30 commented 8 years ago

Don't feel ashamed, your library help me a lot :) this kind of chip is not very difficult to understand, but there are lot of commands with a special protocol to respect, so it's a big deal to get a full working lib.

I tried this :

 dataflash.pageRead(0, 0);
    printSPI();
    dataflash.pageRead(0, 0);
    printSPI();
...
void printSPI() {

  int j = 0;
   byte data;
    do
      {
         data = SPI.transfer(0xff);
        if(data != '\0')
          Serial.write(data);
        ++j;
      } while((data != '\0') && (j < 64)); 

}

Result : the first pageRead(0,0) fails, but the second works. If I add a dataflash.waitUntilReady(), both work. As you suggest, I think it's an internal timing issue, something like an index which takes time to be reset ...