Serial Port Complete - Latest Microcontroller projects

(lily) #1
Ports for Embedded Systems

The value of the multiplier variable depends on the values in BRG16 and
BRGH:

If multiplier = 16 and spbrg < 256, firmware can achieve the same bit rate by
setting BRGH = 1 and BRG16 = 0 or by setting BRGH = 0 and BRG16 =1. If
multiplier = 16 and spbrg> 255, firmware must set BRGH = 0 and BRG16 = 1.
bitRate is the desired bit rate.
To find the setting that results in the closest bit rate to the desired value, per-
form the calculation with each of the three multiplier values. This formula cal-
culates the actual bit rate that results from specific values:
actualBitRate = Round(fosc / (multiplier * (spbrg + 1)))
Thefosc and multiplier variables are set as described above. Depending on the
value of BRG16, spbrg is the 8-bit value in SPBRG or the 16-bit value in
SPBRGH and SPBRG. If BRG16 = 1 and spbrg is greater than 255, you need
to divide spbrg into its lower and higher bytes:
spbrgl = spbrg Mod 256
spbrgh = Int(spbrg / 256)
A carefully selected FOSC frequency can result in a calculated bit rate with zero
error. However, the hardware oscillator can still introduce error if the oscillator
doesn’t operate at exactly its rated frequency.





Firmware can use hardware interrupts to cause program code to branch to an
interrupt service routine (ISR) when the serial port has received data or when
the port’s transmit buffer is empty and ready to store new data to send. Firm-
ware can also set priority levels for specific interrupts to service critical inter-
rupts as quickly as possible. For serial communications at fast bit rates, using a
high-priority interrupt can be useful in preventing overflows of the receive
buffer.

#;. #;<3 
0064
0116
1016
114
Free download pdf