circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

January 2006, Issue 186

Electronic Scarecrow


BASE UNIT SOFTWARE   

The base unit’s code uses approximately 70% of the MC9S08GT16 microcontroller’s 16-KB flash memory, and it includes the serial bootloader with the remote code update feature disabled. The second page of the flowchart posted on the Circuit Cellar FTP site shows the main routine. After initialization, the main loop enables Receive mode and waits for a packet. As it waits, it calls various activity-processing routines.

After a valid packet arrives, its sequence number is checked against the last packet received from the same remote unit. Normally, it will be incremented by one. If it’s the same though, it means the packet is a duplicate, which indicates that the remote unit didn’t get your last reply. If that’s the case, a flag is set and an error counter is incremented. If enough errors occur, the transmit power is increased if it isn’t already at maximum. If the packet number is out of sequence, a flag is set to let you know there was an error.

Next, the incoming packet is processed and a reply is sent. If it isn’t a duplicate data packet, the sensor status is saved and a check is run for trigger events. The remote unit handles some of the output responses (e.g., sound playback and auxiliary output), so the program checks for these right away and sets the appropriate flags in the reply packet. A check for a pending download request is also made so the corresponding flag can be set. If it’s an enable/disable packet, the system master enable flag will be updated. If it’s a ping packet, the various status bytes will be simply saved for later. If a download data request arrives, a block of data will be read from the serial port and sent out the remote unit.