9 years, 2 months ago.

AnalogIn does not recognize the Ain(A0)

Hi all I just starting learning ARM programming, I am using the ST32F401R board and run blinky ok, but tried to read analog for potentiometer wiper (25k ohm pot terminals connected GND , +3.3v and wiper to PA_0 as A0 ) the LED is always off, any help highly appreciated.

  1. include "mbed.h"

AnalogIn analog_value(A0);

DigitalOut myled(LED1);

Calculate the corresponding acquisition measure for a given value in mV

  1. define MV(x) ((0xFFF*x)/3300)

int main() { while(1) { uint16_t meas = analog_value.read_u16(); Converts and read the analog input value if (meas > MV(1000)) { If the value is greater than 1000 mV toggle the LED myled = !myled; } wait(0.2); 200 ms } }

Thanks ,I tried that, still does not recognize the A0 !

posted by Mohammed Shalash 03 Feb 2015

It is ok now after updating the STM32f401R firmware. THANKS

posted by Mohammed Shalash 03 Feb 2015

2 Answers

9 years, 1 month ago.

I have the same problem,that's a bug,please see http://developer.mbed.org/questions/4420/Problem-with-Nucleo-L152RE-AnalogIn/ ,but unfortunately,it has not been fixed!

9 years, 1 month ago.

There is a bug with the HSI clock in the Nucleos with F053R8, which is still to be fixed. But I just checked exactly your configuration (F401RE as well as F103RB) and ran the program successfully. The LED only flashes if read_u16() is bigger than the calculated value. Please double-check if the most recent ST-LINK firmware is programmed, e.g. using ST-LINK/V2-1 firmware upgrade

BTW: the 1000mV is calculated incorrectly, as read_u16() got a range of 16bit and not just 12bit. But that's not the reason of your problem! So please change

define MV(x) ((0xFFF*x)/3300)

to

define MV(x) ((0xFFFF*x)/3300)