I run into problems with EEPROM.h use with the Teensy 4.0. I would like to use the EEPROM to save about 800bytes.
The code below runs for (about) the first 20 EEPROM adresses, but fails with more. Additionally, the problem is not consistent, but the program fails to even print the first message to Serial when EEPROM_limit is too high. And the limit of 20 also seems to be a bit inconsistent, sometimes 19 is possible, sometimes not, sometimes 21 is possible, sometimes not. Am I doing something wrong?
Maybe the EEPROM.write writes the code to the flash where also program code is stored? Do I need to use other EEPROM adresses with the T4?
Code:
// Arduino 1.8.9, Teensyduino 1.47
// Teensy 4.0
// EEPROM problem
// which adresses to use?
// does the EEPROM write overwrite parts of the FLASH where the program is situated?
// it does not even print the "Before writing"-message, if I set EEPROM_limit above 20 . . . ???
// it seems the exact limit is flexible, gets me confused
#include <EEPROM.h>
// this works up to 20, but fails from 21 and higher
#define EEPROM_LIMIT 50
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
delay(1000);
Serial.println("Before writing");
for(unsigned i = 0; i < EEPROM_LIMIT; i++)
{
EEPROM.write(i, 42);
}
Serial.println("After writing");
for(unsigned i = 0; i < EEPROM_LIMIT; i++)
{
int r = EEPROM.read(i);
Serial.print(i);
Serial.print(") ");
Serial.println(r);
}
}
void loop() {
// put your main code here, to run repeatedly:
}