cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f429 external rtc

er3481
Senior
Posted on September 21, 2016 at 15:30

Hi,

I am using stm32f429ZIT6 mcu for my own board. I want to create 1 second interrupt with external 32.768Khz rtc but it doesn't work. My Systemclock config and rtc init functions are below:

void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct;

  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

  __HAL_RCC_PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.LSEState = RCC_LSE_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLM = 20;

  RCC_OscInitStruct.PLL.PLLN = 336;

  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

  RCC_OscInitStruct.PLL.PLLQ = 7;

  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_RTC;

  PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;

  PeriphClkInitStruct.PLLSAI.PLLSAIR = 6;

  PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_4;

  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;

  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  /* SysTick_IRQn interrupt configuration */

  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

void MX_RTC_Init(void)

{

  RTC_TimeTypeDef sTime;

  RTC_DateTypeDef sDate;

  RTC_AlarmTypeDef sAlarm;

    /**Initialize RTC and set the Time and Date 

    */

  hrtc.Instance = RTC;

  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

  hrtc.Init.AsynchPrediv = 127;

  hrtc.Init.SynchPrediv = 255;

  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

  HAL_RTC_Init(&hrtc);

  sTime.Hours = 0x0;

  sTime.Minutes = 0x0;

  sTime.Seconds = 0x0;

  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_SUB1H;

  sTime.StoreOperation = RTC_STOREOPERATION_RESET;

  HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);

  sDate.WeekDay = RTC_WEEKDAY_TUESDAY;

  sDate.Month = RTC_MONTH_SEPTEMBER;

  sDate.Date = 0x19;

  sDate.Year = 0x16;

  HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);

    /**Enable the Alarm A 

    */

  sAlarm.AlarmTime.Hours = 0x0;

  sAlarm.AlarmTime.Minutes = 0x0;

  sAlarm.AlarmTime.Seconds = 0x1;

  sAlarm.AlarmTime.SubSeconds = 0x0;

  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_SUB1H;

  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

  sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS|RTC_ALARMMASK_MINUTES;

  sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;

  sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;

  sAlarm.AlarmDateWeekDay = 0x1;

  sAlarm.Alarm = RTC_ALARM_A;

  HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD);

}

These codes are created by cubemx and i have created the callback function for rtc interrupt:

void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc)

{

  RTC_AlarmTypeDef sAlarm;

  

  HAL_RTC_GetAlarm(hrtc,&sAlarm,RTC_ALARM_A,FORMAT_BIN);

  //HAL_GPIO_TogglePin(GPIOG,GPIO_PIN_2);

 // HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);

  if(sAlarm.AlarmTime.Seconds>58)

  {

    sAlarm.AlarmTime.Seconds=0;

  }

  else

  {

    sAlarm.AlarmTime.Seconds=sAlarm.AlarmTime.Seconds+1;

  }

  

  while(HAL_RTC_SetAlarm_IT(hrtc, &sAlarm, FORMAT_BIN)!=HAL_OK){}

   

}

In callback function the pins must toggle every 1sn but it toggles at  approximately 400ms.

Any advise ??
4 REPLIES 4
Walid FTITI_O
Senior II
Posted on September 21, 2016 at 20:40

Hi rapid84,

I recommend that you check and run the RTC-Alarm example in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubef4.html

at this path:STM32Cube_FW_F4_V1.13.0\Projects\STM324x9I_EVAL\Examples\RTC\RTC_Alarm

-Hannibal-

er3481
Senior
Posted on September 22, 2016 at 14:33

Hi,

By the way  i am using stemwin gui library for 320*240 tft LCD, when i use gui functions, the rtc collapses, and when i dont use gui functions rtc Works clearly. What may the reason be ?? Any advise..
Walid FTITI_O
Senior II
Posted on September 22, 2016 at 17:04

Hi rapid84,

What is the version of STemwin you are using ? and share the GUI configuration .

-Hannibal-

er3481
Senior
Posted on September 22, 2016 at 18:32

Hi,

I am using stemwin version 5.28 and if you ask the GUI_Config, it is like below:

#define GUI_NUMBYTES  (1024) *  150

/*********************************************************************

*

*       Public code

*

**********************************************************************

*/

/*********************************************************************

*

*       GUI_X_Config

*

* Purpose:

*   Called during the initialization process in order to set up the

*   available memory for the GUI.

*/

void GUI_X_Config(void) {

  //

  // 32 bit aligned memory area

  //

  static U32 aMemory[GUI_NUMBYTES / 4];

  //

  // Assign memory to emWin

  //

  GUI_ALLOC_AssignMemory(aMemory, GUI_NUMBYTES);

  //

  // Set default font

  //

  GUI_SetDefaultFont(GUI_FONT_6X8);

}

I can not understand the relevance between the gui functions and rtc. Why does it affect the rtc working ?