2017-04-03 08:15 AM
Hello,
I am having issues with the Real Time clock. Occasionally it will miss its interrupt ( always when I stop the debugger )
I am not setting the date/time as I just want to have interrupt trigger a second from the current time
I have a catch so when I increment the seconds in the TR counter and it reaches 60 to set to zero so just want to make sure my code is correct
My code
uint32_t value = 0U;
// Disable the write protection for RTC registers RTC->WPR = 0xCAU; RTC->WPR = 0x53U;
// Disable the Alarm timer
RTC->CR &= ~(RTC_CR_ALRAE); // Clear flag Wake-Up RTC->ISR &= ~( RTC_ISR_ALRAF ); while((RTC->ISR & RTC_ISR_ALRAWF) != RTC_ISR_ALRAWF) /* (3) */ { /* add time out here for a robust application */ } RTC->ISR |= RTC_ISR_INIT; while((RTC->ISR & RTC_ISR_INITF) != RTC_ISR_INITF) /* (3) */ { /* add time out here for a robust application */ } value = ( RTC->TR ) ; value = RTCBcdToByteSeconds(value); value = value + 1; value = RTCByteToBcdSeconds( value ); // Configure the AlarmA //RTC->ALRMAR = RTC_ALRMAR_MSK4 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2 | RTC_ALRMAR_MSK1; RTC->ALRMAR = RTC_ALRMAR_MSK4 | RTC_ALRMAR_MSK3 | RTC_ALRMAR_MSK2 | value; //RTC->ALRMASSR = RTC_ALRMBSSR_MASKSS | ( RTC->SSR & RTC_ALRMASSR_SS );// Configure the Interrupt in the RTC_CR register
RTC->CR |= RTC_CR_ALRAIE; // Enable the Wakeup Timer RTC->CR |= RTC_CR_ALRAE;RTC->ISR &= ~(RTC_ISR_INIT);
// Enable the write protection for RTC registers RTC->WPR = 0xFFU;2017-04-03 08:32 AM
Hi
koss.david
,please refer to ready example under the
STM32F4xx_DSP_StdPeriph_Lib_V1.8.0\STM32F4xx_DSP_StdPeriph_Lib_V1.7.0\Project\STM32F4xx_StdPeriph_Examples\RTC
-Nesrine-