AVR061: STK500 Communication Protocol Introduction This document describes the protocol for the STK500 starterkit. This protocol is based on earlier protocols made for other AVR tools and is fully compatible with them in that there should not be any overlapping or redefined commands. The following sections describes each part of the protocol in detail. All commands (both commands and responses) are standard ASCII characters between 0x00 - 0x7F. Data can be any character with value between 0x00 - 0xFF.
Response Definitions This section describes the meaning of the valid responses from the STK500 starterkit. Some of the responses will be part of more complex responses also containing data, depending on the command. OK Response Resp_STK_OK is sent after a valid command has been executed. Failed Response Resp_STK_FAILED is sent if a command execution fails. Insync Response Resp_STK_INSYNC is sent after Sync_CRC_EOP has been received.
AVR061 Command Definitions This section defines the commands that are understood by the STK500 starterkit. Check if Starterkit Present The PC sends this command to check if the starterkit is present on the communication channel. Command Cmnd_STK_GET_SIGN_ON, Sync_CRC_EOP Command Value 0x31 Response Resp_STK_INSYNC, sign_on_message, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 1. Parameters Parameter Name Field Usage Field Format sign_on_message Text string.
Get Parameter Value Get the value of a valid parameter from the STK500 starterkit. If the parameter is not used, the same parameter will be returned together with a Resp_STK_FAILED response to indicate the error. See the parameters section for valid parameters and their meaning. Command Cmnd_STK_GET_PARAMETER, parameter, Sync_CRC_EOP Command Value 0x41 Response Resp_STK_INSYNC, value, Resp_STK_OK or Resp_STK_INSYNC, parameter, Resp_STK_FAILED or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 3.
AVR061 Set Device Programming Parameters Set the device Programming parameters for the current device. These parameters must be set before the starterkit can enter Programming mode.
Table 5. Parameters (Continued) Parameter Name Field Usage Field Format flashsize4 FLASH size in bytes, byte 4 (High Byte) of 32-bit value. 1 byte flashsize3 FLASH size in bytes, byte 3 of 32-bit value. 1 byte flashsize2 FLASH size in bytes, byte 2 of 32-bit value. 1 byte flashsize1 FLASH size in bytes, byte 1 (Low Byte) of 32-bit value. 1 byte Set Extended Device Programming Parameters Set extended programming parameters for the current device.
AVR061 Enter Program Mode Enter Programming mode for the selected device. The Programming mode and device programming parameters must have been set by Cmnd_STK_SET_DEVICE prior to calling this command, or the command will fail with a Resp_STK_NODEVICE response. Command Cmnd_STK_ENTER_PROGMODE, Sync_CRC_EOP Command Value 0x50 Response Resp_STK_INSYNC, Resp_STK_OK or Resp_STK_INSYNC, Resp_STK_NODEVICE or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 7.
Check for Address Autoincrement Check if the write/read address is automatically incremented while using the Cmnd_STK_PROG/READ_FLASH/EEPROM commands. Since STK500 always autoincrements the address, this command will always be successful. Command Cmnd_STK_CHECK_AUTOINC, Sync_CRC_EOP Command Value 0x53 Response Resp_STK_INSYNC, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 10.
AVR061 Program Data Memory Program one byte in EEPROM memory. Command Cmnd_STK_PROG_DATA, data, Sync_CRC_EOP Command Value 0x61 Response Resp_STK_INSYNC, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 13. Parameters Program Fuse Bits Parameter Name Field Usage Field Format data Byte to program 1 byte Program Fuse bits. The Fuse bit mapping for the currently supported devices is described in the appendix.
Program Fuse Bits Extended Program Extended Fuse bits. The Fuse bit mapping for the currently supported devices is described in the appendix. Note: For ISP Programming, use the Cmnd_STK_UNIVERSAL command with the appropriate ISP command bytes (found in the device data sheet). Command Cmnd_STK_PROG_FUSE_EXT, fuse_low, fuse_high, fuse_ext, Sync_CRC_EOP Command Value 0x65 Response Resp_STK_INSYNC, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 15.
AVR061 Program Page Download a block of data to the starterkit and program it in FLASH or EEPROM of the current device. The data block size should not be larger than 256 bytes. Command Cmnd_STK_PROG_PAGE, bytes_high, bytes_low, memtype, data, Sync_CRC_EOP Command Value 0x64 Response Resp_STK_INSYNC, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 17.
Read Data Memory Read one byte from EEPROM memory. Command Cmnd_STK_READ_DATA, Sync_CRC_EOP Command Value 0x71 Response Resp_STK_INSYNC, data, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 19. Parameters Read Fuse Bits Parameter Name Field Usage Field Format data Data byte 1 byte Read Fuse bits. The Fuse bit mapping for the currently supported devices is described in the appendix.
AVR061 Read Fuse Bits Extended Read Extended Fuse bits. The Fuse bit mapping for the currently supported devices is described in the appendix. Note: For ISP Programming, use the Cmnd_STK_UNIVERSAL command with the appropriate ISP command bytes (found in the device data sheet). Note that some devices combine Lock bits and Fuse bits in way that actually requires using the Cmnd_STK_READ_LOCK to retrieve the Fuse byte(s). This is described closer in the appendix.
Read Page Read a block of data from FLASH or EEPROM of the current device. The data block size should not be larger than 256 bytes. Command Cmnd_STK_READ_PAGE, bytes_high, bytes_low, memtype, Sync_CRC_EOP Command Value 0x74 Response Resp_STK_INSYNC, data, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 23.
AVR061 Read Oscillator Calibration Byte Read Oscillator calibration byte. Command Cmnd_STK_READ_OSCCAL, Sync_CRC_EOP Command Value 0x76 Response Resp_STK_INSYNC, osc_cal_byte, Resp_STK_OK or Resp_STK_NOSYNC (If no Sync_CRC_EOP received) Table 25. Parameters Parameter Name Field Usage Field Format osc_cal_byte Oscillator callibration byte 1 byte Read Oscillator Calibration Byte Extended Read Oscillator calibration byte.
Universal Command Universal command is used to send a generic 32-bit data/command stream directly to the SPI interface of the current device. Shifting data into the SPI interface at the same time shifts data out of the SPI interface. The response of the last eight bits that are shifted out are returned. Currently this command is used to read and write Fuse and Lock bits in Serial/High-voltage mode. For more information, see the appendix.
AVR061 Parameter Definitions Hardware Version This parameter defines the version of the starterkit hardware. Parameter Parm_STK_HW_VER Access: Read only Table 29. Value Description – – Parameter Value 0x80 Software Version Major The major version of the starterkit MCU software. Parameter Parm_STK_SW_MAJOR Access: Read Only Table 30. Value Description – – Parameter Value 0x81 Software Version Minor The minor version of the starterkit MCU software.
Status LED Sets or retrieves the current setting of the status LED on the starterkit. The status LED on the starterkit is a dual LED which can emit red light, green light or both (yellow). Parameter Parm_STK_LEDS Access: Read/Write Table 32. Value Description 0 Status LED off 1 Green on 2 Red on 3 Green and red both on Parameter Value 0x83 Target Voltage (VTARGET) Sets or retrieves the current target voltage (VTARGET).
AVR061 Oscillator Timer Prescaler Value Sets or retrieves the current prescaler value for the timer in the mcu that is used to generate the adjustable Oscillator. The actual Oscillator frequency is a function of the Parm_STK_OSC_PSCALE and the Parm_STK_OSC_CMATCH parameters. See the Table 35 below. Parameter Parm_STK_OSC_PSCALE Access: Read/Write Table 35.
Buffer Size These parameters retrieve the size of the communication buffer in the starterkit MCU. The parameters form a 16-bit value, where Parm_STK_BUFSIZEH is the high byte and Parm_STK_BUFSIZEL is the Low byte. Parameter Parm_STK_BUFSIZEH:Parm_STK_BUFSIZEL Access: Read only Table 38. Value Description – – Parameter Value 0x91:0x90 Topcard Detect Retrieves information about whether there is a top-card mounted on the STK500 or not.
AVR061 Appendix Reserved Commands There are several commands (or command characters) that are reserved and should not be used for this product. They are either used for other AVR products or are reserved for future use. All reserved commands will return a NACK response (character “?”) to indicate that they are not used.
Device Codes 22 Table 40.
AVR061 Signature Bytes Table 41.
Lock Bits For explanation of the Lock bits, read the data sheet for the particular device. Unprogrammed bits should be set to “1”. Table 42.
AVR061 Fuse Bits, Low Byte For explanation of the Fuse bits, read the data sheet for the particular device. Unprogrammed bits should be set to “1”. Table 43.
Fuse Bits, High Byte For explanation of the Fuse bits, read the data sheet for the particular device. Unprogrammed bits should be set to “1”. Table 44.
AVR061 Fuse Bits, Extended Byte For explanation of the Fuse bits, read the data sheet for the particular device. Unprogrammed bits should be set to “1”. Table 45.
Devices Combining the Fuse and Lock Bits on Readback Some devices combine readback of the the Fuse and Lock bits in the same command and response. The proper command to use is the Cmnd_STK_READ_LOCK command.
AVR061 Writing the Lock Bits if (number of lock bytes >= 1) { // Devices with selftimed SPI has another programming // format for low lock bits than those without, apart from for ATtiny12 & ATtiny15 if ((device supports self-timing programming) && (device is not Attiny12 or Attiny15)) UniversalCommand(0xAC, 0xE0, 0, &lock_byte)) else UniversalCommand(0xAC, lock_byte | 0xF9, 0, &dummy_var)) Sleep(50); // Wait for lock bit write operation in device to complete } Reading the Fuse Bits // As mentioned, some
Writing the Fuse Bits if (number of fuse bytes >= 1) { // Devices with selftimed SPI have another Programming // format for low fuses than those without if (device supports self-timing programming) UniversalCommand(0xAC, 0xA0, 0, &low_fuse_byte); else UniversalCommand(0xAC, (low_fuse_byte & 0x1F) | 0xA0, 0, &low_fuse_byte); Sleep(50); // Wait for fuse write operation in device to complete } if (number of fuse bytes >= 2) { UniversalCommandNew(0xAC, 0xA8, 0, &high_fuse_byte); Sleep(50); // Wait for fuse w
Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg.