不知道怎么了,串口发不出数据了

2019-07-21 07:14发布

串口1接收16进制数据01 02 03 04 05,然后发送到串口助手中,但是接收到的都是00 00 00,这是什么情况?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
9条回答
支持者2400
2019-07-21 09:52
[mw_shl_code=applescript,true]void uart_init(u32 bound){
  //GPIO¶Ë¿úéèÖÃ
  GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
         
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);        //ê1ÄüUSART1£¬GPIOAê±Öó
  
        //USART1_TX   GPIOA.9
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;        //¸′óÃíÆíìêä3ö
  GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉGPIOA.9
   
  //USART1_RX          GPIOA.103õê¼»ˉ
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿Õêäèë
  GPIO_Init(GPIOA, &GPIO_InitStructure);//3õê¼»ˉGPIOA.10  

  //Usart1 NVIC ÅäÖÃ
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//ÇàÕ¼óÅÏ輶3
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;                //×óóÅÏ輶3
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                        //IRQí¨μàê1Äü
        NVIC_Init(&NVIC_InitStructure);        //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷
  
   //USART 3õê¼»ˉéèÖÃ

        USART_InitStructure.USART_BaudRate = bound;//′®¿ú2¨ìØÂê
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö3¤Îa8λêy¾Y¸ñê½
        USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
        USART_InitStructure.USART_Parity = USART_Parity_No;//ÎTÆæżD£Ñéλ
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;        //êÕ·¢Ä£ê½

  USART_Init(USART1, &USART_InitStructure); //3õê¼»ˉ′®¿ú1
  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//¿aÆô′®¿ú½óêüÖD¶Ï
  USART_Cmd(USART1, ENABLE);                    //ê1Äü′®¿ú1

}

void USART1_IRQHandler(void)
{
         u8 res;          
   
        if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) // ½óêÕμ½êy¾Y   
        {                
                  res =USART_ReceiveData(USART1);                //¶á衽óêÕμ½μÄêy¾YUSART1->DR
       
      USART_SendData(USART1,res);
       
}
}[/mw_shl_code]

一周热门 更多>