|
C8051F54X_14 Datasheet, PDF (172/275 Pages) Silicon Laboratories – Mixed Signal ISP Flash MCU Family | |||
|
◁ |
C8051F54x
Use the following equations to calculate the values for the variables for the baud-rate equation:
multiplier
=
-------2---0----0---0---0---------
baud_rate
â
1
prescaler = ln
ï¨---m-----u----l--t--i-p----l--i-e----r----+----S-1---ï©-Y---ï´-S----C-b----aL---u-K---d----_---r---a---t--e------ï´-----2----0---0--
ï´ ---1----- â 1
ln2
divider = -------------------------------------------------------S----Y-----S----C-----L---K---------------------------------------------------------
ï¨2ï¨prescaler + 1ï© ï´ ï¨multiplier + 1ï© ï´ baud_rateï©
In all of these equations, the results must be rounded down to the nearest integer.
The following example shows the steps for calculating the baud rate values for a Master node running at
24 MHz and communicating at 19200 bits/sec. First, calculate the multiplier:
Next, calculate the prescaler:
multiplier = 2----0---0----0---0-- â 1 = 0.0417 ï 0
19200
prescaler
=
lnï¨---0-----+-----1----ï©2---ï´4----0--1-0--9-0---2-0--0-0--0-0-----ï´-----2----0---0-- ï´
---1----- â 1 =
ln2
1.644 ï 1
Finally, calculate the divider:
divider = 2----ï¨--1-----+-----1----ï©---2-ï´--4----0ï¨--0-0---0-+---0--1-0---ï©0----ï´-----1----9---2---0----0- = 312.5 ï 312
These values lead to the following baud rate:
baud_rate = 2----ï¨--1-----+-----1----2ï©---4-ï´--0----0ï¨--0-0---0-+---0--1-0---ï©----ï´-----3----1---2-- ï 19230.77
The following code programs the interface in Master mode, using the Enhanced Checksum and enables
the interface to operate at 19230 bits/sec using a 24 MHz system clock.
LIN0CF = 0x80;
LIN0CF |= 0x40;
// Activate the interface
// Set the node as a Master
LIN0ADR = 0x0D;
// Point to the LIN0MUL register
// Initialize the register (prescaler, multiplier and bit 8 of divider)
LIN0DAT = ( 0x01 << 6 ) + ( 0x00 << 1 ) + ( ( 0x138 & 0x0100 ) >> 8 );
LIN0ADR = 0x0C;
// Point to the LIN0DIV register
LIN0DAT = (unsigned char)_0x138;
// Initialize LIN0DIV
LIN0ADR = 0x0B;
LIN0DAT |= 0x80;
// Point to the LIN0SIZE register
// Initialize the checksum as Enhanced
LIN0ADR = 0x08;
// Point to LIN0CTRL register
LIN0DAT = 0x0C;
// Reset any error and the interrupt
Table 19.2 includes the configuration values required for the typical system clocks and baud rates:
172
Rev. 1.1
|
▷ |