2026-01-28 5:26 AM - last edited on 2026-01-28 6:09 AM by TDK
Hello, I'm trying read core temperature. I use NUCLEO-U575ZI-Q board. I wrote code:
RCC->AHB3ENR |= RCC_AHB3ENR_PWREN;
PWR->SVMCR |= PWR_SVMCR_ASV;
RCC->AHB2ENR1 |= RCC_AHB2ENR1_ADC12EN;
ADC12_COMMON->CCR |= ADC_CCR_VSENSEEN;
ADC1->CR &= ~ADC_CR_DEEPPWD;
ADC1->CR |= ADC_CR_ADVREGEN;
while(!(ADC1->ISR & ADC_ISR_LDORDY));
ADC1->CR |= ADC_CR_ADCAL;
while (ADC1->CR & ADC_CR_ADCAL);
ADC1->CR |= ADC_CR_ADEN;
while (!(ADC1->ISR & ADC_ISR_ADRDY));
ADC1->DIFSEL = 0;
ADC1->PCSEL = ADC_PCSEL_PCSEL_19; // preselection
ADC1->SQR1 = (19 << ADC_SQR1_SQ1_Pos);
ADC1->SMPR2 |= (7 << ADC_SMPR2_SMP19_Pos); // max sample time
ADC1->CR |= ADC_CR_ADSTART;
while (!(ADC1->ISR & ADC_ISR_EOC));
uint16_t raw = ADC1->DR;
volatile float temperature_c =
(
(float)(raw - TS_CAL1) * (130.0f - 30.0f)
) / (float)(TS_CAL2 - TS_CAL1)
+ 30.0f;Unfortunately it doesn't work correctly. ADC1->DR returns always value 10499. It's looks like channel numer 19 wasn't connected to ADC. What do I incorrect?
Solved! Go to Solution.
2026-01-31 1:11 PM
Hello @mƎALLEm - I thought that working directly with the registers would be faster, because I wouldn’t have to learn and use the HAL functions. Besides, it would allow me to get to know the microcontroller very well and have 100% control over the code. I care a lot about execution speed and energy efficiency.
But I found solution: ADC can work with speed up to 55 Mhz - my processor has higher frequency, so I set prescaler on ADC and now all works correctly.
2026-01-28 6:18 AM
Hello @kk9 and welcome to the ST community,
Why starting by direct access to the registers? You can use HAL and validate the function than move on with direct to the registers by inspiring from the call sequence in the HAL. That could save you a lot of time.
2026-01-31 1:11 PM
Hello @mƎALLEm - I thought that working directly with the registers would be faster, because I wouldn’t have to learn and use the HAL functions. Besides, it would allow me to get to know the microcontroller very well and have 100% control over the code. I care a lot about execution speed and energy efficiency.
But I found solution: ADC can work with speed up to 55 Mhz - my processor has higher frequency, so I set prescaler on ADC and now all works correctly.