Skip to main content
fallospenis
Associate
May 24, 2013
Question

Is my GPIO pin configured correctly?

  • May 24, 2013
  • 3 replies
  • 898 views
Posted on May 25, 2013 at 00:12

Hello!

I'm new to micro controller programming. I have been told to ''poll a pin'' and perform a specific action if this pin ''goes low''. So I wrote this code to ''poll'' a PD10 pin on my board:

GPIO_InitTypeDef portd;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
portd.GPIO_Mode = GPIO_Mode_IN;
portd.GPIO_PuPd = GPIO_PuPd_NOPULL;
portd.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOD, &portd);

Next I do this in an endless loop:

uint8_t pd10 = GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_10); 
if
(pd10 == 0){ 
//1=high 0=low
//Perform an action when PD10 goes low
}

I got it right? PS STM32F3-Discovery board.
    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    May 24, 2013
    Posted on May 25, 2013 at 01:41

    At first glance it doesn't appear unreasonable. What are you doing to make the pin attain a high and low state?

    I you have a button that connects to ground, the other side should have a pull-up.
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    fallospenis
    Associate
    May 25, 2013
    Posted on May 25, 2013 at 03:35

    I'm trying to read data from the AD7738 ADC atm.

    So I need to:

    1)Configure the SPI

    2)Write some cfg data to ADC registers

    3)Check the RDY pin state and send some byte through SPI.

    (full sequence I found here: http://ez.analog.com/thread/16829)

    I did all the configuration task but the RDY pin (PD10) stays high from the very beginning (even before the whole configuration executed) and it does not go low. Its OK for the pin to be high all time? It is high even when I do not attach any wire to it. I'm confused.

    If necessary I can show my code for the SPI configuration.

    Thank you for your reply.

    fallospenis
    Associate
    May 25, 2013
    Posted on May 26, 2013 at 01:45

    Its ok now, problem is solved. I configured the ADC wrong. Now everything works... except the actual converted data :p