STM32F103ZET6 PA0问题?

[复制链接]
4561|13
 楼主| win2000_li 发表于 2010-1-4 22:41 | 显示全部楼层 |阅读模式
用PA0做为IO按键输入,加了一个上拉电阻。

当你按下按键时,PA0没有被拉低,依旧是高。

请用过ZET6的兄弟们,指点一下。

程序如下:

void GpioInit(void)
{
/* Configure all unused GPIO port pins in Analog Input mode (floating input
  trigger OFF), this will reduce the power consumption and increase the device
  immunity against EMI/EMC */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE);
GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOG, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, DISABLE);   

// Enable GPIO_LED clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
// Output LD1 LD2 LD3 LD4
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIO_LED, &GPIO_InitStructure);
// KEY Input
GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_0 | GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(TamperKey, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(User2Key, &GPIO_InitStructure);
}
yybj 发表于 2010-1-5 10:13 | 显示全部楼层
你用的芯片,初始化是高组态吧
sinadz 发表于 2010-1-5 16:27 | 显示全部楼层
你程序里,哪里给了低电平呢,我咋没找到
 楼主| win2000_li 发表于 2010-1-6 21:05 | 显示全部楼层
是这样的,我设置PA0为输入,并且外部加了上拉电阻的。
 楼主| win2000_li 发表于 2010-1-6 21:07 | 显示全部楼层
如下图
2.jpg
香水城 发表于 2010-1-6 21:29 | 显示全部楼层
按照这个电路,按下按键时,PA0不可能不被拉低,肯定是硬件有问题。看看你的按键是不是坏了?
gf86530430 发表于 2010-1-7 09:38 | 显示全部楼层
软件 按键PIN时钟使能了,如果初始化输入没问题的话没道理不变低!
gf86530430 发表于 2010-1-7 09:39 | 显示全部楼层
还有是你从软件读的还是用表量的?
yybj 发表于 2010-1-7 13:06 | 显示全部楼层
硬件的问题吧
pkat 发表于 2010-1-8 09:59 | 显示全部楼层
你先用万用表量,如果是低,就证明硬件上没问题
 楼主| win2000_li 发表于 2010-3-4 15:58 | 显示全部楼层
已经解决,非常感谢。。。。

是按键坏了。

结帖。。。。。。。。。。。。
xsgy123 发表于 2010-3-4 21:54 | 显示全部楼层
这种问题首先是查硬件
dfsa 发表于 2010-3-4 22:08 | 显示全部楼层
按键也太差了,建议下次换个好点的
 楼主| win2000_li 发表于 2010-3-20 22:14 | 显示全部楼层
请版主结贴!!!谢谢!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

142

主题

718

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部