From 72459052e05af14e260186f159da24545ac27f07 Mon Sep 17 00:00:00 2001 From: Felix Rusu Date: Tue, 12 Jan 2021 13:57:50 -0500 Subject: [PATCH] Create SPIFlash_Detect.ino --- examples/SPIFlash_Detect/SPIFlash_Detect.ino | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/SPIFlash_Detect/SPIFlash_Detect.ino diff --git a/examples/SPIFlash_Detect/SPIFlash_Detect.ino b/examples/SPIFlash_Detect/SPIFlash_Detect.ino new file mode 100644 index 0000000..f4d58e9 --- /dev/null +++ b/examples/SPIFlash_Detect/SPIFlash_Detect.ino @@ -0,0 +1,44 @@ +// Blink LED_BUILTIN slower if the FLASH chip is detected, and faster if there is no FLASH chip detected +// Code by Felix Rusu, LowPowerLab.com +#include //https://github.com/lowpowerlab/spiflash +#include + +#define SERIAL_ENABLE +#define BLINK_FAST_DELAY 100 +#define BLINK_SLOW_DELAY 500 + +SPIFlash flash(SS_FLASHMEM, 0xEF30); //EF40 for 16mbit windbond chip +int LEDTIME = 500; + +// the setup routine runs once when you press reset: +void setup() { +#ifdef SERIAL_ENABLE + Serial.begin(115200); + delay(4000); //wait a bit until SerialMonitor can be opened +#endif + pinMode(LED_BUILTIN, OUTPUT); + + if (flash.initialize()) { + Serial.println("SPI Flash Init OK!"); + LEDTIME = BLINK_SLOW_DELAY; + } + else + { + Serial.println("SPI Flash Init FAIL! (is chip soldered?)"); + LEDTIME = BLINK_FAST_DELAY; + } +} + +// the loop routine runs over and over again forever: +void loop() { + word jedecid = flash.readDeviceId(); +#ifdef SERIAL_ENABLE + Serial.print("FLASH DeviceID: "); + Serial.println(jedecid, HEX); + Serial.print("FLASH init "); Serial.println(flash.initialize() ? "OK" : "FAIL"); +#endif + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(LEDTIME); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(LEDTIME); // wait for a second +} \ No newline at end of file