Closed perigalacticon closed 6 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.
Should this library work with the AT45DB011D? I'm not getting correct results with it.
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...).
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
...
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
}
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
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);
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!
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.
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).
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.
Hum... weird... Maybe you have to call waitUntilReady before the first pageread.
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.
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.
15ms is the elapsed time when using dataflash.waitUntilReady(); without any delay() statements, Everything is fine.
So everything is ok now?
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
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?
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.
Yes it is working correctly now, thanks!
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: