cancel
Showing results for 
Search instead for 
Did you mean: 

rtc bug stm32 cube l0

jmarkose_i3trainee
Associate
Posted on September 17, 2015 at 07:41

Hello,

I have implemented RTC on STM32l053-Nucleo using CubeMX and CubeL0 HAL libraries. I set and get the time and date in RTC using HAL functions but the RTC is not running, I am getting the same time and date I have set. The crystal oscillator connected to RTC as showed in CubeMX is LSI. My IDE is Keil MDK-5. I have posted my RTC initialization function and main function below (main.c is attached).

/****************************** RTC init function **********************/

void MX_RTC_Init(void)

{

    /**Initialize RTC and set the Time and Date

    */

  hrtc.Instance = RTC;

  hrtc.Init.HourFormat = RTC_HOURFORMAT_12;

  hrtc.Init.AsynchPrediv= 127;

  hrtc.Init.SynchPrediv= 255;

  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_PC13;

  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

  HAL_RTC_Init(&hrtc);

}

**********************MAIN FUNCTION********************

int main(void)

{

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_RTC_Init();

  MX_USART2_UART_Init();

/***********************RTC*********************/

    RTC_TimeTypeDef sTime;

  RTC_DateTypeDef sDate;

  RTC_AlarmTypeDef sAlarm;

    

        

  sTime.Hours = 9;

  sTime.Minutes = 30;

  sTime.Seconds = 0;

  sTime.SubSeconds = 0;

  sTime.TimeFormat = RTC_HOURFORMAT12_AM;

  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sTime.StoreOperation = RTC_STOREOPERATION_RESET;

  HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD);

  sDate.WeekDay = RTC_WEEKDAY_MONDAY;

  sDate.Month = RTC_MONTH_AUGUST;

  sDate.Date = 24;

  sDate.Year = 15;

  HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BCD);

    /**Enable the Alarm A

    */

  sAlarm.AlarmTime.Hours = 0;

  sAlarm.AlarmTime.Minutes = 0;

  sAlarm.AlarmTime.Seconds = 0;

  sAlarm.AlarmTime.SubSeconds = 0;

  sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;

  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

  sAlarm.AlarmMask = RTC_ALARMMASK_NONE;

  sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;

  sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;

  sAlarm.AlarmDateWeekDay = 1;

  sAlarm.Alarm = RTC_ALARM_A;

  HAL_RTC_SetAlarm(&hrtc, &sAlarm, FORMAT_BCD);

    

    RTC_TimeTypeDef gTime;

    char str[100];

    

  while (1)

  {

        HAL_RTC_GetTime(&hrtc, &gTime, FORMAT_BCD);

        

        sprintf(str, ''Time -> %d:%d:%d (sub seconds: %d)\n'',sTime.Hours, sTime.Minutes, sTime.Seconds, sTime.SubSeconds);

        HAL_UART_Transmit(&huart2, str, 100, 5000);

        HAL_Delay(1000);

  }

}

1 REPLY 1
Posted on September 17, 2015 at 11:18

Post the content of relevant RCC and RTC registers.

JW