cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Read Problem. Adc reads absurd value with stm32l053 nucleo.

Mutlu.Mert
Associate III

Hi, i want to try adc ch0 and ch1 in stm32f053 nucleo, i have 10k ohm and 1k ohm between 3v3, gnd and analog input. ( Basically voltage divider for measure.)

However, i've faced absurd values in adc channel and, these values never changes. I'm sharing all of the codes about adc initialization and main. I just want to read number between 0-2047. Where am i wrong ? Thans a lot.0690X000006ByoRQAS.jpg

Here is pins, where i want to measure adc values.

0690X000006ByoWQAS.jpg

This is adc_init function as you see.

0690X000006ByobQAC.jpg

This is hal_msp_init function as you see.

0690X000006ByogQAC.jpg

This is the main for init adc functions in my main.

0690X000006ByoqQAC.jpg

Also while loop.

0690X000006ByovQAC.jpg

Finally, i've faced this result when i was debugging.

I know there is a point i've missed. Where am i wrong ?

With warmest regards.

3 REPLIES 3
HJorg
Associate

Just took a brief look at you code the first thing i can think of is try call HAL_ADC_Start after HAL_ADC_MspInit.

It also looks like you code expect to use Continues Conversion mode being enabled which is not the case.

If using continues conversion you should consider changing the overrun behavior to overwrite data, so that you get the latest conversions.

I do not know if it helps but this is my best guess

Mutlu.Mert
Associate III

Yes, this solving sound like works however i is not worked, i've changed Msp_init and Adc_Start also changed ADC_OVR_DATA_OVERWRITTEN instead of ADC_OVR_DATA_PRESERVED. It is working same adc value, like "134217959" and never changes.

Thanks for your help

AvaTar
Lead

It seems you have a datatype problem with your display.

ADC data are 12 bit at most, and usually represented as unsigned short (uint16_t).

I don't dig into HAL code, though.