Chapter 12
A message format can also define a field that indicates the length of the data
that follows, and receiving nodes can use this value to determine when a mes-
sage ends.
0
A header is information that uses a defined format and appears at the beginning
of a message or other block of data. The header typically consists of a series of
fields, with each field having a defined size and location. The information
included in a header can vary. A header might include some or all of these
items:
- Start-of-communication code.
- Address of the receiving node.
- Address of the sending node.
- Length of the data that follows the header.
- Checksum or other value used for error detection.
- Description of the type of data that follows.
- Time and date information.
)"4
Another option for distinguishing between addresses and data uses a 9-bit for-
mat. Bit 8 (the ninth bit) indicates whether bits 0–7 contain data (0) or an
address (1). Not all UARTs support the 9-bit format. The longer words in 9-bit
data mean that communications are slightly more sensitive to mismatches in
the rates at the transmitting and receiving ports. Messages that consist of only
US ASCII text can use seven data bits for a text character and the eighth bit to
indicate address or data.
Some microcontrollers have a built-in ability to use the ninth bit to detect an
address. The PIC18F4520 introduced in Chapter 11 is an example.
To transmit 9-bit data, PIC18F4520 firmware must set the TX9 bit in the
TXSTA register to 1. Before writing a byte to transmit to TXREG, firmware
should write the ninth bit to the TX9D bit in TXSTA.
To receive 9-bit data, firmware must set the RCSTA register’s RX9 bit to 1.
Before reading RCREG to obtain a received byte, firmware should read the
RCSTA register’s RX9D bit to obtain the ninth bit.