cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read internal temperature on STM32U575ZI using registers

kk9
Visitor

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

 

1 REPLY 1
mƎALLEm
ST Employee

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.