Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 4 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:
2 Answers
10 years, 4 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?
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 29 Jun 2015
It may help if you said what code you were using.
posted by Andy A 29 Jun 2015It'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); } }