An Open Source USB to I2C interface

A simple, yet robust USB to I2C/SPI/Serial/GPIO interface, written in software using usbtiny.
This interface was originally developed for the OpenServo project, but serves as a generic USB to I2C, serial and SPI adapter.
Example code is provided for integration with other I2C devices.

Downloads
-- Download Latest Firmware
-- Download Older Firmware
Installation
-- Windows XP
-- Windows Vista
-- Linux
System Overview
-- GPIO Access
-- Serial usage
Firmware Update
API guide
IO pinouts
PCB and schematics


Downloads

Latest firmware

Firmware version 1.06 03/03/2008

Changelog:- Added dual mode serial support. Allows USB to serial (not using virtual com) and serial to I2C modes. Upgraded usbtiny to 1.4


Older Firmware


Firmware version 1.06 01/02/2008

Changelog:- Fixed error with error callbacks that cause lockup of OSIF on bad device comms.

Source code and schematics are available, and can be downloaded from OpenServo CVS (BE SURE TO USE THE VERSION2 DIRECTORY!) Also available is a windows dll file that can be used to communicate with the OSIF and reflash an OpenServo.


Installation


Microsoft Windows XP

Download the Windows XP executable file and dll + USB drivers.

Version 2.1 Improved speed considerably. Added software support for SPI
Older releases
Version 2.0

1) Plug the OSIF into your USB port. When prompted for a driver, navigate to the folder in the package above, \drivers\ and follow the on screen instructions.

2) Run the applications from the directory in step 1.

3) Enjoy!

The control application and the underlying library are designed to run on multiple platforms. The main application uses QT for its widget library, and is statically compiled into the win32 release.


System Overview


The design uses an Atmega 8 and also provide 3 GPIO lines to allow serial communication.

The firmware is capable of SPI mode as well as hardware based 400khz I2C communication. Provided is a connector that allows for flashing of the OSIF, flashing any AVR based SPI device, such as an atmega8 or atmega168, for example the OpenServo board.

There are two jumper pins on the OSIF.
JP1 allows you to use an external power supply to power your target application when disconnected. When it is connected it uses the USB +5V signal to power the application. While the USB power may be able to control some devices, it is recommended that you use an external PSU. Do not connect and external supply and this jumper. Although there is a diode to protect from this, serious damage to USB ports may occur if used incorrectly.

JP2 is normally disconnected unless you are SPI flashing the OSIF board with new firmware or wish to provide an extra 5v USB voltage to an external device. Using the connector in this was is not recommended.

R4 and R5 are the I2C pullup lines, and suitable resistors should be selected for your bus. The supplied 4.7K resistor pair is the recommended for low device count.


GPIO Access


GPIO access is controlled through the provided dll/shared library API
See here: OSIF GPIO guide


Serial usage


The OSIF allows two serial modes of operation.
1) USB to serial using the serial API
This allows you to control a basic TTL level serial device over the USB bus. This method of communication does not allow for a virtual com port.
2) Serial to I2C access.
This is the default mode of the OSIF. When you send a data packet over the serial port on the OSIF, it is sent to the I2C port. A serial packet is constructed in a simple manner.

A transaction is defined as a direction + address + length then a space followed by the data. A full transaction finishes with a stop condition.

Each transaction happens until the data is received or a timeout occurred. Each packet is acknowledged with an OK, OK SCAN and OK STOP

W=write R=read S=stop F=scan
A header of a packet looks like this:
W[address][length][space]
A whole packet ...
R/W[address][length][space][data][data][...]

> indicates send to OSIF < out of OSIF
Example write:
> Wa4 1234 // Write the data
< OK
> S // Send stop
< OK STOP

Example read:
> Wa1 [register]
< OK
> Ra4 // Read the data. Note there is a space after.
< OK
> S // Send stop
< OK STOP

Example Scan:
> F // Scan the bus
< OK SCAN
< 0x10 | 0x0b ... // Returns a | separated list.

Firmware Update


You can update the firmware to the latest version in more than one way...

Use Method one if you want to completely upgrade all bootloader and firmware on the OSIF.

use Method two if you want to update the OSIF from the build in bootloader over USB. (devices after 01/02/08 only)

Method 1:- Build you own flash cable, or use an AVR programmer

Build a cable and flash:-

  1. Build an Avrdude compatible flash cable such as the STK 200 http://openservo.com/moin.cgi/STK200
  2. Install AVRdude from the above link.
  3. Grab the CVS/hex files of the firmware from the OpenServo CVS repository
  4. Optionally build the firmware
  5. Flash the device from the command line:-
    You have two choices at this point, you can apply the bootloader (preferred but longer) or you can flash the main firmware.
    Apply the bootloader code:
    sudo ./avrdude -c stk200 -p atmega8 -v -U lfuse:w:0x9f:m -U hfuse:w:0xc8:m -U flash:w:/path/to/openservocvs/bootloader/main.hex -e

    If you want to apply the main firmware instead of the bootloader, use /openservocvs/firmware/main.hex

Method 2:- Use the built in bootloader

The OSIF comes shipped with a built in bootloader (devices after 01/02/08 only) which can be used to update the firmware of the OSIF over USB.

  1. Disconnect the OSIF from the USB. Put a jumper PIN on the pins marked MOSI (pin 7) and MISO (pin 8). Now reconnect the OSIF to the USB
  2. Windows: Download the OSIF Flash updater for Windows.
  3. Linux: Download the CVS repository for the bootloader flash update program from the OpenServo CVS
    • Build the software for updating the OSIF. There is a Makefile included, so it is fairly simple:

      make

  4. Windows: Run the osifupdate tool like so:
    Start->Run
    Type "cmd" (no quotes) and press OK
    cd to the directory where you unzipped the files
    e.g cd c:\osifupdate
    type "update.bat" (no quotes)
    The shipped firmware hex file may be out of date, and it is recommended you download the latest main.hex as detailed above, replacing the distributed firmware.
  5. Linux: Run the osifupdate tool with the following parameters:-

    sudo ./osifupdate w /path/to/openservocvs/firmware/main.hex

    If the update fails for any reason, reconnect the OSIF and try again.

API Guide


Provided is an API specification to allow you to develop applications to communicate with the OSIF.

Please read the OSIF API page for more information and code snippets


IO Pinouts



PCB's


OpenSource Interface Both Layers

OpenSource Interface Top

OpenSource Interface Bottom

OpenSource Interface Top parts placement

OpenSource Interface Bottom parts placement

Schematic (click for bigger)

Finished product