Hi,
I'm trying to perform an internal temperature measurement with the integrated temp sensor of an STM32F303RE on a NUCLEO-303RE board. And something goes wrong. Indeed my measurements are incorrect.
Here is the main loop
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_ADC1_Init();
/* USER CODE BEGIN 2 */
if(HAL_ADC_Start(&hadc1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if (HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY) == HAL_OK)
{
uint32_t raw_temp = HAL_ADC_GetValue(&hadc1);
float temperature = ((1.43 - ((raw_temp/4096.0)*1.2)) / 0.0043) + 25.0;
char buffer[50];
sprintf(buffer, "Température brute : %lu, Température en Celsius : %.4f\r\n", raw_temp, temperature);
HAL_UART_Transmit(&huart2, (uint8_t *)buffer, strlen(buffer), HAL_MAX_DELAY);
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
}
else
{
HAL_UART_Transmit(&huart2, "error\r\n", 8, HAL_MAX_DELAY);
}
HAL_Delay(1000); // 1 second delay
}
/* USER CODE END 3 */
I applied the formula explained in the ST Reference manual with the values specified in the datasheet of my STM32F303 chip.
According to the reference manual, the raw to Celsius conversion formula is :
{(V_25 - Vts) / AVG_Slope} + 25.0
And the main conversion formula I wrote:
float temperature = ((1.43 - ((raw_temp/4096.0)*1.2)) / 0.0043) + 25.0;
Firstly I convert the RAW ADC Value in volts with
(raw_temp/4096.0)*1.2)
The analog to digital conversion is done with 12 bits so 4096 values and a ref of 1,2 Volt. So I have my Vts value here
And here my results :
RAW ADC Temperature °C
1731 239,6212
1727 239,8937
1723 240,1662
1722 240,2344
1719 240,4388
1720 240,3706
1718 240,5069
1717 240,575
1717 240,575
1717 240,575
1716 240,6432
1714 240,7794
1716 240,6432
1712 240,9157
1705 241,3926
1702 241,597
1699 241,8014
1698 241,8696
1697 241,9377
1697 241,9377
1695 242,0739
1695 242,0739
On the results above, the board was in a freezer before the test (and I confirm the STM32 was quite cold
) and I put my finger on it.
So it's unexpected, I expect a first value of about 0°C ~ 10°C and an increment of 2 ~3°C per second when I put my finger on the chip. Also, I don't understand why the computed temperature is about 240°C. I checked the formula several, and for me, it's okay between the one given by ST in the ref manual, and my own in the code