2
AVR350
1472D-AVR-01/08
2 Theory of Operation
Xmodem is a half-duplex communication protocol. The Receiver, after receiving a
packet, will either acknowledge (ACK) or not acknowledge (NACK) the packet. The
original Xmodem protocol used a standard checksum method to verify the 128-byte
data packet. The CRC extension to the original protocol uses a more robust 16-bit
CRC to validate the data block and is used here. Xmodem can be considered to be
receiver driven. That is, the Receiver sends an initial character “C” to the sender
indicating that it’s ready to receive data in CRC mode. The Sender then sends a 133-
byte packet, the Receiver validates it and responds with an ACK or a NACK at which
time the sender will either send the next packet or re-send the last packet. This
process is continued until an EOT is received at the Receiver side and is properly
ACKed to the Sender. After the initial handshake the receiver controls the flow of data
through ACKing and NACKing the Sender.
Table 2-1.
XmodemCRC Packet Format
Byte 1
Byte 2
Byte 3
Bytes 4 - 131
Bytes 132 - 133
Start of Header
Packet Number
~(Packet Number)
Packet Data
16 bit CRC
3 Definitions
The following defines are used for protocol flow control.
Table 3-1.
Protocol Flow Control
Symbol Description
Value
SOH
Start of Header
0x01
EOT
End of Transmission
0x04
ACK Acknowledge
0x06
NACK Not
Acknowledge
0x15
C ASCII
“C”
0x43
Byte one of the XmodemCRC packet can only have a value of SOH or EOT, anything
else is an error. Bytes two and three form a packet number with checksum, add the
two bytes together and they should always equal 0xff. Please note that the packet
number starts out at “1” and rolls over to “0” if there are more than 255 packets to be
received. Bytes 4 - 131 form the data packet and can be anything. Bytes 132 and 133
form the 16-bit CRC. The high byte of the CRC is located in byte 132.
4 Synchronization
The Receiver starts by sending an ASCII “C” (0x43) character to the sender indicating
it wishes to use the CRC method of block validating. After sending the initial “C” the
receiver waits for either a three second time out or until a buffer full flag is set. If the
receiver is timed out then another “C” is sent to the sender and the three second time
out starts again. This process continues until the receiver receives a complete 133-
byte packet.