2014-09-04 02:04 PM
I'm writing an app, that most of its time will spend in STOP or STANDBY mode (battery powered microsystem). I'd like the internal RTC to wakeup my STM32 every 5 minutes, enter the ISR, do its tasks in ISR (ADC measurement and send it over) and enter back the STOP mode.
My question is: how to do it nice and simple?
I tried with RTC alarm interrupt, but when I set 5 minutes in the alarm register, the interrupt run every 10 minutes (5 min, 15 min, 25 min and so on... - actually I had tested with 5 seconds). I tried to reset the time register in the ISR, but it works only sometimes.
Could you give me some advice what's the best/most proper way to do a periodical wakeup in STM32F030?
2014-09-04 04:21 PM
Well using the RTC Alarm would seem like a reasonable approach, not sure why you have timing issues, and I don't see any example code, I might guess an issue with the prescaler, or bcd-vs-binary representations.
2014-09-05 02:47 AM
EDIT: I have solved my problem, it was the missing semicolon at the end of flag polling while in an ISR. Now I have antoher problem - I wrote a delay function, msDelay.
void
msDelay(uint32_t dlyTicks)
{
uint32_t curTicks;
curTicks = msTicks;
while
((msTicks - curTicks) < dlyTicks);
}
msTicks is declared as volatile uint32_t and incremented in SysTickHandler. When I try to use it in my ISR, the program stucks in it and can't return to main, so the interrupt is run only once. In main the msDelay function works well. Any ideas?
my code for an ISR:
void
RTC_IRQHandler(
void
)
{
static
uint32_t i = 1;
uint32_t cnt = 0;
printf
(
''int %d occured
''
, i++);
RTC->WPR = 0xCA;
// Disable the write protection for RTC registers
RTC->WPR = 0x53;
RTC->ISR |= RTC_ISR_INIT;
while
(!(RTC->ISR & RTC_ISR_INITF)); //here I had the missing semicolon
RTC->TR = (uint32_t)0x00000000;
// Set the RTC_TR register
RTC->ISR &= ~RTC_ISR_INIT;
// Exit initialisation mode
RTC->WPR = 0xFF;
// Disable the write protection for RTC registers
//msDelay(1000);
printf
(
''RTC->TR = %u
''
, RTC->TR);
EXTI->PR |= EXTI_PR_PR17;
RTC->ISR &= ~RTC_ISR_ALRAF;
}
EDIT2: I have noticed that while being in RTC ISR, msTicks is not incremented, ie. the SysTickHandler doesn't periodically interrupt the RTC ISR. I guess it has something to do with interrupt priorities... Am I right?
EDIT3: Found an answer.
[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/SysTick_Handler%20suspended%20during%20other%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=383]SysTick interrupt vs other interrupts
Sorry for bothering :)