How to assign analog input in common GPIO expansion connector

I want to use “common GPIO expansion connector” of OpenCR board to interface analog signal.
As I want to use BDPIN_GPIO_1 as Analog input 0, I modified “variant.cpp”:

{GPIOA, GPIO_PIN_0,   NULL,     NO_ADC        , NULL   ,   NO_PWM       , NO_EXTI },  // 16 A0
   . . .
{GPIOB, GPIO_PIN_10,  &hADC3,   ADC_CHANNEL_0 , NULL   ,   NO_PWM       , NO_EXTI },  // 50 BDPIN_GPIO_1

But this seems not be enough and analogRead(A0) returns wrong answer.
Is there any suggestion to this ?

Hi @masakiyamamoto
You can only use specific pins for ADC.

ADC pins of the OpenCR are defined in the variant.cpp file as below

{GPIOA, GPIO_PIN_0,   &hADC3,   ADC_CHANNEL_0 , NULL   ,   NO_PWM       , NO_EXTI },  // 16 A0
{GPIOF, GPIO_PIN_10,  &hADC3,   ADC_CHANNEL_8 , NULL   ,   NO_PWM       , NO_EXTI },  // 17 A1
{GPIOF, GPIO_PIN_9,   &hADC3,   ADC_CHANNEL_7 , NULL   ,   NO_PWM       , NO_EXTI },  // 18 A2
{GPIOF, GPIO_PIN_8,   &hADC3,   ADC_CHANNEL_6 , NULL   ,   NO_PWM       , NO_EXTI },  // 19 A3
{GPIOF, GPIO_PIN_7,   &hADC3,   ADC_CHANNEL_5 , NULL   ,   NO_PWM       , NO_EXTI },  // 20 A4
{GPIOF, GPIO_PIN_6,   &hADC3,   ADC_CHANNEL_4 , NULL   ,   NO_PWM       , NO_EXTI },  // 21 A5

These PA0, PF6 ~ PF10 pins support ADC as shown in the datasheet below.

And, unfortunately, PB10 which is the BDPIN_GPIO_1 does not support ADC.

Thanks!

1 Like