// arduino-dataflash example // #include #include "DataFlash.h" DataFlash dataflash; uint16_t flashPage; // dataflah page #. uint8_t dataWrite; // value stored in dataflash. uint8_t dataRead; // value stored in dataflash. unsigned int i, j; // indices for retrieving data values. uint16_t dataStart = 0; uint16_t dataEnd = 5; //============================================================================================================================= void setup() { uint8_t status; DataFlash::ID id; Serial.begin(115200); SPI.begin(); dataflash.setup(10, 6, 7); delay(10); dataflash.begin(); status = dataflash.status(); dataflash.readID(id); Serial.print("Status register :"); Serial.print(status, BIN); Serial.print('\n'); /* Display manufacturer and device ID */ Serial.print("Manufacturer ID :\n"); Serial.print(id.manufacturer, HEX); Serial.print('\n'); Serial.print("Device ID (part 1) :\n"); Serial.print(id.device[0], HEX); Serial.print('\n'); Serial.print("Device ID (part 2) :\n"); Serial.print(id.device[1], HEX); Serial.print('\n'); Serial.print("Extended Device Information String Length :\n"); Serial.print(id.extendedInfoLength, HEX); Serial.print('\n'); } //============================================================================================================================= void loop() { dataflash.bufferWrite(0, 0); for (dataWrite = dataStart; dataWrite < dataEnd; dataWrite++) // send data to buffer: { SPI.transfer(dataWrite); // send the number "100". Serial.print("transfer to buffer, dataWrite = "); Serial.println(dataWrite); } Serial.print("transfer buffer to flash, page = "); Serial.println(flashPage); dataflash.bufferToPage(0, flashPage); // transfer buffer to dataflash page. dataStart += 5; // increment the values to be transferred: dataEnd += 5; flashPage++; if (flashPage > 4) // after writing to 5 pages read back the data from flash: { for (i = 0; i < 5; i++) { // dataflash.pageToBuffer(i, 0); // dataflash.bufferRead(0, 0); dataflash.pageRead(i, 0); Serial.print("page read = "); Serial.println(i); for (j = 0; j < 10; j++) { dataRead = SPI.transfer(0xff); Serial.print("data address = "); Serial.print("\t"); Serial.print(j); Serial.print("\t"); Serial.print("i = "); Serial.print("\t"); Serial.print(i); Serial.print("\t"); Serial.print("j = "); Serial.print(j); Serial.print("\t"); Serial.print("data value read = "); Serial.print("\t"); Serial.println(dataRead); } } dataflash.end(); // re-read first page: dataflash.pageRead(0, 0); // dataflash.pageToBuffer(0, 0); // dataflash.bufferRead(0, 0); Serial.print("RE-READ pageRead(0,0) = "); Serial.println(0); for (j = 0; j < 10; j++) { dataRead = SPI.transfer(0xff); Serial.print("data address = "); Serial.print("\t"); Serial.print(j); Serial.print("\t"); Serial.print("i = "); Serial.print("\t"); Serial.print(i); Serial.print("\t"); Serial.print("j = "); Serial.print(j); Serial.print("\t"); Serial.print("data value read = "); Serial.print("\t"); Serial.println(dataRead); } dataflash.end(); // re-read first page again: dataflash.pageRead(0, 0); // dataflash.pageToBuffer(0, 0); // dataflash.bufferRead(0, 0); Serial.print("RE-READ AGAIN pageRead(0,0) = "); Serial.println(0); for (j = 0; j < 10; j++) { dataRead = SPI.transfer(0xff); Serial.print("data address = "); Serial.print("\t"); Serial.print(j); Serial.print("\t"); Serial.print("i = "); Serial.print("\t"); Serial.print(i); Serial.print("\t"); Serial.print("j = "); Serial.print(j); Serial.print("\t"); Serial.print("data value read = "); Serial.print("\t"); Serial.println(dataRead); } dataflash.end(); flashPage = 0; dataStart = 0; dataEnd = 5; } } //=============================================================================================================================