Baptiste
Baptiste

Reputation: 41

STM32L4xx USART Low temperature

I have got a problem with an electronic board based on a TSM32L4xx microcontroler. I am using HAL driver for all peripherals initilization. I use USART3 to communicate in RS232 with a computer When the microcontroler rise under -6°C (in a freeze), the transmission on the microcontroler works, but not the reception (interruption doesn't rise). The USART is initialized with SYSCLOCK :

void HAL_UART_MspInit(UART_HandleTypeDef *huart)
{
    [...]
    USARTx_RCC_CONFIG(RCC_USART3CLKSOURCE_SYSCLK);
    [...]
}

I read that under 0°C the PLL can stop to work but I don't use it...

Here is my System Clock initialisation :

void InitSystemClock(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_PeriphCLKInitTypeDef PeriphClkInit;


  RCC_OSCILLATORTYPE_MSI|RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.OscillatorType      =   RCC_OSCILLATORTYPE_HSI
                                      | RCC_OSCILLATORTYPE_MSI
                                      | RCC_OSCILLATORTYPE_LSE;
  RCC_OscInitStruct.LSEState            = RCC_LSE_ON;
  RCC_OscInitStruct.MSIState            = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = 0;
  RCC_OscInitStruct.MSIClockRange       = CLOCK_RANGE;
  RCC_OscInitStruct.HSIState            = RCC_HSI_OFF;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState        = RCC_PLL_OFF;
  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_MSI;
  RCC_ClkInitStruct.AHBCLKDivider       = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider      = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider      = RCC_HCLK_DIV1;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);


  PeriphClkInit.PeriphClockSelection    = RCC_PERIPHCLK_RTC;
  PeriphClkInit.RTCClockSelection       = RCC_RTCCLKSOURCE_LSE;
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);


  __HAL_RCC_PWR_CLK_ENABLE();


  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  DWT->CTRL |= 1;   //CYCCNTENA
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

    /* GPIO Ports Clock Enable */
    __GPIOA_CLK_ENABLE();
    __GPIOB_CLK_ENABLE();
    __GPIOC_CLK_ENABLE();
    __GPIOD_CLK_ENABLE();
    __GPIOE_CLK_ENABLE();

}

Edit : I made an interresting test : I've configured a PWM (using timer2 channel 3 and 4). The PWM generates a 375Hz frequency. After putting the electronic board into the freezer, the PWM decrease to 345Hz at -18°C I made the measures with a laboratory oscilloscope

Anyone has encountered this issue ? Anyone has got an idea about this problem ?

Thanks a lot by advance,

Baptiste

Upvotes: 1

Views: 664

Answers (2)

Hugo Bevilacqua
Hugo Bevilacqua

Reputation: 382

Assuming you are using the USART as UART:

If you have an accurate reference frequency such as LSE, you could perform a RC calibration according to the temperature, see the RCC_ICSCR register. An internal temperature sensor is available.

This application note shows how to calibrate the internal RCs.

At 30°C, the HSI16 oscillator has an accuracy of ±0.5%, the MSI oscillator has an accuracy of ± 0.6% and the HSI48 oscillator has an accuracy of ±4%. But in the temperature range of -40°C to 105°C, the accuracy decreases.

Upvotes: 1

0___________
0___________

Reputation: 67765

UARTs are very sensitive to the clock variations especially if you send more data in one go.

You need to use crystal oscillator with good temperature stability or send very small chunks of data or check the internal temperature sensor and change the baud settings accordingly

Upvotes: 1

Related Questions