Serial Processing & Packet Handling

Serial Processing Overview

Ultra-Fast Interrupt Context

UART Byte Available
Store Single Byte & Exit
(No Frame Processing)

Critical Points:

  • Absolute minimum time in interrupt!
  • Single byte storage only
  • Doesn't care about partial frames
  • Next interrupt will continue frame
  • No processing or validation here

Frame Reception Example:

Interrupt 1: Bytes 1-3
Store & Exit
Interrupt 2: Bytes 4-5
Store & Exit
Interrupt 3: Bytes 6-8
Store & Exit
Frame assembly happens later in main loop

Main Loop Processing

Check Buffer for New Data
Build Packet Buffer
(If new data available)
Validate Packet Type
(Modbus or 0x7E)
Check CRC & Length

Continuous Timeout Check:

Time since last byte greater than 9/baudrate?
Example: greater than 9ms @9600
Clear Buffer
+
Reset Packet Array

Key Points:

  • Runs continuously in main loop
  • Handles packet assembly
  • Validates packet integrity
  • Clears all buffers if timeout occurs
    (No data received for 1 byte period)

Timeout Handling

No UART Activity
Clear Buffers
Reset State

Important:

  • Timeout based on baud rate period
  • Prevents partial packet processing
  • Ensures clean state for next message

Circular Buffer Operation