[求助] STM32F103C8 usart2发送端口一直输出低电平,求大家帮忙看下程序

肚肚嘿嘿   2015-7-3 22:42 楼主
void usart2_config(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;     
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;        
  NVIC_Init(&NVIC_InitStructure);

       
       
       
        RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB2Periph_GPIOA, ENABLE);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
          USART_InitStructure.USART_BaudRate = 115200;                 /*éèÖÃ2¨ìØÂêÎa115200*/
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;  /*éèÖÃêy¾YλÎa8λ*/
    USART_InitStructure.USART_StopBits = USART_StopBits_1;       /*éèÖÃí£Ö1λÎa1λ*/
    USART_InitStructure.USART_Parity = USART_Parity_No;          /*ÎTÆæżD£Ñé*/   
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /*ûóDó2¼tá÷¿Ø*/
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;      /*·¢Ëíóë½óêÕ*/
    /*íê3é′®¿úCOM1μÄê±ÖóÅäÖá¢GPIOÅäÖ㬸ù¾YéÏêö2Îêy3õê¼»ˉ2¢ê1Äü*/
       
        USART_Init(USART2, &USART_InitStructure);
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
        //USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
        USART_Cmd(USART2, ENABLE);       
        USART_ClearFlag(USART2,USART_FLAG_RXNE);
        USART_ClearITPendingBit(USART2, USART_IT_RXNE);
}

回复评论 (3)

求助求助
点赞  2015-7-3 23:23
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB2Periph_GPIOA, ENABLE);
这个的问题,请仔细检查
处处留心皆学问!
点赞  2015-7-6 13:52
没有设置通道吧!!
点赞  2015-7-10 10:35
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复