AVR tutorial 7

Last change : 13 November 2006 recompiled using WinAVR 20060412.

17 April 2006 : A small bug has been fixed in the fifo.inc file. The RX bit count was applied to both the RX and TX buffers. Download the new Zips or simply correct your older file manually.

25 January 2006
SLIP packet communications using a ATMega 8.

SLIP protocol has been around for many years and provides a simple "packetizer" for serial data.

SLIP

SLIP originally provided a service for transmitting IP packets over a serial line. Since then the protocol has become a standard and has been used for many other packet based communications. The protocol does NOT provide error protection, error correction, routing etc. The only thing it provides, is start and end of packet markers. The beauty of the protocol is in it's simplicity. It transmits packets over a stream of data, everything else is up to you.
You can download the original SLIP protocol documentation here (5KB).

Circuit diagram



Software.

The files included :
usart.gif : the above circuit diagram.
main.c : the main c application.
fifo.c : the fifo interface, used by main.c.
fifo.inc : defines the size of the fifo buffers.
fifo.h : the header file, used by main.c for the function prototypes.
slip.c : the slip interface to the fifo buffers. included in fifo.c
usart001_drv.c : the uart driver routines. This file is included in fifo.c.
usart001_drv.h : the header file, only used by fifo.c for the function prototypes.
usart001_drv.inc : baud rate constants and defines.
hw.h : defines the crystal speed.
makefile : the make file.

Structure

The only file the main application interacts with is the FIFO file. The primary reason for this is that although this application uses the AVR's uart (called by fifo.c), the main application should not be concerned with the specifics of the hardware communications interface.

One of the advantages of SLIP is that the packet start and stops are indicated with real bytes and not quiet times. Because of this, the main routine does not have to check on the received bytes very frequently.
The tx and rx interrupt routines will move data to and from the fifo circular buffers.

The receive fifo elastic buffer act as both the interrupt interface and an unprocessed packet storage. Only once the buffer run the risk of overflowing does the main routine have to ask for any new SLIP packets.

Download (28KB) the software and diagram in one Zip.

SLIP only

Here is zip containing the stripped SLIP only FIFO. Removing all other FIFO access routines reduces the firmware and demonstrates just how easy it is to use the SLIP FIFO.
Download (26KB) the software and diagram in one Zip.

This project will only return valid SLIP packets if the packet consists of a minimum of 5 bytes. ie 1 data byte

Serial setup.

9600 baud.
1 stop bit.
0 parity bits.
Full duplex

A SLIP terminal is still to be added to the project.

How to.

To build your project simply extract all the files to the same directory.
Next, using programmers note pad, open main.c.
Now click on tools and then on make all.

Note: The provided makefile is generated for a SP12 type programmer as shown in tutorial 2. If you are using a different programmer you'll have to edit the makefile.

Program the device, insert it into the circuit and plug the db9 into your PC's serial port.
Power up the circuit.
Interact with the hardware using a SLIP terminal application.

For a terminal application, use a SLIP compatible terminal like the one found here.


On to the list of tutorials

Home mail add