Regarding reading of Vcc in STm32

Thread Starter

Raj Waghmare

Joined May 8, 2019
32
Hello guys,

I need to read the voltage from ADC pin where I have connected a voltage divider to it. I do have a code of ATMEGA where I need to convert it to HAL STM code. Can anyone please help?

Here's the code:

byte ATR[8] = {0x3B, 0x06, 0x55, 0x63, 0x63, 0x3D, 0x00, 0x00 }; //TS, T0, Historical Characters: Vcc= byte (ADCH, ADCL)


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;
}
 

MrChips

Joined Oct 2, 2009
30,802
STM32 MCU is not an Atmel ATmega. You cannot hope to convert code from one to the other.

You did not say what software development platform (the IDE) you are using to program an STM32 MCU.
If you are using STM32CubeIDE you would configure the MCU to access the ADC module. The IDE will automatically insert initialization code for the ADC module.

You start the ADC with the function,
HAL_ADC_Start(ADC_HandleTypeDef* hadc);

You read the ADC data with the function,
HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
 
Top