Skip to content

Instantly share code, notes, and snippets.

@mix86
Created October 2, 2017 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mix86/c9af8a35f7a2761144f57e7377f88386 to your computer and use it in GitHub Desktop.
Save mix86/c9af8a35f7a2761144f57e7377f88386 to your computer and use it in GitHub Desktop.
SPI Flash Test
#include <SPIFlash.h>
#define BAUD_RATE 9600
#define WP 8
#define HOLD 9
#define LED 2
SPIFlash flash;
uint16_t page = 1;
uint8_t offset = 5;
uint8_t dataByte = 0;
int sensorValue = 0;
void setup() {
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
delay(10);
Serial.begin(BAUD_RATE);
Serial.print(F("Initialising Flash memory..."));
flash.begin();
Serial.println(flash.getJEDECID(), HEX);
digitalWrite(LED, LOW);
}
void loop() {
digitalWrite(LED, HIGH);
sensorValue = byte(analogRead(A0));
Serial.print(F("Random value: "));
Serial.println(sensorValue, HEX);
Serial.print(F("write..."));
flash.eraseSector(page, 0); //<-- Does not work without this line (WTF?)
flash.writeByte(page, offset, byte(sensorValue));
Serial.println(flash.error(), HEX);
delay(100);
Serial.print(F("read..."));
dataByte = flash.readByte(page, offset);
Serial.println(dataByte, HEX);
digitalWrite(LED, LOW);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment