Figure 26-8. Serial Programming Instruction example

Serial Programming Instruction

Load Program Memory Page (High/Low Byte)/

Write Program Memory Page/

Load EEPROM Memory Page (page access)

Write EEPROM Memory Page

Byte 1

Byte 2

 

Byte 3

 

Byte 4

Byte 1

 

Byte 2

 

Byte 3

Byte 4

 

 

 

 

Adr LSB

 

 

 

 

Adr MSB

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

d

r LS

 

 

 

 

 

 

 

 

 

 

Bit 15

B

 

 

 

 

 

 

0

Bit 15

B

 

 

 

 

0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Page Buffer

Page Offset

Page 0

Page 1

Page 2

Page Number

Page N-1

Program Memory/

EEPROM Memory

26.9SPI Serial Programming Characteristics

For characteristics of the SPI module, see “SPI Timing Characteristics” on page 298.

26.10 Programming via the JTAG Interface

Programming through the JTAG interface requires control of the four JTAG specific pins: TCK,

TMS, TDI and TDO. Control of the reset and clock pins is not required.

To be able to use the JTAG interface, the JTAGEN Fuse must be programmed. The device is default shipped with the fuse programmed. In addition, the JTD bit in MCUCSR must be cleared. Alternatively, if the JTD bit is set, the External Reset can be forced low. Then, the JTD bit will be cleared after two chip clocks, and the JTAG pins are available for programming. This provides a means of using the JTAG pins as normal port pins in running mode while still allowing In-System Programming via the JTAG interface. Note that this technique can not be used when using the JTAG pins for Boundary-scan or On-chip Debug. In these cases the JTAG pins must be dedicated for this purpose.

As a definition in this datasheet, the LSB is shifted in and out first of all Shift Registers.

26.10.1Programming Specific JTAG Instructions

The instruction register is 4-bit wide, supporting up to 16 instructions. The JTAG instructions useful for Programming are listed below.

280 ATmega16A

8154A–AVR–06/08

ATmega16A

The OPCODE for each instruction is shown behind the instruction name in hex format. The text describes which Data Register is selected as path between TDI and TDO for each instruction.

The Run-Test/Idle state of the TAP controller is used to generate internal clocks. It can also be used as an idle state between JTAG sequences. The state machine sequence for changing the instruction word is shown in Figure 26-9.

Figure 26-9. State Machine Sequence for Changing the Instruction Word

1 Test-Logic-Reset

 

0

 

0

Run-Test/Idle

1

 

 

 

1

0

1

Select-DR Scan

0

Capture-DR

0

Shift-DR 0

1

1

Exit1-DR

0

Pause-DR 0

1

Exit2-DR

1

Update-DR

1 0

1

Select-IR Scan

0

1

Capture-IR

0

Shift-IR 0

1

1

Exit1-IR

0

Pause-IR

0

 

 

 

 

1

 

 

 

 

0

Exit2-IR

1

Update-IR

1 0

281

8154A–AVR–06/08

26.10.2AVR_RESET ($C)

The AVR specific public JTAG instruction for setting the AVR device in the Reset mode or taking the device out from the Reset Mode. The TAP controller is not reset by this instruction. The one bit Reset Register is selected as Data Register. Note that the Reset will be active as long as there is a logic “one” in the Reset Chain. The output from this chain is not latched.

The active states are:

Shift-DR: The Reset Register is shifted by the TCK input.

26.10.3PROG_ENABLE ($4)

The AVR specific public JTAG instruction for enabling programming via the JTAG port. The 16bit Programming Enable Register is selected as Data Register. The active states are the following:

Shift-DR: The programming enable signature is shifted into the Data Register.

Update-DR: The programming enable signature is compared to the correct value, and Programming mode is entered if the signature is valid.

26.10.4PROG_COMMANDS ($5)

The AVR specific public JTAG instruction for entering programming commands via the JTAG port. The 15-bit Programming Command Register is selected as Data Register. The active states are the following:

Capture-DR: The result of the previous command is loaded into the Data Register.

Shift-DR: The Data Register is shifted by the TCK input, shifting out the result of the previous command and shifting in the new command.

Update-DR: The programming command is applied to the Flash inputs

Run-Test/Idle: One clock cycle is generated, executing the applied command (not always required, see Table 26-14 below).

26.10.5PROG_PAGELOAD ($6)

The AVR specific public JTAG instruction to directly load the Flash data page via the JTAG port. The 1024 bit Virtual Flash Page Load Register is selected as Data Register. This is a virtual scan chain with length equal to the number of bits in one Flash page. Internally the Shift Register is 8-bit. Unlike most JTAG instructions, the Update-DR state is not used to transfer data from the Shift Register. The data are automatically transferred to the Flash page buffer byte by byte in the Shift-DR state by an internal state machine. This is the only active state:

Shift-DR: Flash page data are shifted in from TDI by the TCK input, and automatically loaded into the Flash page one byte at a time.

Note: The JTAG instruction PROG_PAGELOAD can only be used if the AVR device is the first device in JTAG scan chain. If the AVR cannot be the first device in the scan chain, the byte-wise programming algorithm must be used.

26.10.6PROG_PAGEREAD ($7)

The AVR specific public JTAG instruction to read one full Flash data page via the JTAG port. The 1032 bit Virtual Flash Page Read Register is selected as Data Register. This is a virtual scan chain with length equal to the number of bits in one Flash page plus 8. Internally the Shift Register is 8-bit. Unlike most JTAG instructions, the Capture-DR state is not used to transfer data to the Shift Register. The data are automatically transferred from the Flash page buffer byte by byte in the Shift-DR state by an internal state machine. This is the only active state:

282 ATmega16A

8154A–AVR–06/08

ATmega16A

Shift-DR: Flash data are automatically read one byte at a time and shifted out on TDO by the TCK input. The TDI input is ignored.

Note: The JTAG instruction PROG_PAGEREAD can only be used if the AVR device is the first device in JTAG scan chain. If the AVR cannot be the first device in the scan chain, the byte-wise programming algorithm must be used.

26.10.7Data Registers

The Data Registers are selected by the JTAG Instruction Registers described in section “Programming Specific JTAG Instructions” on page 280. The Data Registers relevant for programming operations are:

Reset Register

Programming Enable Register

Programming Command Register

Virtual Flash Page Load Register

Virtual Flash Page Read Register

26.10.8Reset Register

The Reset Register is a Test Data Register used to reset the part during programming. It is required to reset the part before entering programming mode.

A high value in the Reset Register corresponds to pulling the external Reset low. The part is reset as long as there is a high value present in the Reset Register. Depending on the Fuse settings for the clock options, the part will remain reset for a Reset Time-out Period (refer to “Clock Sources” on page 25) after releasing the Reset Register. The output from this Data Register is not latched, so the reset will take place immediately, as shown in Figure 24-2 on page 234.

26.10.9Programming Enable Register

The Programming Enable Register is a 16-bit register. The contents of this register is compared to the programming enable signature, binary code 1010_0011_0111_0000. When the contents of the register is equal to the programming enable signature, programming via the JTAG port is enabled. The register is reset to 0 on Power-on Reset, and should always be reset when leaving Programming mode.

283

8154A–AVR–06/08

Соседние файлы в папке МК