凯恩斯

导航

stm32F407 GPIO库函数操作

  比如配置PA9、PA10为USART1

第一步:使能GPIOA的时钟

   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 

第二步:配置PA9、PA10的模式、工作速度、输出推挽或开漏、上拉或下拉电阻

        1.   GPIO_InitTypeDef GPIO_InitStructure;

        2.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
        3.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;            //复用模式
        4.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;  
        5.   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;      //输出为推挽模式
        6.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;             //接上拉电阻
        7.   GPIO_Init(GPIOA, &GPIO_InitStructure);

最后将PA9、PA10复用为USART1:
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);    //PA9->USART_TX
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);  //PA10->USART_RX

posted on 2015-12-12 14:31  凯恩斯  阅读(481)  评论(0)    收藏  举报