Fun with I2C
Work on the Open Automaton Project the last few days has focused on getting the IIC bus up and running with the VIA Nehemiah M10000 EPIA M Mini-ITX motherboard which is at the heart of my prototype droid. The I2C bus is the backbone to which many of the microcontroller-based driver and sensor boards connect. This arrangement keeps the wire runs around the robot simple (basically just power and IIC), and keeps most of the mainboard ports free for other functions.
After a few trials and tribulations, I finally got the whole thing working really well, so I thought it would be worth chronicling some of the notable things I found for the benefit of others who may also be attempting to access I2C peripherals on their PC-based robot (running GNU/Linux).
I found this web page a useful source of information. It describes how to access I2C devices using the /dev interface from the PC's standpoint. If you're using the same VIA mainboard as me, then you'll need to load the drivers i2c-viapro and i2c-dev. For example, you could add the following lines to a startup script such as /etc/rc.d/rc.local
modprobe i2c-dev modprobe i2c-viapro
To check if the devices are loaded, typing cat /proc/bus/i2c should list the I2C buses on your system. On my system, there's one entry, called i2c-0. This device is accessed from your code using the device name /dev/i2c-0, as described in the web page I linked to earlier.
I found that on Red Hat Linux 9, everything worked "out of the box". There were no patches to apply or drivers to download.
One thing worth noting about the hardware implementation of the I2C interface on the VIA motherboard, is that it uses 3.3V logic rather than the usual 5V logic. This is no big deal because all I2C signal lines are open collector anyway. It just means that any pull-up resistors you use be should tied to the 3.3V rail that's conveniently provided on the mainboard I2C connector, rather than a 5V rail. This last point may actually be moot, because based on the results of my experimentation, it appears that the host mainboard has its own on-board pull-up resistors, and the interface seemed to work perfectly well without pull-up resistors at the peripheral end.
I'm using PICmicro devices on the I2C bus, configured as slaves (obviously, the mainboard is the master), and I found a couple of very useful documents to help me with this. One is Microchip's Application Note AN734, "Using the PICmicro SSP for Slave I2C Communication", and the other is the official SMBus Specification, version 2.0. The second of these documents describes how the SMBus protocol can be implemented using I2C, allowing the higher level i2c_smbus_ functions to be used at the PC end (highly recommended). I've provided links to PDF versions of both of these documents at the bottom of the downloads page of the Open Automaton Project web site.