A Better USI I2C Library For The MSP430


TI’s MSP430 chips are rather interesting – they’re low power, very capable, and available for under a dollar in most cases. Some of these chips, though, don’t have native SPI or I2C interfaces; instead, everything is done through a USI, or Universal Serial Interface module. [Jan] found the stock I2C USI module was a little rough around the edges, so he created his own.

[Jan] found the TI example code for using the USI as an I2C device overly complicated and something that an intern whipped up in a week and was never touched again. In response to this, he created a much, much simpler USI/I2C module that’s actually readable. It’s available over on the GitHub if you want to grab it for yourself.

Compared to the TI code, [Jan]’s library is dead simple. There are only two functions, one for initialization, and another for sending and receiving. Easy, small, and it works. Can’t do much better than that.

5 thoughts on “A Better USI I2C Library For The MSP430

  1. I’ve tried to do this, as well as use ti’s lib. The frustrating thing is that each slave device implements i2c slightly differently requiring digging through the library to add in the right options. 7 or 8 bit addressing? repeated starts? little or big endian? What if you have to use USCI1 instead of USCI0? Not to mention all he other non-standard but close i2c like protocols. After a while you just end up re-implementing. The best ways to make i2c easier are:
    1) knowing the USCI and USART modules well
    2) be good at writing state machines
    3) use your logic analyzer liberally
    I could be wrong, but I think that i2c headaches are just the price you pay for using less pins. Although it does get easier/faster after the first few times.

    1. Author here. Please note that this micro-library is strictly for USI, not USCI. I use it on the tiny MSP430G2412 chips. It does support repeated start, but not 10-bit addressing. I used it with microchip I/O expanders, Freescale MMA845x accelerometers, SFH7773 light/proximity sensors.

      In general, I agree that I2C is more complex than one might think.

      As to MSP430 and libraries, I agree with other commenters that the state of the libraries is poor. But I would not consider arduino as a “clean” ideal. It is very difficult to strike a good balance between code size, ease of use, and universal applicability. My code definitely favors small size and easy to use, but is not universal at all. TI has huge frameworks for the larger chips, those are big, difficult to use and dominate your code base, but are very flexible.

  2. I just wish someone would come up with a better all around Lib for the MSP430 and the watch. TI’s nightmare is a mess and the open source copy is as bad. Honestly Why cant the MSP430 have good CLEAN libraries like the arduino? Instead we get convoluted messes that are full of “trendyness” in programming styles that are useless to the world.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s