Auto-Baud
In mode 2, the first thing you do is teach the bootloader what baud rate to use, since the bootloader
doesn't know how fast the chip's clock is. Wait 3mS or so for the chip to come out of reset, then send
16 NUL bytes spaced 20 mS or more (I use 40 mS) apart. These bytes should be sent at 9600 baud, 8
bits, no parity, one stop bit. Different chips require different delays between bytes, but this should be
long enough to work with them all. In this diagram we show the sequence - set MODE, reset, start
sending NUL bytes. Note that all values shown for the Tx and Rx lines are in hex, so {65} is 0x65
(decimal 101), not decimal 65.
nRESET
====\/== · · ·
MODE/CNVss
??\----- · · ·
Tx
_______{00}___________________{00}___ · · ·
<_____ >20 mS ____>
After sending the last byte, wait 2mS and then read any data that might have been sent back to the host.
Sometimes there's a glitch at reset that looks like a byte, and some chips transmit a byte at the end of
synchronization. By reading these optional bytes and clearing your receive buffer, you ensure you're in
sync with the bootloader.
Baud Rate
The next step is to verify the autobaud rate, and set the desired baud rate. The initial synchronization is
done at 9600 baud, but you can ask the chip to use a faster baud rate if your hardware (host and chip)
support it. Baud changes are done with single byte commands, and the chip responds by sending you
the same byte back:
9600
_{B0}_
19200
_{B1}_
38400
_{B2}_
57600
_{B3}_
115200
_{B4}_
The request is sent out with the old baud rate, and the chip responds with the old baud rate before
changing it. Send the baud rate command, check the response, and if it's correct then change the baud
rate at your end. So, after the last NUL byte is sent, read any pending bytes and send a request for
9600 baud to verify communications, then request your new baud rate and verify it:
Tx
__{00}________{B0}___________{B4}_______ change speed
Rx
______{??}________{B0}___________{B4}___ change speed
Note that not all baud rates will work; which ones work depend on what speeds your chips are running
at. For some speeds, the chip might not be able to generate a baud clock accurately enough. Try them
all until you find one that works reliably.
Bootloader Version
The next thing to do is ask the bootloader for its version number. It's not that useful from a program's
point of view, but you can use it to make sure the baud rate is reliable. The request is a single byte
Kommentare zu diesen Handbüchern