cancel
Showing results for 
Search instead for 
Did you mean: 

STR75x GPIO reconfiguration

Vagni
Associate II
Posted on August 11, 2010 at 09:47

Due to a hardware revision my application firmware on STR750F has to detect (for compatibility with the older hardware) the presence of a resistor divider on a GPIO pin not connected before. If detected, the resistor divider ha to be read as analog input.

The resistor divider is made to generate a voltage level always less than the VIL,max = 0.8V. So I first configure the GPIO pin as input pullup: if I read 0, the resistor divider is present and then I can configure the GPIO pin as analog input to be read with the internal 10-bit ADC.

This is my code:

 ...

 GPIO_InitTypeDef GPIO_InitStructure;

 // P1.13 as input pullup

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;

 GPIO_Init(GPIO1, &GPIO_InitStructure);

 // check if the resistor divider is present

 if( !(GPIO1->PD & GPIO_Pin_13) )

 {

    // P1.13 as analog input

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;

    GPIO_Init(GPIO1, &GPIO_InitStructure);

    // init ADC

    InitADC();

    ...

 }

 ...

With that code the check works properly, but the value read by the ADC is always about three times grater than the expected value. Why?

Instead, If at reset I configure the GPIO pin as analog input (assuming the resistor divider is present), the value read by the ADC is always good (the expected value).

Could you please help me to fix this issue?

0 REPLIES 0