BlockoS / arduino-dataflash

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

pageTest.ino error: test/Dummy.h: No such file or directory #17

Closed perigalacticon closed 6 years ago

perigalacticon commented 7 years ago

I tried to compile the pageTest sketch for Uno and it gave the error:

test/Dummy.h: No such file or directory

Here is the full output:

C:\Program Files (x86)\Arduino\libraries\arduino-dataflash\DataFlash_test.cpp:4:24: fatal error: test/Dummy.h: No such file or directory

 #include "test/Dummy.h"

                        ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.
BlockoS commented 7 years ago

Remove Dataflash_test.cpp from your imported files. It's a standalone test program and it may interfer with the exemple sketches.

I should have put it in a dedicated directory.

perigalacticon commented 7 years ago

Should this library work with the AT45DB011D? I'm not getting correct results with it.

BlockoS commented 7 years ago

Yes it should. Can you paste the result of the pageTest example? In particular what's printed during setup (status register, manufacturer id, device id, etc...).

perigalacticon commented 7 years ago

Ok Thanks. I checked in the datasheet for device 22 (b00010110) it is the AT45DB011D (1Mb). I tried 2 different chips. I uploaded the exact sketch I am using to: https://drive.google.com/open?id=0B-jN2Adg-YnuWEdpYzQ4UUsyUmc so there's no chance for discrepancy, except I just noticed I have the CS pin set to 10 in my sketch not 5. I'm using IDE 1.8.3.

Status register :10001101
Manufacturer ID :
1F
Device ID (part 1) :
22
Device ID (part 2)  :
0
Extended Device Information String Length  :
0
Page read
200253235255188115125167231247100114832541747111073136292157561146231191851033025512829162233222153241123629911252127247251217792212461392251491601461313426242188238672645250Page to buffer
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255254Page read
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255255Page to buffer
255255255255255255255255255255255255255255255255255255255255255255255255255255255255255130Page read

...

BlockoS commented 7 years ago

Ok. Can you try this instead of pageTest? I fear pageTest.pde needs some rework... Unfortunately I don't have my gear right now.

#include <SPI.h>
#include "DataFlash.h"

DataFlash dataflash;
uint16_t  page;

void setup()
{   
  uint8_t status;
  DataFlash::ID id;

  /* Initialize SPI */
  SPI.begin();

  /* Let's wait 1 second, allowing use to press the serial monitor button :p */
  delay(1000);

  /* Initialize dataflash */
  dataflash.setup(5,6,7);

  delay(10);

  dataflash.begin();

  /* Read status register */
  status = dataflash.status();

  /* Read manufacturer and device ID */
  dataflash.readID(id);

  /* Set baud rate for serial communication */
  Serial.begin(115200);

  /* Display status register */
  Serial.print("Status register :");
  Serial.print(status, BIN);
  Serial.print('\n');

  /* Display manufacturer and device ID */
  Serial.print("Manufacturer ID :\n");  // Should be 00011111
  Serial.print(id.manufacturer, HEX);
  Serial.print('\n');

  Serial.print("Device ID (part 1) :\n"); // Should be 00011111
  Serial.print(id.device[0], HEX);
  Serial.print('\n');

  Serial.print("Device ID (part 2)  :\n"); // Should be 00000000
  Serial.print(id.device[1], HEX);
  Serial.print('\n');

  Serial.print("Extended Device Information String Length  :\n"); // 00000000
  Serial.print(id.extendedInfoLength, HEX);
  Serial.print('\n');

  //--------------------------------------------------------------------
  static const char message[] = 
"The End, Fredric Brown 1961\n\n"
"Professor Jones had been working on time theory for many years.\n"
"  \"And I have found the key equation,\" he told his daughter one\n"
"day. \"Time is a field. This machine I have made can manipulate,\n"
"even reverse, that field.\"\n\n"
"  Pushing a button as he spoke, he said, \"This should make time\n"
"run backward backward run time make should this,\" said he,\n"
"spoke he as button a pushing.\n\n"
"  \"Field that, reverse even, manipulate can made have I machine\n"
"this. Field is a time.\" Day one daughter his told he, \"Equation\n"
"key the found have I and.\"\n\n"
"\"Years many for theory time on working been had Jones\n"
"Professor.\"\n";

  const int message_len = sizeof(message);
  int i, j;

  for(i=0, page=0; i<message_len; page++)
  {
    dataflash.bufferWrite(0, 0);
    for(j=0; (i<message_len) && (j<256); j++, i++)
    {
      SPI.transfer(message[i]);
    }
    dataflash.bufferToPage(0, page);
  }

  for(i=0, page=0; i<message_len; page++)
  {
    dataflash.pageToBuffer(page, 1);    
    dataflash.bufferRead(1, 0);
    for(j=0; (i<message_len) && (j<256); j++, i++)
    {
      data = SPI.transfer(0xff);
      if(data != '\0')
        Serial.print(data);
    }
  }

  dataflash.end();
  //--------------------------------------------------------------------
}

void loop()
{
  // nothing
}
perigalacticon commented 7 years ago

Thanks. Here's the output:

Status register :10001101
Manufacturer ID :
1F
Device ID (part 1) :
22
Device ID (part 2)  :
0
Extended Device Information String Length  :
0
2552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552556412552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552481625525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525525532
BlockoS commented 7 years ago

Ok... Just checked the datasheet and unlike the other AT45DB chips, the AT45DB011D has only one buffer. So the buffer number for any buffer op must be 0. Does it work better by using this in the read loop?

    dataflash.pageToBuffer(page, 0);    
    dataflash.bufferRead(0, 0);
perigalacticon commented 7 years ago

Output:

Status register :10001101
Manufacturer ID :
1F
Device ID (part 1) :
22
Device ID (part 2)  :
0
Extended Device Information String Length  :
0
The End, Fredric Brown 1961

Professor Jones had been working on time theory for many years.
  "And I have found the key equation," he told his daughter one
day. "Time is a field. This machine I have made can manipulate,
even reverse, that field."

  Pushing a button as he spoke, he said, "This should make time
run backward backward run time make should this," said he,
spoke he as button a pushing.

  "Field that, reverse even, manipulate can made have I machine
this. Field is a time." Day one daughter his told he, "Equation
key the found have I and."

"Years many for theory time on working been had Jones
Professor."

Beautiful. Thank you very much. You also need to declare data as char type FYI.

So I have a question - this is my first time using SPI - it appears the transfer speed, often quoted in the range of many MHz - this speed is determined only by how rapidly you can call SPI.transfer? Does this loop actually determine the actual SCK clock speed?

Thanks!

perigalacticon commented 7 years ago

In pageTest if I change to pageRead instead of pageToBuffer incorrect data is returned. It seems the first time pageRead is called it reads from a random page, but the second time it is called for the same page it reads it correctly. See my test sketch and output files attached.

arduino-dataflash_example_ino.txt

arduino-dataflash_example_output.txt

BlockoS commented 7 years ago

Not at all. The SCK clock speed is set up via the SPI module. Nevertheless you can send data at a lower speed.

About the pageread issue, remove all the dataflash.end() in the loop. This method disables the dataflash in order to use another SPI device (daisy chain).

perigalacticon commented 7 years ago

Thanks. Removing the dataflash.end() commands from the loop didn't work for the test sketch it still seems to print from a random page first time.

BlockoS commented 7 years ago

Hum... weird... Maybe you have to call waitUntilReady before the first pageread.

perigalacticon commented 7 years ago

I needed to include a 18ms delay after the page write for proper function. Adding dataflash.waitUntilReady(); just before the read gives a 15ms delay for the first read.

BlockoS commented 7 years ago

According to the datasheet, "Page Erase and Programming Time" takes 14 to 35ms, but it also states that during this time the status register will remain busy...

Can you remove the delay and print the value of the dataflash status register before the pageRead ?

That's weird.

perigalacticon commented 7 years ago

15ms is the elapsed time when using dataflash.waitUntilReady(); without any delay() statements, Everything is fine.

BlockoS commented 7 years ago

So everything is ok now?

perigalacticon commented 7 years ago

Thanks for your continued support. I would like to use the arrayRead() method for rapidly reading sequential values. However I find that the data returned from certain pages (starting at address 512, page 3) is not from the expected page. I have tried waitUntilReady() here but this does not fix the problem. Here are the input and output files:

arduino-dataflash_example_841_ino.txt arduino-dataflash_example_841_output.txt

perigalacticon commented 7 years ago

There may be a problem with this section of arrayRead() (starting line 366):

    /* Address (page | offset)  */
    SPI.transfer(pageToHiU8(page));  
    SPI.transfer(pageToLoU8(page) | (uint8_t)(offset >> 8)); 
    SPI.transfer((uint8_t)(offset & 0xff)); 

I looked into the pageToHiU8() and pageToLoU8() functions:

inline uint8_t DataFlash::pageToHiU8(uint16_t page) const
{
    return page >> (16 - m_bufferSize);  **= 0**
}
inline uint8_t DataFlash::pageToLoU8(uint16_t page) const
{
    return page << (m_bufferSize  - 8);  **=  (page  << 1)**
}

For the AT45DB011D, I calculate the following:

stat = status();  = 10001101
uint8_t deviceIndex = ((stat & 0x38) >> 3) - 1;   **= 0**
m_bufferSize   = m_infos.bufferSize[deviceIndex];  **= 9**

This gives the following result in arrayRead():

    /* Address (page | offset)  */
    SPI.transfer(pageToHiU8(page));  **-->  SPI.transfer(0);**
    SPI.transfer(pageToLoU8(page) | (uint8_t)(offset >> 8));  **-->  SPI.transfer(page  << 1);**
    SPI.transfer((uint8_t)(offset & 0xff));  **-->  SPI.transfer(0);**

I don't understand how this section works, but do you think it's correct?

BlockoS commented 7 years ago

Arg! I realize that the current code only supports 264 bytes pages. As the bit 0 of your status register is set, this means the page size is set to 256. So m_buffersize should be 8 and not 9... A quick hack should be to decrease m_buffersize if the bit 0 of the status register is set in the constructor.

perigalacticon commented 7 years ago

Yes it is working correctly now, thanks!