cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Disco RTC (old version) not updating SECONDS

shorai
Associate III

I am using the Audio Playback and record exaample.

I modified Systeem_clock_config as follos

  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 336;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 7;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

Then ran the RTC config from a Cube generated source

My main is stubbed out to do the following

 SystemClock_Config();
 
  
  /* Initialize MEMS Accelerometer mounted on STM32F4-Discovery board */
  if(BSP_ACCELERO_Init() != ACCELERO_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }
  
  MemsID = BSP_ACCELERO_ReadID();
//  RTC does not initiaalise with the system clock config dictated by this SW.
  // By not using the IOC file, it is a pain to debug the clock config errors
  // The ARM compiler optimisation also messes with the program flow
MX_RTC_Init();
  MX_DMA_Init();
  MX_USART2_UART_Init();
 
  HAL_RTC_MspInit(&hrtc);
  while (-1) {
	  RTC_TimeTypeDef ttime;
	  HAL_RTC_GetTime(&hrtc, &ttime, RTC_HOURFORMAT_24);
      char str[50];
      sprintf(str,"%5d %5d %5ld %5ld\r\n",ttime.Minutes,ttime.Seconds, ttime.SubSeconds,ttime.SecondFraction);
      HAL_UART_Transmit_DMA(&huart2,(uint8_t *) str,strlen(str));
      HAL_Delay(990);
  }

And my output on the serial port looks like this

  0     1   108   255
    0     1   133   255
    0     1   158   255
    0     1   183   255
    0     1   208   255
    0     1   233   255
    0     1     3   255
    0     1    28   255
    0     1    53   255
    0     1    78   255
    0     1   103   255
    0     1   128   255
    0     1   153   255
    0     1   178   255
    0     1   203   255
    0     1   229   255
    0     1   254   255
    0     1    23   255
    0     1    48   255
    0     1    73   255
    0     1    98   255
    0     1   122   255

As you can see, the seconds and minutes do not update. The seconds either has a 0 or a 1.

Additionally, if I have LSI enabled then I seem to lose systick

Any ideas as to what is going on and how to correct it?

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
3 REPLIES 3
shorai
Associate III

Changing RCC_OscInitStruct.HSIState = RCC_LSI_OFF;

does not affect the result.

After reading time, you have to read date, too.

JW

shorai
Associate III

Thank you so much Jan, really appreciate, it works

I bookmarked the gotchas:-)

So annoying,

STM really need to offer a single GetDateTime and deprecate the getTime function