stm32 103 芯片引脚 PB4 无法拉低 PB3 无法拉高

void LED_GPIO_Config(void)
{
/*¶¨ÒåÒ»¸öGPIO_InitTypeDefÀàÐ͵ĽṹÌå*/
GPIO_InitTypeDef GPIO_InitStructure1;
GPIO_InitTypeDef GPIO_InitStructure2;
/*¿ªÆôGPIOCµÄÍâÉèʱÖÓ*/
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
/*Ñ¡ÔñÒª¿ØÖƵÄGPIOCÒý½Å*/
GPIO_InitStructure1.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_3;
GPIO_InitStructure2.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_6;
/*ÉèÖÃÒý½ÅģʽΪͨÓÃÍÆÍìÊä³ö*/
GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure2.GPIO_Mode = GPIO_Mode_Out_PP;
/*ÉèÖÃÒý½ÅËÙÂÊΪ50MHz */
GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure2.GPIO_Speed = GPIO_Speed_50MHz;
/*µ÷Óÿ⺯Êý£¬³õʼ»¯GPIOC*/
GPIO_Init(GPIOB, &GPIO_InitStructure1);
GPIO_Init(GPIOA, &GPIO_InitStructure2);
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ¹Ø±ÕËùÓÐledµÆ */
GPIO_SetBits(GPIOB, GPIO_Pin_4);
GPIO_SetBits(GPIOB, GPIO_Pin_3);
GPIO_ResetBits(GPIOA, GPIO_Pin_9);
GPIO_SetBits(GPIOA, GPIO_Pin_6);
// GPIO_SetBits(GPIOA, GPIO_Pin_15);
}

 

主要设置标红的两句话,作用是因为stm32 的这两个引脚默认是JTAG 的功能,需要用这两句话来恢复为io的设置。

posted on 2018-01-16 17:33  dotiger  阅读(486)  评论(0编辑  收藏  举报

导航