2019-10-13 01:21 AM
I have just started working with Micro controller, I use stm32l496 .
I want to init RTC with LSI clock source and HCLK is 2MHz from MSI source. I configure RTC in stm32 cubemx but RTC is not working i.e. the time is set correctly but does not increase, always displaying the time set.
please guide me where my settings or code are incorrect.
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_SPI1_Init();
MX_LPTIM1_Init();
MX_RTC_Init();
/* USER CODE BEGIN 2 */
RTC_TimeTypeDef RTC_Time;
RTC_Time.Hours=2;
RTC_Time.Minutes=5;
RTC_Time.Seconds=10;
HAL_Delay(100);
HAL_RTC_SetTime(&hrtc,&RTC_Time,RTC_FORMAT_BIN);
while (1)
{
HAL_Delay(1000);
HAL_RTC_GetTime(&hrtc,&RTC_Time,RTC_FORMAT_BIN);
AA_Hour=RTC_Time.Hours;
AA_Minute=RTC_Time.Minutes;
AA_Second=RTC_Time.Seconds;
sprintf(AA_str,"Hour=%d\r\n",AA_Hour);
HAL_UART_Transmit(&huart1,(uint8_t *)AA_str,strlen(AA_str),100);
sprintf(AA_str,"Min=%d\r\n",AA_Minute);
HAL_UART_Transmit(&huart1,(uint8_t *)AA_str,strlen(AA_str),100);
sprintf(AA_str,"Sec=%d\r\n",AA_Second);
HAL_UART_Transmit(&huart1,(uint8_t *)AA_str,strlen(AA_str),100);
}
}