1

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

Baptiste
  • 41
  • 7
  • 1
    What is your clock source? If it's an RC temperature may cause it to drift enough the USART can't sync. – Colin Oct 11 '18 at 08:29
  • Hello Colin, I've updated my post with the System Clock Init function. Thanks – Baptiste Oct 11 '18 at 09:31
  • Do you go in a low power mode supported by your µC? – Hugo Bevilacqua Oct 11 '18 at 09:48
  • Hello Hugo, No, I don't use low power mode. I've updated my first post with the result of a new test. Thanks – Baptiste Oct 11 '18 at 12:28
  • It does sound like the internal RC changing with temperature. Maybe look into using an external crystal, tcxo or ocxo for your system clock instead. – Colin Oct 11 '18 at 12:41
  • I finaly setup a clock calibration in function of the temperature (I've got a OneWire on the electronic board). It works fine, The Serial port keep synchronization under -20°C – Baptiste May 31 '20 at 22:12
  • I have got the same problem this summer with high temperatures. The problem is that I change the MSICalibrationValue when temperature is low, but the MSICalibrationValue is set to 0 at 20°C. If the temperature increase beyond 20°C, I can not put a negative Calibration Value. So I tried to change ClockRange but there is a gap between too clock range and I can't have a progressive adjustment by playing with clock range and MSICalibrationValue. anyone has an idea ? – Baptiste Jul 10 '20 at 13:54

2 Answers2

1

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

0___________
  • 60,014
  • 4
  • 34
  • 74
1

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.

Hugo Bevilacqua
  • 362
  • 4
  • 12