Communication protocol

Warning: Undefined variable $optionString in /customers/8/4/7/usbpicprog.org/httpd.www/wp-content/plugins/wpmu-syntax-highlighter.php on line 52

Writing or reading data to / from usbpicprog occurs in a binary form. Commands which require no additional data are just single byte instructions (erase, read_id and get_firmware version). All other commands start with a 6-byte header see the table below.

The communication occurs through an usb_interrupt_write (libusb). The device ID of usbpicprog is:

04D8:000E

#define CMD_ERASE 0x10
#define CMD_READ_ID 0x20
#define CMD_WRITE_CODE 0x30
#define CMD_READ_CODE 0x40
#define CMD_WRITE_DATA 0x50
#define CMD_READ_DATA 0x60
#define CMD_WRITE_CONFIG 0x70
#define CMD_SET_PICTYPE 0x80
#define CMD_FIRMWARE_VERSION 0x90
#define CMD_DEBUG 0xA0

typedef union _UppPackage
{
struct _fields
{
unsigned cmd:8;
unsigned size:8;
unsigned addrU:8;
unsigned addrH:8;
unsigned addrL:8;
unsigned blocktype:8;
unsigned char dataField[32];
}fields;
char data[38];
}UppPackage;
Command Command Code Data (PC to Usbpicprog) Data (Usbpicprog to PC)
Bulk erase 0x10
  • 0x01 to tell ok
  • 0x03 unsupported
Read DEVID 0x20
  • 2 bytes containing the DEVID of the current device
Write CODE memory 0x30
  • 1 byte: block size
  • 3 bytes: block start address
  • 1 byte: block type (0: middle block, 1: first block, 2: last block, 3: only block)
  • n bytes: data block
  • 0x01 to tell ok
  • 0x02 ask for next block
  • 0x03 unsupported
  • 0x04 verify error
Read CODE memory 0x40
  • 1 byte: block size
  • 3 bytes: block start address
  • 1 byte: block type (0: middle block, 1: first block, 2: last block, 3: only block)
  • n bytes: data block
Write DATA memory 0x50
  • 1 byte: block size
  • 3 bytes: block start address
  • 1 byte: block type (0: middle block, 1: first block, 2: last block, 3: only block)
  • n bytes: data block
  • 0x01 to tell ok
  • 0x02 ask for next block
  • 0x03 unsupported
  • 0x04 verify error
Read DATA memory 0x60
  • 1 byte: block size
  • 3 bytes: block start address
  • 1 byte: block type (0: middle block, 1: first block, 2: last block, 3: only block)
  • n bytes: data block
Write Config words 0x70
  • 1 byte: block size
  • 3 bytes: block start address
  • 1 byte: block type (0: middle block, 1: first block, 2: last block, 3: only block)
  • n bytes: data block
  • 0x01 to tell ok
  • 0x02 ask for next block
  • 0x03 unsupported
  • 0x04 verify error
Set pic type 0x80
  • 1 byte: picfamily
  • 0x01 to tell ok
  • 0x03 unsupported
Read usbpicprog firmware version 0x90 “Usbpicprog 0.3.0”
Debug the programmer

(for development purposes only)

0xA0
  • 1 byte: debug command (0: VPP high, 1: VPP low, 2: write 24 bit to dsPIC, 3: read 16 bit from dsPIC
  • 3 bytes containing the data for the command
  • 0x01 to tell ok
  • or the 2 bytes of data to read

Leave a Reply