Hi,
I have a calibration routine I want to run the first time the teensy 4.1 is turned on.
I figure i want to set a boot flag in eeprom, probably at address 0. Check whether this is set to (lets call it is_calibration_set for ease) is_calibration_set == 0, run calibration then set calibration flag to 1 so it no longer runs on subsequent bootups.
Problem I've got is, how do I ensure that the eeprom address is zero to start with. I dont know how to set to zero without it presumably always setting to zero on power up, thereby causing the calibration to always run. Can i be sure that an unwritten to EEPROM is actually blank and all zeros? Is there some kind of programming time directive that does something only at program time for eeprom?
I found some solutions which involve loading in an initialization sketch, but surely this is a common situation for many systems and there's a better solution. Or perhaps is there a way to automatically load an eeprom memory file when programming. Im using platformIO in vscode.
I found this snippet of code for an AVR which apparently solves the problem (I think its a totally different platform), but I don't see how this would get round that problem. Wouldnt this line:
uint16_t EEMEM SerialNumber = 0;
set the counter back to zero each time the device is turned on?
/*
* EEPROM_serialno.c
*
* Created: 12-Sep-16 14:55:51
* Author : David Prentice
*/
#include <avr/io.h>
#include <avr/eeprom.h>
uint16_t EEMEM SerialNumber = 0;
int main()
{
uint16_t wordRead = eeprom_read_word(&SerialNumber); // read the existing value
wordRead++; //increment it
eeprom_update_word(&SerialNumber, wordRead); //write to EEPROM
while (1) {
}
}
Thanks
I have a calibration routine I want to run the first time the teensy 4.1 is turned on.
I figure i want to set a boot flag in eeprom, probably at address 0. Check whether this is set to (lets call it is_calibration_set for ease) is_calibration_set == 0, run calibration then set calibration flag to 1 so it no longer runs on subsequent bootups.
Problem I've got is, how do I ensure that the eeprom address is zero to start with. I dont know how to set to zero without it presumably always setting to zero on power up, thereby causing the calibration to always run. Can i be sure that an unwritten to EEPROM is actually blank and all zeros? Is there some kind of programming time directive that does something only at program time for eeprom?
I found some solutions which involve loading in an initialization sketch, but surely this is a common situation for many systems and there's a better solution. Or perhaps is there a way to automatically load an eeprom memory file when programming. Im using platformIO in vscode.
I found this snippet of code for an AVR which apparently solves the problem (I think its a totally different platform), but I don't see how this would get round that problem. Wouldnt this line:
uint16_t EEMEM SerialNumber = 0;
set the counter back to zero each time the device is turned on?
/*
* EEPROM_serialno.c
*
* Created: 12-Sep-16 14:55:51
* Author : David Prentice
*/
#include <avr/io.h>
#include <avr/eeprom.h>
uint16_t EEMEM SerialNumber = 0;
int main()
{
uint16_t wordRead = eeprom_read_word(&SerialNumber); // read the existing value
wordRead++; //increment it
eeprom_update_word(&SerialNumber, wordRead); //write to EEPROM
while (1) {
}
}
Thanks