本帖最后由 xiaoluoshan 于 2018-11-8 15:43 编辑
在任务中,发送数据前,置位标志位1,填好第一包使能发送中断,后续发送在中断中处理,中断发送结束后,置位标志位为0,并关闭发送中断; 在中断中接受数据,接受完一帧数据后,发送给任务处理;
在发送数据的同时,下发数据,会出现不进入中断的情况:
中断处理代码为: void UARTISR () { GR_U32 u32int_id = 0; GR_U32 u32fifo_status = 0; GR_U8 u8CharData = 0;//收到的1字节数据 GR_U32 u32SerialData= 0; GR_U16 u16Class = 0,u16Type = 0; GR_U16 u16PutCharCount = 0, u32Temp;
// 确定中断源 u32int_id = UARTIntStatus(SOC_UART_1_REGS); //IntEventClear(SYS_INT_UART1_INT);
// 发送中断 if (UART_INTID_TX_EMPTY == u32int_id) { if (DalUartSendBusy(UART1)) { while ((tUart1Buf.u32SendBufPos < tUart1Buf.u32SendBufLen) && (u16PutCharCount < 16)) { HWREG(SOC_UART_1_REGS + UART_THR) = tUart1Buf.u8SendBuf[tUart1Buf.u32SendBufPos]; tUart1Buf.u32SendBufPos++; u16PutCharCount++; } } if (DalUartSendBusy(UART1)) { if (tUart1Buf.u32SendBufPos == tUart1Buf.u32SendBufLen) { tUart1Buf.u32SendBufPos = 0; tUart1Buf.u32SendBufLen = 0; tUart1Buf.s32SendStatus = 0; UARTIntDisable(SOC_UART_1_REGS, UART_INT_TX_EMPTY); } } } // 接收中断 if (UART_INTID_RX_DATA == u32int_id) { u32fifo_status = DalUartReadBusy(UART_PORT); vCommPortTimersEnable(); while (u32fifo_status) { //接收串口数据,放到全局缓冲区中 DalUartCharGet(UART_PORT, (GR_S8 *)&u8CharData, 0); // 拷贝至全局数组中 ………………………… u32fifo_status = DalUartReadBusy(UART_PORT); } } // 接收错误 if (UART_INTID_RX_LINE_STAT == u32int_id) { u32Temp = UARTRxErrorGet(SOC_UART_1_REGS); while(u32Temp) { while(DalUartReadBusy(UART_PORT)) { // 从 RBR 读一个字节 UARTCharGetNonBlocking(SOC_UART_1_REGS); } u32Temp = UARTRxErrorGet(SOC_UART_1_REGS); } } else if ((UART_INTID_RX_LINE_STAT != u32int_id) && (UART_INTID_RX_DATA != u32int_id) && (UART_INTID_TX_EMPTY != u32int_id)) { u32int_id = u32int_id; } }
|