cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Vcc at ADC

RWagh.2
Associate II

Hello I need to read the voltage where I connected ADC to the voltage divider. I have a code of ATmega where I need it to convert to HAL code. Can you please suggest me how?

here's the code:

void readVcc(byte ATR[])

{

    ADCSRA |= _BV(ADSC); // Convert

    while (bit_is_set(ADCSRA,ADSC));

    ATR[7] = ADCL; // must read ADCL first - it then locks ADCH

    ATR[6] = ADCH;

}

2 REPLIES 2

Which STM32?

And which ATMega? Also, the code you've posted says nothing about ADMUX state so it's just a wild guess what does it do.

Generally, in STM32, there's an internal voltage source with known voltage (given in datasheet), VREFINT, and you compare that against the ADC's reference on VREF+ pin (which in many small packages is tied to VDDA).

JW

I am using STMl011G4U7 low power microcontroller which is connected to ISO 7816 and I am here sending the ATR and also i need to measure the value and store it in the byte of ATR. The above code is from ATMEGA 168-20mu