cancel
Showing results for 
Search instead for 
Did you mean: 

Read internal temperature stm32L412 TEMPSENSOR_CAL2_ADDR and TEMPSENSOR_CAL1_ADDR

PGood.1
Associate II

Im attempting to migrate code from a STML0 to L4 and I am getting very different values from the calibration values on the L0 the Values are 666 and 911 and I am getting consistat temperature reading that are within a couple of degrees of the ambient temperature. On the STM32L412 if a read the values using int16_t TEMP130_CAL=*TEMPSENSOR_CAL2_ADDR; and int16_t TEMP30_CAL=*TEMPSENSOR_CAL1_ADDR; I get 1381 1037 and the ADC values are similar to the L0 either using ( myTemp -TEMP30_CAL)*(130 - 30)/(TEMP130_CAL - TEMP30_CAL)+30 or __LL_ADC_CALC_TEMPERATURE(3300, myTemp , LL_ADC_RESOLUTION_12B); consistantly returns a temperature of -60 to-80 degrees

int main(void)

{

 /* USER CODE BEGIN 1 */

char buff[50];

uint16_t myTemp;

uint16_t myTemp1;

float temperature;

ADC_ChannelConfTypeDef sConfig = {0};

int16_t TEMP130_CAL=*TEMPSENSOR_CAL2_ADDR;

int16_t TEMP30_CAL=*TEMPSENSOR_CAL1_ADDR;

uint16_t n;

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_USART2_UART_Init();

 MX_TIM2_Init();

 MX_TIM6_Init();

 MX_ADC1_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; //ADC_Channel_TempSensor = ADC_Channel_18 on STM32f7xx

 sConfig.Rank = 1;

 sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5;

 HAL_ADC_ConfigChannel(&hadc1, &sConfig);

 HAL_ADC_Start(&hadc1);

 HAL_ADC_PollForConversion(&hadc1, 100);

 myTemp = HAL_ADC_GetValue(&hadc1);

 temperature = ( myTemp -TEMP30_CAL)*(130 - 30)/(TEMP130_CAL - TEMP30_CAL)+30;

 //temperature = __LL_ADC_CALC_TEMPERATURE(3300, myTemp , LL_ADC_RESOLUTION_12B);

 n = sprintf(buff," temp %3.4f deg C %d raw %d %d \r\n",temperature,myTemp,TEMP130_CAL,TEMP30_CAL);

 HAL_UART_Transmit(&huart2,buff,n,1000);

 temperature = __LL_ADC_CALC_TEMPERATURE(3300, myTemp , LL_ADC_RESOLUTION_12B);

 temperature = (( myTemp1 -TEMP30_CAL)*(110 - 30)/(TEMP130_CAL - TEMP30_CAL))+30;

 n = sprintf(buff," temp1 %3.4f deg C %d raw %d %d \r\n",temperature,myTemp,TEMP130_CAL,TEMP30_CAL);

 HAL_UART_Transmit(&huart2,buff,n,1000);

*/  HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);

 HAL_Delay(1000);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

Output

 temp -79.0000 deg C 660 raw 1381 1037

 temp -79.0000 deg C 661 raw 1381 1037

 temp -79.0000 deg C 662 raw 1381 1037

 temp -78.0000 deg C 663 raw 1381 1037

 temp -79.0000 deg C 661 raw 1381 1037

 temp -78.0000 deg C 663 raw 1381 1037

1 REPLY 1
TDK
Guru

Are you reading from the right location?

0693W000005BQwrQAG.png 

Is your sampling time at least 5us per the datasheet?

0693W000005BQwwQAG.png

If you feel a post has answered your question, please click "Accept as Solution".