RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); // 使能AFIO時(shí)鐘,功能復(fù)用IO時(shí)鐘 注意:只有使用了AFIO的事件控制寄存器、AFIO的重映射功能以及外部中斷(EXTI)控制寄存器才需要開啟AFIO的時(shí)鐘,STM32參考手冊(cè)從來沒說過使用IO的復(fù)用功能就一定要開啟AFIO時(shí)鐘,這是個(gè)誤區(qū)。 重映射串口1到PB6,PB7步驟為: GPIO_Init(GPIOB, &GPIO_InitStructure);1.打開重映射時(shí)鐘和USART重映射后的I/O口引腳時(shí)鐘, RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); 2.I/O口重映射開啟. GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE); 3.配制重映射引腳, 這里只需配置重映射后的I/O,原來的不需要去配置. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); |
歡迎光臨 (http://www.torrancerestoration.com/bbs/) | Powered by Discuz! X3.1 |