Skip to main content
Associate
January 28, 2026
Solved

Unable to read internal temperature on STM32U575ZI using registers

  • January 28, 2026
  • 2 replies
  • 241 views

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?

kk9_0-1769606704960.png

 

Best answer by kk9

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. 

2 replies

mƎALLEm
Technical Moderator
January 28, 2026

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.

 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
kk9AuthorBest answer
Associate
January 31, 2026

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.