enable the receive interrupt structure and wait for incoming
characters. I blink the node’s LED1 at this point. In a real
world application, useful work will be performed while
waiting for the incoming characters.
SCREENSHOT 3. In this composite capture, the first byte in the
PIC18F2620’s EUSART receive buffer at offset 0x00 is a no load
as the buffer ring pointers were initialized before the frame
was transmitted. You should be able to easily identify the
PID beginning at offset 0x01 and the classic frame checksum
at offset 0x0A.
Let’s configure the LIN Serial Analyzer as a master node
and send some data to our LIN slave which is running the
small driver we just analyzed. I’ve blinded the PIC18F2620’s
EUSART by commenting out the preset baud rate divisor.
This will test the slave node’s Auto-Baud detect firmware
we’ve assembled:
//***********************************************
//* Init EUSART Function
//*************************************
void init_EUSART(void)
{
// load baud rate divisor for 19200
// bps with 20MHz clock = 64
// load baud rate divisor for 9600 bps
// with 20MHz clock = 129
SPBRG = 129;
As you can see in Screenshot 3, I configured the LIN Serial Analyzer to send a 10-byte
frame with an identifier of 0x3C and a classic
frame checksum. The buffer ring data dump
embedded in the LIN Serial Analyzer window
is a capture of the MPLAB Watch window
displaying the data that was placed into the
PIC18F2620’s circular receive buffer.
Let’s have some fun and only send an
identifier to the slave using the LIN Serial
Analyzer as the master node. We’ll program
the slave to return 11 22 33 plus the enhanced
frame checksum byte as a response when it
sees the correct identifier which in this case
is 0x02. We already have the Break-Sync,
Auto-Baud detector, frame checksum calculator,
and frame transmission firmware written and
tested. All we have to do to build our slave
response is add some PID parsing routines and
some response generation code like this:
if(RCIDL)
{
//make sure receive
//not in progress
LIN_RX; //put MCP2021 in Rx mode
disable_RXint; //disable the Rx
//interrupt
SET_WUE; //enable WakeUp
//Enable
SET_ABDEN; //enable autobaud
//feature
IDLEN = 1; //idle CPU only
//while sleeping
SCREENSHOT 4. I’ll call the play-by-play in LIN
lingo. The LIN Serial Analyzer is acting as a LIN
master and publishes a PID of 0x42 (identifier of
0x02). The LIN slave subscribes to the PID sent by
the master and returns the required three bytes
as per the application’s requirements.
48 SERVO 07.2009