
7
0943E–AVR–08/08
AVR910
byte, and $01 from the low byte. The data on the MISO and MOSI lines will look like shown in
Table 7.
Writing to the Flash memory will, however, differ depending on the available programming
mode.
For devices using Byte Programming mode bytes are written with the “Write Program Flash
Memory” command. This command sends a memory address ($aa bb) to select a 16-bit word,
and selects low or high byte with the H bit (0 is low, 1 is high byte). The byte to be stored is then
sent to the target AVR microcontroller in byte 4.
For devices using Page Programming mode the Flash is programmed in two steps. First a tem-
porary Page buffer is filled using the “Load Program Memory Page” command. Each byte in this
buffer can be directly accessed. Once the entire Page buffer is filled, it can be written to the
Flash Memory using the “Write Program Memory Page” command.
In some devices, there is no method to detect when the Flash write cycle has ended. For this
reason, the programmer presented in this application note waits N ms before attempting to send
another command to the interface (the delay N will depend on target device, and can be found in
the programming section of the datasheet). For some devices it is possible to use polling. When
a byte is being programmed into the Flash or EEPROM, reading the addressed location being
programmed will give a value M (often $FF). At the time the device is ready for a new byte, the
programmed value will read correctly. This can be used to determine when the next byte can be
written. When programming the value M polling will not work, and a delay N should be used
before writing the next value. Polled mode will decrease the time required to program a device.
Table 7. Example, Reading “add r16,r17” as $0F01 From Flash Memory Location $104
Action
MOSI, Sent to
Target AVR
MISO, Returned from
Target AVR
Read $01 at address $104, low byte
$20 01 04 xx
$zz 20 01 01
Read $0F at address $104, high byte
$28 01 04 yy
$xx 28 01 0F