4 years, 5 months ago.

I can't get the Inputs working!

Hey, i got a Data Logger working on the STM32F401. Logging the AnalogIn Voltage. Now i just wanted to put the code on the EFM32 STK3700. So i connected the wiper of my Potentiometer to PD3 and the other from 3.3 to GND. In the code i just changed the AnalogIn-Line to AnalogIn value(PD3). Now the logged Voltage i got over the serial port is always 0V, however the potentiometer is turned. Do i have to add aditional config lines to get a value from the AnalogIns?

Question relating to:

Silicon Labs' EFM32™ Giant Gecko ARM® Cortex®-M3 based 32-bit microcontrollers (MCUs) provide flash memory configurations up to 1024 kB, 64-128 kB of RAM and CPU speeds up to 48 MHz, ...

It may help if you said what code you were using.

posted by Andy A 29 Jun 2015

It's based on the AnalogValue Example on the STM32f401.

AnalogValue

#include "mbed.h"
#include <time.h>
#include <stdio.h>
 
AnalogIn analog_value(PD3);
DigitalOut led(LED1);

int hour(int sec){
    int h = sec/3600;
    return h;
    }
int min(int sec){
    int m = (sec%3600)/60;
    return m;
    }
int sec(int sec){
    int s = (sec%3600)%60;
    return s;
    }

int main() {
   
    Timer timer;
    float meas;
    printf("Date and time are set.\n");
    printf("\nRead AnalogValue\n");
    timer.start();
    
    while(1) {
        meas = analog_value.read();
        meas = meas * 3300;
        printf("measure = %.0f mV\n", meas);
        /* if (meas > 2000) { 
          printf("Value over: %d : %d : %d\r\n", hour(timer.read()), min(timer.read()), sec(timer.read()));
          while(meas > 2000){
              //printf("\r\n\r\n%.0f",meas);
              meas = analog_value.read();
              meas = meas * 3300;
              led = 1;
              wait(0.01);
              }
        }
        else {
          led = 0;
        }*/
        wait(0.2);
    }
}

posted by Simon Haase 29 Jun 2015

2 Answers

4 years, 5 months ago.

Did you update your mbed lib to the latest version? Right click, update, on the lib.

Accepted Answer

Thanks! Didn't know i have to update... It works!

posted by Simon Haase 29 Jun 2015
4 years, 5 months ago.

I'm afraid I can't replicate this issue.

The following code worked just fine for me:

#include "mbed.h"

//using PD3, 3.3V and GND
AnalogIn input(PD3);
LowPowerTicker tick;
volatile bool update = false;
float value;

void updateValue(void)
{
    value = input;
    update = true;   
}

int main(void)
{
    tick.attach(updateValue, 1.0f);
    while(true){
        sleep();
        if(update){
            update = false;
            printf("%f\n",value);
        }   
    }
}

This outputted values between 0.00000 and 0.99977 over serial, once every second.

Edit: I also tried the code you posted, and it worked just fine out of the box. Are you certain you connected the pins correctly?

I hope you mean it outputted values between 0.00000 and 0.999977 ;-)

posted by Andy A 29 Jun 2015

Heh. Yeah =P

Fixed now; thanks.

posted by Srod Karim 29 Jun 2015

Yes! Pins are correctly connected. I think I got problems with ESD here and destroyed the A/D-Converter carelessly. I looked up the schematics and saw that there are no limitations between the input connectors and the mcu. I can't figure out any other reason. But thanks for your help :)

Edit: Your Code also doesn't work here. I also checkd the Voltage on the Input-Connector. There should be definetely a voltage. Not 0 V!

posted by Simon Haase 29 Jun 2015