STM32C031 RTC domain / using LL library
ST moderator has edited this post to be compliant with the community rules. In next time please use </> button to paste your code. Thank you for your undersranding.
Hello collegues.
LL library.
Can you help with RTC domain in STM32C031T6. Problem is that, RTC start and counting, I set alarm A evry 1s. This wokrs fine. I'm counting moreless about 30min. After push the pin RESET, RTC starts counting from 0, I want to continue counting ? Initialization code below:
void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
LL_RTC_InitTypeDef RTC_InitStruct = {0};
LL_RTC_TimeTypeDef RTC_TimeStruct = {0};
LL_RTC_DateTypeDef RTC_DateStruct = {0};
LL_RTC_AlarmTypeDef RTC_AlarmStruct = {0};
if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSE)
{
FlagStatus pwrclkchanged = RESET;
if (LL_APB1_GRP1_IsEnabledClock (LL_APB1_GRP1_PERIPH_PWR) != 1U)
{
/* Enables the PWR Clock and Enables access to the backup domain */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
pwrclkchanged = SET;
}
//LL_RCC_ForceBackupDomainReset();
//LL_RCC_ReleaseBackupDomainReset();
LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_LOW);
LL_RCC_LSE_Enable();
/* Wait till LSE is ready */
while(LL_RCC_LSE_IsReady() != 1)
{
}
LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
/* Restore clock configuration if changed */
if (pwrclkchanged == SET)
{
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_PWR);
}
}
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTC);
LL_RCC_EnableRTC();
/* RTC interrupt Init */
NVIC_SetPriority(RTC_IRQn, 0);
NVIC_EnableIRQ(RTC_IRQn);
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR;
RTC_InitStruct.AsynchPrescaler = 127;
RTC_InitStruct.SynchPrescaler = 255;
LL_RTC_Init(RTC, &RTC_InitStruct);
RTC_DateStruct.WeekDay = LL_RTC_WEEKDAY_MONDAY;
RTC_DateStruct.Month = LL_RTC_MONTH_JANUARY;
RTC_DateStruct.Day = 0x1;
RTC_DateStruct.Year = 0x26;
LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_DateStruct);
if(LL_RTC_IsActiveFlag_INITS(RTC) == 0){
RTC_TimeStruct.Hours = 0x0;
RTC_TimeStruct.Minutes = 0x0;
RTC_TimeStruct.Seconds = 0x0;
LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_TimeStruct);
}
/** Enable the Alarm A
*/
RTC_AlarmStruct.AlarmTime.Hours = 0x0;
RTC_AlarmStruct.AlarmTime.Minutes = 0x0;
RTC_AlarmStruct.AlarmTime.Seconds = 0x0;
RTC_AlarmStruct.AlarmMask = LL_RTC_ALMA_MASK_ALL;
RTC_AlarmStruct.AlarmDateWeekDaySel = LL_RTC_ALMA_DATEWEEKDAYSEL_DATE;
RTC_AlarmStruct.AlarmDateWeekDay = 0x1;
LL_RTC_ALMA_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_AlarmStruct);
/* USER CODE BEGIN RTC_Init 2 */
/*Enable alram interaput, set 1s*/
LL_RTC_DisableWriteProtection(RTC);
LL_RTC_ALMA_Enable(RTC);
LL_RTC_EnableIT_ALRA(RTC);
LL_RTC_EnableWriteProtection(RTC);
}
A bit os code from main.c:
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
/* SysTick_IRQn interrupt configuration */
NVIC_SetPriority(SysTick_IRQn, 3);
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_RTC_Init();
MX_USART2_UART_Init();
LL_SYSTICK_EnableIT();
