Skip to content

STM32RTC in any mode halts CPU when used EEPROM in sketch too. #23

@HamidSaffari

Description

@HamidSaffari

Hi, It is weird but when I use EEPROM funcs with RTC, CPU hangs and freeze after trying to write EEPROM in loop(). and even restart do not bring it to the loop (maybe because have Attached battery) until I remove the rtc.begin() line once and then start and then write the rtc.begin() to repeat the same problem.
Both EEPROM and RTC work fine without other ones in sketch.
I even use lesser flash and shift EEPROM FLASH_BASE_ADDRESS back and forth but still the same.
After crashes it's hang on the EEPROM.write(addr,_byte) in my setup();
I used STM32F103RC and version 1.8.0 core and the last STM32RTC version.
Here is my code:

`

#include <LightChrono.h>
#include <STM32RTC.h>
#include <EEPROM.h>

#define LED_PIN PA8
STM32RTC& rtc = STM32RTC::getInstance();
uint8_t value = 10;
uint32_t lasttime;

void setup() {

pinMode(LED_PIN, OUTPUT);

rtc.setClockSource(STM32RTC::LSE_CLOCK);
rtc.begin(); // initialize RTC 24H format

}

void loop() {

Heartbeat(LED_PIN,2);

if(millis()-lasttime >= 2000){
if(value>=255) value=0;
else value++;
EEPROM.write(0, value);
lasttime=millis();
}

}

void Heartbeat(byte _ledPin, uint8_t ReduceSpeedFactor){
static LightChrono heartbeatChrono;
static unsigned long interval_millis = 50*ReduceSpeedFactor;
static int counter = 0;
static bool ledState = false;

if(heartbeatChrono.hasPassed(interval_millis,true)){	if(counter == 1){	digitalWrite(_ledPin, ledState);	interval_millis =(50*ReduceSpeedFactor);	ledState = !ledState;	}	else if(counter == 2){	digitalWrite(_ledPin, ledState);	interval_millis =(200*ReduceSpeedFactor);	ledState = !ledState;	}	else if(counter == 3){	digitalWrite(_ledPin, ledState);	interval_millis =(50*ReduceSpeedFactor);	ledState = !ledState;	}	else{	digitalWrite(_ledPin, ledState);	interval_millis =(750*ReduceSpeedFactor);	ledState = !ledState;	counter = 0;	}	counter++; } 

}
`

code.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions