Serial Port Complete - Latest Microcontroller projects

(lily) #1
Network Programming

Firmware is responsible for determining the value of the ninth bit to transmit
and interpreting the value of a received ninth bit. The hardware has no built-in
support for setting and detecting address/data bytes. Firmware must also define
an 8-bit address for the device.
To use address detecting with 9-bit data, in the RCSTA register, set ADDEN =


  1. A computer that wants to communicate with the device must begin by send-
    ing a 9-bit word consisting of the device’s address with the ninth (most signifi-
    cant) bit = 1. In the PIR1 register, RCIF will be set only after receiving a word
    whose ninth bit = 1. When RCIF = 1, firmware should read the received byte. If
    the byte matches the device’s address, firmware sets ADDEN = 0 to enable
    reading data. All received words that follow with bit 9 = 0 contain data
    intended for the device. On receiving a word with bit 9 = 1, firmware should
    again check for a matching address. If it’s not a match, firmware should set
    ADDEN = 1 to disable setting RCIF on any data that follows.
    Other microcontrollers, such as Maxim Integrated Products, Inc.’s DS89C420,
    can store a node address and a broadcast address and respond only when a
    received address matches one of these values.



The UARTs in PCs typically don’t have full hardware support for 9-bit proto-
cols, but applications can use Mark and Space parity to implement a soft-
ware-assisted 9-bit protocol.
Before changing the parity type, an application should ensure that all data writ-
ten with the previous parity setting has transmitted. Chapter 6 described meth-
ods for finding out when the data has finished transmitting to determine when
it’s OK to disable an RS-485 driver. The same methods are also useful for deter-
mining when it’s OK to change the parity type. An application that sends 9-bit
data might also need to add delays to ensure that the receiving computer pro-
cesses received bytes in the correct order, as described below.
To use 9-bit data in a .NET application, set the SerialPort object’s DataBits
property to 8 and set the ParityReplace property to zero to disable the par-
ity-replace feature. The ParityReplace property can specify a byte that will
replace any byte received with a parity error. With 9-bit data, you want to pre-
serve the data rather than overwrite it.

 myComPort.DataBits = 8
myComPort.ParityReplace = 0
myComPort.Open

Free download pdf