January
2006, Issue 186
Electronic
Scarecrow
REMOTE
UNIT SOFTWARE
The
application code, which I wrote in C language with CodeWarrior
3.1 from Metrowerks (now Freescale Developer Technology
Organization), uses the SMAC 4.0 protocol stack. This
isn’t ZigBee- or 802.15.4-compliant because I don’t
need compatibility with other devices.
When
I started development, I found that the software for
downloading the boards wouldn’t run on Windows 98. The
demonstration programs and the compiler were fine, but
I couldn’t download new code. There weren’t any alternatives
(short of upgrading my PC), so I made my own. Because
I didn’t need any of the ZigBee embedded bootloader’s
special features, I found a generic serial bootloader
and borrowed a P&E Microcomputer Systems BDM Multilink
download cable so I could try it out. The bootloader
also came with a DOS program (hc08sprg.exe) that talks
to it over a serial port. (You may download the hc08sprg.exe
file from the Circuit Cellar FTP site.) I used the bootloader
for the rest of the development process.
The
entire application fits in 7 KB of flash memory, leaving
8.5 KB available to store a PCM sound file. This provides
about one 1 s of sound at 8 kHz. I wanted to be able
to download a new sound file or update the running code
over the radio link. The latter required some changes
to the serial bootloader, which sits in a 512-byte protected
area at the top of the flash memory. To free up enough
space to add the update function, I replaced the bootloader’s
flash memory routines with smaller ones from a MC9S08GB/GT
serial monitor. The remote download feature enabled
me to update both the base and all of the remotes through
the base unit’s serial port.
The
radio link operates with a simple request and reply
protocol. A remote unit sends a request whenever it
has something to report such as a sensor trigger event
or the press of a switch. It also sends ping packets
with the results of sensor tests performed at regular
intervals. The base unit always responds by sending
back a reply packet. The remote unit handles the resending
of missed packets. Because packets are sent infrequently,
any external RF interference is usually different from
one packet to the next. Therefore, searching for the
quietest channel didn’t make sense, so I just went with
a fixed channel.
The
SMAC stack had all the features required for this simple
protocol. I added a few functions for system control,
including support for Timer2 and Doze mode, the ability
to read GPIO pins, and control over the ATTN pin interrupt.
I also made a few changes to decrease the execution
time of some frequently used routines.