cancel
Showing results for 
Search instead for 
Did you mean: 

please help me to find error with read input data pin

chauvoluuhuong
Associate II
Posted on May 19, 2015 at 11:18

hi guys , i have tried to get input data pin ,

i use CMSIS library and stm32 discovery kit this is my code

void main() 
{ 
//// i set up port D wiht internal pull-up resistor before read value i/o pin 
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = 0xffff;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/// i set up port E as output data to see whether the pin change value 
GPIO_InitStructure.GPIO_Pin = 0xffff;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/// and this is while loop to check the value data in pin D2 
while(1)
{ 
if( GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_2)==1)
GPIO_Write(GPIOE,256);
if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_2)==0)
GPIO_Write(GPIOE,0xffff);
}
and it isn't run hizzz ,unless i connect the PD2 to Gnd before reset MCU ( if MCU running , after i connect pin PD2 to GND , IT IS NOT TRUE ) i think it very simple . 
some body can help me , thank very much

2 REPLIES 2
Posted on May 20, 2015 at 00:15

You'd want to enable the GPIOE clock

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chauvoluuhuong
Associate II
Posted on May 20, 2015 at 03:53