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.

I work with the online compiler. This is only an example. I think there is no optimization problem because the led doesn't blink. So I don't know why the program doesn't run.

posted by Daniel Z 12 Nov 2015