新手上路 
 
	- 积分
 - 25
 
        - 金钱
 - 25 
 
       - 注册时间
 - 2020-4-11
 
      - 在线时间
 - 4 小时
 
 
 
 | 
 
 
 楼主 |
发表于 2023-12-25 17:17:38
|
显示全部楼层
 
 
 
用F103RT6的PB4/PB3脚当做IO口读他们的状态,可是这两个脚的默认是JTAG脚,只能关闭JTAG功能,然后在读这两个脚的状态 
void KEY_Init(void) 
{         
        GPIO_InitTypeDef GPIO_InitStructure; 
 
         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOD,ENABLE);//使能PORTC时钟 
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO ,ENABLE); //使用复用时钟功能 ,因为要用PB4/PB3的复用功能 
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//关闭jtag,使能SWD,可以用SWD模式调试 
 
       GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_4;//PB4 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; //PB4设置成输入,默认上拉           
        GPIO_Init(GPIOB, &GPIO_InitStructure); 
         
        GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_3;//PB3 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; //PB3设置成输入,默认上拉           
        GPIO_Init(GPIOB, &GPIO_InitStructure); 
} 
我是上面这样写的,可是现在读不到PB4、PB3的引脚状态。 
把这句GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;   改成GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 这样也不行 
请问大神是怎么回事 
 |   
 
 
 
 |