1 year ago.

How to use AnalogIn on PA_2,PA_3 with NUCLEO F446RE

Hi. I need to use AnalogIn on PA_2 and PA_3 with Nucleo F446RE. I wrote the code for use AnalogIn on PA_2 and PA_3 but it doesn't move.

Could you tell me how to use PA_2 and PA_3 with AnalogIn?

This is the code.

AnalogIn F446RE PA_2 PA_3

#include "mbed.h"

// FROM DATA SHEET(STM32F446XX)
// ADC123_IN0 PA_0
// ADC123_IN1 PA_1
// ADC123_IN2 PA_2
// ADC123_IN3 PA_3
// ADC123_IN4 PA_4
// ADC123_IN5 PA_5
// ADC123_IN6 PA_6
// ADC123_IN7 PA_7
// ADC123_IN8 PB_0
// ADC123_IN9 PB_1
// ADC123_IN10 PC_0
// ADC123_IN11 PC_1
// ADC123_IN12 PC_2
// ADC123_IN13 PC_3
// ADC123_IN14 PC_4
// ADC123_IN15 PC_5

AnalogIn AnalogINPUT00(PA_0);
AnalogIn AnalogINPUT01(PA_1);
AnalogIn AnalogINPUT02(PA_2);//#
AnalogIn AnalogINPUT03(PA_3);//#
AnalogIn AnalogINPUT04(PA_4);
AnalogIn AnalogINPUT05(PA_5);
AnalogIn AnalogINPUT06(PA_6);
AnalogIn AnalogINPUT07(PA_7);
AnalogIn AnalogINPUT08(PB_0);
AnalogIn AnalogINPUT09(PB_1);
AnalogIn AnalogINPUT10(PC_0);
AnalogIn AnalogINPUT11(PC_1);
AnalogIn AnalogINPUT12(PC_2);
AnalogIn AnalogINPUT13(PC_3);
AnalogIn AnalogINPUT14(PC_4);
AnalogIn AnalogINPUT15(PC_5);

PwmOut LEDS(D13);//led

uint16_t AnalogValue[16];

void ReadAnalog(){
        AnalogValue[0] = AnalogINPUT00.read_u16();
        AnalogValue[1] = AnalogINPUT02.read_u16();
        AnalogValue[2] = AnalogINPUT02.read_u16();
        AnalogValue[3] = AnalogINPUT03.read_u16();
        AnalogValue[4] = AnalogINPUT04.read_u16();
        AnalogValue[5] = AnalogINPUT05.read_u16();
        AnalogValue[6] = AnalogINPUT06.read_u16();
        AnalogValue[7] = AnalogINPUT07.read_u16();
        AnalogValue[8] = AnalogINPUT08.read_u16();
        AnalogValue[9] = AnalogINPUT09.read_u16();
        AnalogValue[10] = AnalogINPUT10.read_u16();
        AnalogValue[11] = AnalogINPUT11.read_u16();
        AnalogValue[12] = AnalogINPUT12.read_u16();
        AnalogValue[13] = AnalogINPUT13.read_u16();
        AnalogValue[14] = AnalogINPUT14.read_u16();
        AnalogValue[15] = AnalogINPUT15.read_u16();
}

void setup(){
        LEDS.period_us(15);//LED
        for (float i = 0; i < 1; i = i + 0.025) {
                LEDS = i; wait_ms(10);
        }
        for (uint8_t i = 0; i < 2; i++) {
                LEDS = 1.0; wait_ms(100);
                LEDS = 0.0; wait_ms(100);
        }
}
/**************************************************************************************************/
int main() {
        setup();
        while(1) {
                ReadAnalog();
                LEDS = ! LEDS;
        }
}

1 Answer

1 year ago.

Hi Daiki,

The PA_2 and PA_3 pins are used for stdio messages which are enabled by default, please see:

You should be able to change the definitions on lines 181 and 186 and then observe valid values on those pins.

Regards,

Ralph, Team Mbed