I2C-tiny-USB data transfer

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Posts: 6
Joined: Wed May 14, 2008 11:46 pm
Location: Christchurch, NZ

I2C-tiny-USB data transfer

Post by alanp » Mon Nov 03, 2008 9:54 pm

Hi Guys,

I'm not sure if this is the right place to ask the question but here goes.

I'm writing a python module to access the I2C bus via I2C-tiny-USB.
I'm doing this through libUSB so it can be used on Linux and Windows. I'm using the pyUSB project as a wrapper to get to libUSB.

I'm not sure whether my questions relates to USB in general or libUSB.

My question is how many bytes can I transfer at a time to the I2C bus.

I want to be able to read/write to I2C memory (24LCxx parts) which are able to do page read and write. All the examples that come with I2C-tiny-USB only do a byte or word read and write.

Can I throw, say, 32 bytes at the device or will have I to do 32 individual read/write instruction.



Rank 1
Rank 1
Posts: 27
Joined: Sat Oct 20, 2007 5:58 pm

Post by gert » Tue Nov 04, 2008 12:52 am

Hi Alan

I2C-tiny-USB uses the control endpoint to transfer data, therefore it's limited to 8 Bytes at a time.

If you plan to transfer more than 8 bytes at a time you need to implement an interrupt endpoint in your USB device. It may be a good idea to take USBasp or USBaspLoader as a starting point.

One more thing: besides the time necessary to transer 32 bytes of data plus address and command to your EEPROM using (slow) software I2C, it takes 5-15msec until a EEPROM block write is finished (see data sheet). You shouldn't forget to test if the EEPROM is "ready" before accepting new data through USB.


Posts: 16
Joined: Mon Sep 08, 2008 4:17 pm

Post by henni » Tue Nov 04, 2008 2:35 pm

gert wrote:I2C-tiny-USB uses the control endpoint to transfer data, therefore it's limited to 8 Bytes at a time.

That's wrong. All versions of AVRUSB allow up to 254 bytes control data in both directions. Newer versions allow even more bytes. IMHO Windows limit control transfers to 4KB.
However, the I2C-tiny-USB firmware may lack of more-than-8-byte support, I don't know.

I have written a more general-use USB-to-I²C interface that supports a variety of chips with following features:
* Selectable I²C address (wIndexL[7:1])
* Selectable I²C speed (wIndexL[0])
* Selectable chip-internal address (wValue[15:0]), both 1-byte and 2-byte, Little Endian and Big Endian order (wIndexH[1:0])
* Selectable size of EEPROM page (wIndexH[7:4], 0 = automatic, 1 = byte per byte etc.)
* Automatic EEPROM page write inclusive ready waiting
* Automatic address repetition (and incrementation, necessary for some non-EEPROM chips) (wIndexH[7:4] = 1)
* Full control over start conditions and stop conditions (wIndexH[3:2]), allowing split-and-concatenate transfers (very long data streams)
* All non-data (address etc.) bytes packed to SETUP data block, no data copying necessary on host side
* Upward compatible to EzMr.exe I²C interfacing (Cypress EzUSB Manager)
However, the code is for 8051 (CY7C68013A) and here: http://www.tu-chemnitz.de/~heha/bastele ... sb2lpt.zip and inside src/firmware/USB2LPT2.A51

Post Reply