STM32H743 ADC3 temperature sensor not reading correctly in latest STMCubeMX 6.18 but was working in earlier STM32CubeMX 6.15
We have recently updated to the latest STM32CubeMX 6.17 and then STMCubeMX 6.18 and noticed in both versions that the internal temperature sensor is mis-reading (by something like 100x).
Previously the project was reading the temperature correctly (STMCubeMX 6.14 or 6.15 not sure exactly).
I have checked that all the ADC3 settings are the same and there are no changes causing by migrating the .IOC project.
I’ve also checked the TSEN and VREFEN are enabled in ADC3_CCR. The value is 0x00C00000.
Before I invest a lot of time rolling back to the old STM32CubeMX version and investigating what changed that broke the ADC3 internal temperature reading I’m hoping that this is known issue with the latest STM32CubeMX?
STM32CubeMX generated code:
/** Common config
*/
hadc3.Instance = ADC3;
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.NbrOfConversion = 2;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
hadc3.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc3.Init.OversamplingMode = ENABLE;
hadc3.Init.Oversampling.Ratio = 1024;
hadc3.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_10;
hadc3.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc3.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
The latest version 6.18 of STM32CubeMX has changed the generated code slightly so that ADC_RESOLUTION_12B is done separately. Rolling this change back had no affect on the mis-reading.
Initialization:
#define ADC3_BufferSize 2
uint16_t ADC3_Buffer[ADC3_BufferSize];
HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED);
HAL_ADC_Start_DMA(&hadc3, (&ADC3_Buffer), ADC3_BufferSize);
SCB_InvalidateDCache_by_Addr(&ADC3_Buffer, ADC3_BufferSize * sizeof(uint16_t));
Get_CPU_Temp = __HAL_ADC_CALC_TEMPERATURE(__HAL_ADC_CALC_VREFANALOG_VOLTAGE(ADC3_Buffer[1], ADC_RESOLUTION_12B), ADC3_Buffer[0], ADC_RESOLUTION_12B);
