The invention provides a data receiving and
processing method based on
serial port idle interruption and memory direct transmission. The method comprises the following steps of: S1, initializing a multi-stage buffer area, enabling idle interruption and DMA (
Direct Memory Access) by a UART S2,
serial port receiving and DMA transmission are started; s3, automatically transmitting data to an active buffer area by a DMA background, identifying frame ending with 1.5 times of character idle duration through idle interruption, and detecting whether communication of a
serial port is abnormal or not in combination with a
heartbeat packet and overtime detection design; s4, the
effective length of the data is calculated through the address offset, the data is copied to the to-be-processed buffer area, the buffer area is switched, and finally the
application layer is notified; s5, the
application layer carries out CRC
verification on the data, the data is processed if the CRC
verification passes, and the data is retransmitted if the CRC
verification fails; and S6, initializing the serial port and the DMA when the serial port communication is judged to be abnormal. According to the method, through idle interruption, DMA, a multi-level buffer area and exception
recovery, efficient receiving of the variable-length data is achieved, CPU occupation is reduced, and communication reliability is improved.