Question
Is my GPIO pin configured correctly?
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.