新手上路 
 
	- 积分
 - 25
 
        - 金钱
 - 25 
 
       - 注册时间
 - 2017-10-5
 
      - 在线时间
 - 4 小时
 
 
 
 | 
 
3金钱 
STM32F767用到2个串口:串口1,230400,DMA发送,中断接收;串口5,460800,DMA发送,中断接收。初始化程序如下: 
//初始化函数 
void MX_UART5_Init(void) 
{ 
  huart5.Instance = UART5; 
  huart5.Init.BaudRate = 460800; 
  huart5.Init.WordLength = UART_WORDLENGTH_8B; 
  huart5.Init.StopBits = UART_STOPBITS_1; 
  huart5.Init.Parity = UART_PARITY_NONE; 
  huart5.Init.Mode = UART_MODE_TX_RX; 
  huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE; 
  huart5.Init.OverSampling = UART_OVERSAMPLING_16; 
  huart5.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 
  huart5.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 
  if (HAL_UART_Init(&huart5) != HAL_OK) 
  { 
    _Error_Handler(__FILE__, __LINE__); 
  } 
  HAL_UART_Receive_IT(&huart5, RS422Type.RxTmpBuf, 1); 
} 
/* USART1 init function */ 
 
void MX_USART1_UART_Init(void) 
{ 
  huart1.Instance = USART1; 
  huart1.Init.BaudRate = 230400; 
  huart1.Init.WordLength = UART_WORDLENGTH_9B; 
  huart1.Init.StopBits = UART_STOPBITS_2; 
  huart1.Init.Parity = UART_PARITY_EVEN; 
  huart1.Init.Mode = UART_MODE_TX_RX; 
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 
  huart1.Init.OverSampling = UART_OVERSAMPLING_16; 
  huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; 
  huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 
  if (HAL_UART_Init(&huart1) != HAL_OK) 
  { 
    _Error_Handler(__FILE__, __LINE__); 
  } 
  HAL_UART_Receive_IT(&huart1, RS232Type.RxTmpBuf, 1); 
} 
//串口中断函数 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 
{ 
        if(huart->Instance==USART1)//如果是串口1 
        { 
                if(RS232Type.RxTmpBuf[0]==0x55 && RS232Type.rx_len==0) 
                { 
                        RS232Type.RxBuf[0]=RS232Type.RxTmpBuf[0]; 
                        RS232Type.rx_len=1; 
                } 
                else if(RS232Type.RxTmpBuf[0]==0xAA && RS232Type.rx_len==1) 
                { 
                        RS232Type.RxBuf[1]=RS232Type.RxTmpBuf[0]; 
                        RS232Type.rx_len=2; 
                } 
                else if(RS232Type.rx_len>1 && RS232Type.rx_len<12) 
                { 
                        RS232Type.RxBuf[RS232Type.rx_len]=RS232Type.RxTmpBuf[0]; 
                        RS232Type.rx_len++; 
                        if(RS232Type.rx_len>=12) 
                        { 
                                RS232Type.rx_len=0; 
                                HAL_UART_Transmit_DMA(&huart1,RS232Type.RxBuf,12);         
                        } 
                } 
                else 
                { 
                        RS232Type.rx_len=0; 
                } 
                HAL_UART_Receive_IT(&huart1,RS232Type.RxTmpBuf,1); 
        } 
        else if(huart->Instance==UART5)//如果是串口5 
        { 
                if(RS422Type.RxTmpBuf[0]==0x90 && RS232Type.rx_len==0) 
                { 
                        RS422Type.RxBuf[0]=RS422Type.RxTmpBuf[0]; 
                        RS422Type.rx_len=1; 
                        HAL_GPIO_WritePin(GPIOA, LED2_Pin|LED4_Pin|LED5_Pin|LED3_Pin, GPIO_PIN_RESET); 
                } 
                else if(RS422Type.rx_len>=1 && RS422Type.rx_len<12) 
                { 
                        RS422Type.RxBuf[RS422Type.rx_len]=RS422Type.RxTmpBuf[0]; 
                        RS422Type.rx_len++; 
                        if(RS422Type.rx_len>=12) 
                        { 
                                RS422Type.rx_len=0; 
                                //90 FF FC 69 FF F9 A0 00 01 DC 00 CA,共12个字节 
                                 
                        } 
                } 
                else 
                { 
                        RS422Type.rx_len=0; 
                } 
                HAL_UART_Receive_IT(&huart5,RS422Type.RxTmpBuf,1); 
        } 
} 
767先上电,设备再上电通信正常,但设备先上电,再运行767,767进不了串行中断。请指正。 
 
 |   
 
 
 
 
 
 |