STM32F411 - temperature sensor returning 0
Hi All , Im trying to read the temperature from the internal temperature sensor.
But everytime Im reading i recevied 0
Here is my code:
#define ADC1EN (1U<<8)
void temp_init()
{
// Configure ADC module ADC1_IN18 channel
// Enable Clock access
RCC->APB2ENR |= ADC1EN;
//10010 =18
ADC1->SQR3 |=(1U<<4);
ADC1->SQR3 |=(1U<<1);
//conversion length 1 channels
ADC1->SQR1 = 0x00;
// TEMP sensor enable
ADC->CCR |=ADC_CCR_TSVREFE;
// Enable ADC module
ADC1->CR2 |=ADC_CR2_ADON;
}
void start_conversion()
{
// Enable continues conversion
ADC1->CR2 |= C2_CONT;
// Start ADC conversion
ADC1->CR2 |= C2_SWSTART;
}
uint32_t adc_read(void)
{
//Wait for conversion to complete
while(!(ADC1->SR & SR_EOC)){};
//Read ADC sampled value
return ADC1->DR;
}
from the main I just call the function every ~1 second
printf("Temp :%f \n\r",adc_read());
BTW i know that the printf value isnt yet the final temp value
Thanks ahead!