5 years, 1 month ago.

DISCO_L475VG_IOT01A AnalogIn reads positive number when grounded

Hi,

I am having a very strange problem with the DISCO_L475VG_IOT01A board...

The code below is practically copied from the mbed-os AnalogIn example. However, the values I read are wacky. When I ground the A1 pin, I read roughly 31831 (varies +/- 20 occasionally). When I connect it to 3.3V (VDD), I read roughly 64367 (also varies, which is actually close to what it should be). Why on earth is a grounded A1 pin reading roughly half of the range of a 16 bit number? It seems the whole range is shifted by about 2^15 = 32768.

#include "mbed.h"

// Initialize a pins to perform analog input and digital output fucntions
AnalogIn ain(A1);

int main(void)
{
    while (1) {
        uint16_t val = ain.read_u16();
        printf("%u \n\r", val);
        wait(0.1f);
    }
}
Be the first to answer this question.