I've released a tiny library that implements I2C master functionality for MSP430 chips that have the USI module (MSP430G2412 or MSP430G2452 are ones that I use often).
The code is on GitHub, it is MIT-licensed, so you can do whatever you want with it.
From the README:
- Reads and writes.
- Implements repeated start.
- Uses the Bus Pirate convention.
I wrote this out of frustration. There is lots of code floating around, most of which I didn't like. TI supplies examples which seem to have been written by an intern and never looked at again. The examples are overly complex, unusable in practical applications, ugly and badly formatted, and sometimes even incorrect.
The MSP430G2xx2 devices are tiny and inexpensive and could be used in many application requiring I2C, but many people avoid them because it is so annoyingly difficult to use I2C with the USI module.
This code is very, very loosely based on the msp430g2xx2usi16.c example from TI, but if you compare you will notice that:
- the state machine is different (simpler): see doc/usi-i2c-state-diagram.pdf for details,
- it actually has a useful interface,
- it is smaller.
This is a simple I2C master that needs to fit on devices that have 128 bytes of RAM, so scale your expectations accordingly. There is no error detection, no arbitration loss detection, only master mode is implemented. Addressing is fully manual: it is your responsibility to shift the 7-bit I2C address to the left and add the R/W bit.