SCREENSHOT 1. The Break signal has a width of 0.677
milliseconds which equates to a Start bit and 12 zero bits
at 19200 baud. All we had to do to generate the Break
signal was set a bit and send a dummy character.
components are large enough to be easily mounted and
soldered by hand without the need for specialized soldering
equipment. The PCB silk screen legends give a visual cue to
the orientation of the MCP2021 and PIC18F2620.
You really can’t miss with D4. However, to make the
assembly process as straightforward as possible, the diode
component enumerators (D1, D2, D3, D4, LED1, LIN) are all
placed near the cathode pad of the respective device. The only
polarized capacitor is C3 and if you match the capacitor’s base
plate with the PCB silk screen, mounting C3 is a no-brainer.
Once you’ve pulled all of the electronic components
together on your bench, carefully mount and solder them to the
PCB. When the solder smoke clears, you will have assembled
a LIN Development Board like the one you see in Photo 2.
by 12 zero bits and a Stop bit. The Sync character is
actually a byte with the value of 0x55 that follows the
Break sequence. In a regulation LIN frame, the Break-Sync
signal is followed by a protected identifier byte and what
is termed the response — which is one to eight bytes of data.
The LIN frame is topped off with a checksum byte. There
are two types of checksums. The enhanced checksum
includes the protected identifier in the checksum calculation
while the classic checksum only covers the data. Right now,
we’re only interested in synthesizing the Break and Sync signals.
So, let’s put some simple code together to do just that.
It doesn’t take much to coax a Break-Sync signal out of the
PIC18F2620’s EUSART. Here’s the code I used to generate the
waveform captured by my logic analyzer in Screenshot 1:
SENDB = 1;
//set the SEND BREAK bit
//send dummy character
//send autobaud chirp
Let’s See If It Works
The best place to start our functional testing is at the
beginning of a LIN frame. A Break-Sync sequence is sent
with every LIN frame. A standard RS-232 sniffer won’t like
the way the Break-Sync sequence looks. So, a logic analyzer
would work well for us here. Photo 3 is a bird’s eye view
of the Saleae logic analyzer I’m going to use to capture a
Break-Sync sequence in real time.
The PIC18F2620’ EUSART subsystem is designed to emit
a LIN Break-Sync signal which consists of a Start bit followed
PHOTO 4. This is a must-have tool if you’re going to develop LIN
applications. I got this one from Microchip DIRECT. If you want
to build one of these from scratch, you can get the full schematic
and firmware driver from a download on the Microchip website.
Setting the SENDB bit forces the PIC’s EUSART to send
the LIN Break signal. The 0x55 that is sent after setting the
SENDB bit is ignored and 0x00 is sent instead. The second 0x55
is actually transmitted. The slave node sees the Break signal and
prepares to receive and time the bit widths of the 0x55 byte.
The next byte a LIN slave expects to see is the protected
identifier. For this example, we’ll use the 0x3E identifier which
indicates that a LIN user-defined message is in the incoming
frame. We must add a checksum to the two most significant
bits of the identifier. That will result in us actually sending
0xFE as our identifier byte. The Break-Sync sequence and
the protected identifier make up the LIN frame header.
Let’s set the EUSART baud rate for 9600 bps and
send four bytes of data (0x4A, 0x55, 0x93, 0xE5) behind a
protected identifier of 0x3E. I’ve put together a function to
do all of the work:
#define make8(var,offset) \
((unsigned int)var >> (offset 8)) & 0x00FF
//protected ID bit fields
char id0: 1;
char id1: 1;
char id2: 1;
char id3: 1;
char id4: 1;
char id5: 1;
char p0: 1;
char p1: 1;
void send_frame4(char id, char data1, char
data2, char data3, char data4)
40 SERVO 06.2009