Skip to content

Instantly share code, notes, and snippets.

@BlockoS
Created September 28, 2011 14:26
Show Gist options
  • Save BlockoS/1248074 to your computer and use it in GitHub Desktop.
Save BlockoS/1248074 to your computer and use it in GitHub Desktop.
DataFlash sector erase test
#include <SPI.h>
#include "DataFlash.h"
DataFlash dataflash;
uint8_t currentSector;
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.begin(5,6,7);
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');
uint8_t buffer = 0;
uint8_t page = 0;
// [todo::begin] for page=0; page<pagesPerSector; page++
{
dataFlash.BufferWrite(buffer, 0);
for(int j=0; j<bufferSize; j++) // [todo]
{
SPI.transfer( /* [todo] */ );
}
dataFlash.BufferToPage(buffer, page);
buffer ^= 1;
}
// [todo::end]
currentSector = 0;
dataFlash.SectorErase(currentSector);
dataFlash.BufferWrite(0, 0);
for(int i=0; i<bufferSize; i++) // [todo]
{
SPI.transfer(0x00);
}
// [todo::begin] for page=0; page<pagesPerSector; page++
{
int8_t res = ComparePageToBuffer(page, 0);
Serial.print("Page ");
Serial.print(page, HEX);
if(res)
{
Serial.print (" was succesfully erased.\n");
}
else
{
Serial.print (" was not properly erased.\n");
}
}
// [todo::end]
}
void loop()
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment