#include "at45db161d.h" #define NUM_PAGES 8 ATD45DB161D dataflash; uint8_t loop_cnt; uint16_t page; void setup() { uint8_t status; ATD45DB161D::ID id; /* Let's wait 1 second, allowing use to press the serial monitor button :p */ delay(1000); /* Initialize dataflash */ dataflash.Init(); delay(10); /* Read status register */ status = dataflash.ReadStatusRegister(); /* Read manufacturer and device ID */ dataflash.ReadManufacturerAndDeviceID(&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'); loop_cnt = 0; page = 0; } void loop() { unsigned int i,j; char message[] = "write test "; char overflow[] = "\nOVERFLOW!\n"; char buffer[64]; uint8_t data; /* We are going to write a simple text into buffer 1 */ itoa(loop_cnt, buffer, 10); /* Set dataflash so that any call to spi_tranfer will write the byte * given as argument to the Buffer 1 */ dataflash.BufferWrite(1, 0); /* Transfer the message */ for(i=0; message[i] != '\0'; ++i) { spi_transfer(message[i]); } /* Transfer the loop counter (as string) */ for(i=0; buffer[i] != '\0'; ++i) { spi_transfer(buffer[i]); } spi_transfer('\n'); ++loop_cnt; if(loop_cnt == 0) { /* loop_cnt overflow */ /* To celebrate this we write the string "\nOVERFLOW!\n" to Buffer 1 */ for(i=0; overflow[i] != '\0'; ++i) { spi_transfer(overflow[i]); } } /* Write '\0' to buffer 1. This will help us know that we must stop reading from it. */ spi_transfer('\0'); /* Transfer buffer 1 to 'page' page (with builtin erase) */ dataflash.BufferToPage(1, page, 1); ++page; /* When we wrote the number of pages we wanted (NUM_PAGES), we display their contents by * using 2 methods alternatively ; * - PageToBuffer + BufferRead * - PageRead */ if(page >= NUM_PAGES) { for(i=0; i