INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18) { /* In order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction. */ u8 RX_Data; if(UART1_GetITStatus(UART1_IT_RXNE )!= RESET) { /*接收中断*/ RX_Data =UART1_ReceiveData8(); if(Rs485_Rx_Finished_Flag==0) { if(UART1_RX_Count == 0) { if(RX_Data == 0xFF) { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; } else { UART1_RX_Count = 0; Checksum = 0; } } else if(UART1_RX_Count == 1) { if(RX_Data == 0xFF) { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; } else { UART1_RX_Count = 0; Checksum = 0; } } else if(UART1_RX_Count == 2) //模块类型 { if((RX_Data == Module_type_485)||(RX_Data == Module_type_EQ1)||(RX_Data == Module_type_EQ2)) { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; Checksum += RX_Data; } else { UART1_RX_Count = 0; Checksum = 0; } } else if(UART1_RX_Count == 3) //ID号 { if((RX_Data == Module_ID)||(RX_Data == 0xFE)) { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; Checksum += RX_Data; } else { UART1_RX_Count = 0; Checksum = 0; } } else if(UART1_RX_Count == 4) //长度=数据长度N+2,整包长度= 长度+5。 { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; Length_Rx_485 = RX_Data; Checksum += RX_Data; } else if(UART1_RX_Count == 5) //指令,PING:0x01,READ DATA:0x02,WRITE DATA:0x03,REG WRITE:0x04,ACTION:0x05,RESET:0x06,SYNC WRITE:0x07。 { if((RX_Data == PING)||(RX_Data == READ_DATA)||(RX_Data == WRITE_DATA)||(RX_Data == REG_WRITE)||(RX_Data == ACTION)||(RX_Data == RESET)||(RX_Data == SYNC_WRITE)) { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; Checksum += RX_Data; } else { UART1_RX_Count = 0; Checksum = 0; } } else { UART1_RX_Buffer[UART1_RX_Count++] = RX_Data; if(UART1_RX_Count<(Length_Rx_485 + 5)) { Checksum += RX_Data; } else if(UART1_RX_Count >= (Length_Rx_485 + 5)) { if((255-Checksum) == RX_Data) { UART1_RX_Count = 0; Length_Rx_485 = 0; Checksum = 0; Rs485_Rx_Finished_Flag = 1; return; } else { UART1_RX_Count = 0; Length_Rx_485 = 0; Checksum = 0; Rs485_Rx_Finished_Flag = 0; return; } } } } } }