|
| 1 | +/* |
| 2 | + Reading and writing to flash using the EEPROM library |
| 3 | + By: Nathan Seidle |
| 4 | + SparkFun Electronics |
| 5 | + Date: June 24th, 2019 |
| 6 | + This example code is in the public domain. |
| 7 | +
|
| 8 | + SparkFun labored with love to create this code. Feel like supporting open source hardware? |
| 9 | + Buy a board from SparkFun! https://www.sparkfun.com/products/15376 |
| 10 | +
|
| 11 | + This example shows how to use the EEPROM get and put functions |
| 12 | + to read and write to EEPROM inside Artemis. |
| 13 | +
|
| 14 | + Artemis doesn't actually have EEPROM. Instead we are writing to a protected |
| 15 | + section of flash. 1028 bytes of flash are updated each time a variable is written. |
| 16 | + This can take up to 30ms. |
| 17 | + |
| 18 | + Page erase takes 15ms |
| 19 | + Write byte takes 30ms - This is much longer than Arduino that takes 3.3ms |
| 20 | + Float write across two words takes 30ms |
| 21 | + Update (no write) takes 1ms |
| 22 | +*/ |
| 23 | + |
| 24 | +#include <EEPROM.h> |
| 25 | + |
| 26 | +void setup() |
| 27 | +{ |
| 28 | + Serial.begin(9600); |
| 29 | + Serial.println("EEPROM Examples"); |
| 30 | + |
| 31 | + byte myValue1 = 200; |
| 32 | + EEPROM.put(0, myValue1); //(location, data) |
| 33 | + byte response1; |
| 34 | + EEPROM.get(0, response1); |
| 35 | + Serial.printf("Location %d should be %d: %d\n\r", 0, myValue1, response1); |
| 36 | + |
| 37 | + int myValue5 = -245000; //Note that ints are 4 bytes on the Artemis |
| 38 | + EEPROM.put(2, myValue5); |
| 39 | + int response5; |
| 40 | + EEPROM.get(2, response5); |
| 41 | + Serial.printf("Location %d should be %d: %d\n\r", 2, myValue5, response5); |
| 42 | + |
| 43 | + float myValue9 = -7.35; |
| 44 | + EEPROM.put(10, myValue9); |
| 45 | + float response9; |
| 46 | + EEPROM.get(10, response9); |
| 47 | + Serial.printf("Location %d should be %f: %f\n\r", 10, myValue9, response9); |
| 48 | +} |
| 49 | + |
| 50 | +void loop() |
| 51 | +{ |
| 52 | +} |
0 commit comments