skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: Teensy Reference HalfKay Protocol

PJRC Store
Teensy 4.1, $31.50
Teensy 4.0, $23.80
Teensy
Main Page
Hardware
Getting Started
Tutorial
How-To Tips
Code Library
Projects
Teensyduino
Reference

HalfKay Communication Protocol

Tthis section, together with the command line source code, serves to document the communication protocol used by HalfKay.

HalfKay uses only 2 very simple commands. Both are USB control transfers which also correspond to a HID output report.

Write Block Command

To write a 128 byte block, simply send this 130 byte control transfer. The first 2 bytes are the address, which should be aligned to a 128 byte block boundry.

buf[0] = addr & 255;
buf[1] = (addr >> 8) & 255;
ihex_get_data(addr, 128, buf + 2);
usb_control_msg(handle, 0x21, 9, 0x0200, 0, (char *)buf, 130, first_block ? 3000 : 200);

HalfKay always preforms a complete erase of all blocks when it receives the first write command. A timeout of 3 seconds should be allowed during the first write, through the erase operation typically takes less than 1 second. All other writes can use a timeout of 0.2 seconds.

Reboot Command

To reboot the AVR processor, simply send HalfKay a write command to address 0xFFFF. The 128 data bytes are ignored.

buf[0] = 0xFF;
buf[1] = 0xFF;
memset(buf + 2, 0, sizeof(buf) - 2);
usb_control_msg(handle, 0x21, 9, 0x0200, 0, (char *)buf, 130, 200);

On Linux and Macintosh, this command will typically return a failure result, because the AVR processor executes the command very rapidly and the operating system quickly detects the device is no longer attached. On Windows, the return result is less consistent.