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.
9 years ago.
Probelms with AnalogIn on Nucleo F334R8
I want to read two analog values. One channel is connected to ADC1 an the other to ADC2. Why it doesn't work? Has anyone the same problem? Thanks for help.
Example:
include the mbed library with this snippet
#include "mbed.h" DigitalOut led1(LED1,1); AnalogIn adc_1(PC_0); //ADC1 AnalogIn adc_2(PC_4); //ADC2 float adc_1_meas; float adc_2_meas; int main () { while(1) { adc_1_meas = adc_1.read(); // Converts and read the analog input value (value from 0.0 to 1.0) adc_2_meas = adc_2.read(); // Converts and read the analog input value (value from 0.0 to 1.0) led1=!led1; wait(0.5); } }
1 Answer
9 years ago.
Hmmm...what does the compiler optimizer do with adc_1_meas and adc_2_meas once read? There is no code that uses these variables so I suspect that the compiler has optimized them out.
How are you checking? What is your build environment? If you do command line or IAR build you can set the optimization to "0" so that it won't optimize out these statements.