| 我使用的是STM32F427VG,现在做的部分是PC机通过串口配置3个传感器。 大致流程是这样的,PC机与板子通过UART4通信,然后将收到的数据转发给指定串口,取配置传感器。使用了UART4,USART1,USART3,USART6。UART4能够正常的向每个串口发送数据,但是USART3和USART6没有收到反馈,USART1能收到反馈。
 单步调试,得到发现反馈数据进入了USART_SendData函数,但是数据没有输出来。
 简化,只进行UART4与USART3之间相互透传,UART4收到数据可以通过USART3传出,而USART3收到的数据透传进入USART_SendData,但是收不到数据。USART6与USART3之间透传没问题,USART1与UART4之间透传没问题。
 找到的可能线索,USART3与USART6在同一个max3223上,UART4与USART1在同一个max3223上。
 
 串口配置代码:
 
 复制代码void UART_Configuration(void)
{
        USART_InitTypeDef USART_InitStructure;
 
  /* USART resources configuration (Clock, GPIO pins and USART registers) ----*/
  /* USART configured as follow:
        - BaudRate = 115200 baud
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
  */
        
        /*USART1 Configure*/
        USART_DeInit(USART1); 
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
 
  /* USART configuration */
  USART_Init(USART1, &USART_InitStructure);
        USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
 
  /* Enable the USART1 */
  USART_Cmd(USART1, ENABLE);
        
        
        /*USART3 Configure*/
        USART_DeInit(USART3); 
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
 
  /* USART configuration */
  USART_Init(USART3, &USART_InitStructure);
        USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
 
  /* Enable the USART3 */
  USART_Cmd(USART3, ENABLE);
        
        /*USART6 Configure*/
        USART_DeInit(USART6); 
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
 
  /* USART configuration */
  USART_Init(USART6, &USART_InitStructure);
        USART_ITConfig(USART6,USART_IT_RXNE,ENABLE);
 
  /* Enable the USART6 */
  USART_Cmd(USART6, ENABLE);
        
        /*UART4 Configure*/
        USART_DeInit(UART4); 
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
        
        /* UART configuration */
        USART_Init(UART4,&USART_InitStructure);
        USART_ITConfig(UART4,USART_IT_RXNE,ENABLE);
        
  /* Enable the UART4 */
        USART_Cmd(UART4, ENABLE);
        
        /*UART7 Configure*/
        USART_DeInit(UART7); 
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
        
        /* UART configuration */
        USART_Init(UART7,&USART_InitStructure);
        USART_ITConfig(UART7,USART_IT_RXNE,ENABLE);
        
        /* Enable the UART7 */
        USART_Cmd(UART7, ENABLE);
}
 中断处理代码(设置标志位,然后再在while循环里处理)
 
 复制代码
void USART1_IRQHandler(void)                //´®¿ÚÖжϴ¦Àíº¯Êý
{
        if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
        {
                Buf1 = USART_ReceiveData(USART1);
                USART_ClearITPendingBit(USART1, USART_IT_RXNE);        
                Flag=1;
        }
}
void USART3_IRQHandler(void)
{
        Buf3 = USART_ReceiveData(USART3);
        
        USART_ClearITPendingBit(USART3, USART_IT_RXNE);
        Flag=1;
}
void UART4_IRQHandler(void)
{
        Buf4 = USART_ReceiveData(UART4);
        
        USART_ClearITPendingBit(UART4, USART_IT_RXNE);
 Flag=1;
}
void USART6_IRQHandler(void)
{
        Buf6= USART_ReceiveData(USART6);
        
        USART_ClearITPendingBit(USART6, USART_IT_RXNE);
        Flag=1;
}
 
 | 
我开始就是这么做的,可是能发不过去,我才试这种的
找到原因的,是max3223芯片的forceon脚的问题。