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





 

January 2006, Issue 186

Electronic Scarecrow


CODE UPDATES

You can download updated code for the base and remote units via the serial port on the base unit. For base unit updates, the PC talks directly to the serial bootloader. I wanted the remote update to use the same protocol, so I set up the base unit code to simulate the bootloader’s responses. I can use the same program running on the PC for both base and remote updates.

Selecting the base unit’s update function simply resets the MC9S08GT16 microcontroller and starts the flash memory-based bootloader.

The remote unit update is considerably more complex. The base unit notifies each remote unit of a pending update one at a time by setting a flag in the reply packet the next time it sends one. Then the remote unit requests download packets. The base unit replies with a block of data that the remote unit writes to its download buffer. After the entire file is sent, the remote checks if it’s a valid code update. If so, it calls the bootloader to perform the update. Otherwise, it’s a sound file, which is left in the buffer for later. The base unit reads in the data file from the PC as it’s sent without buffering it locally, so it has to be transferred once for each remote unit’s update. A batch file on the PC automates this process.