2016-02-17 06:32 PM
I used a function generator send a signal to PA1, if PA1 get the high signal that let LED on. But my program can't work correctly. Always high or always low, depend on GPIO_Mode = IPU or IPD. Below are my program, have any problem in my program! thanks!
int main(void)
{
while (1)
{
Delay();
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1))
{ GPIO_SetBits(GPIOF,GPIO_Pin_0); // LED On
}
else
{
GPIO_ResetBits(GPIOF,GPIO_Pin_0); // LED OFF
}
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOF,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
2016-02-17 06:45 PM
In one place you're initializing PA0, in the other you're reading PA1. It's not exactly clear what isn't working for you, but it seems like those should match.
2016-02-17 06:58 PM
I fix the error! The read signal pin is PA1.
My program have any question for reading signal?