2015-05-19 02:18 AM
hi guys , i have tried to get input data pin ,
i use CMSIS library and stm32 discovery kit this is my codevoid 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
2015-05-19 03:15 PM
You'd want to enable the GPIOE clock
2015-05-19 06:53 PM