Electrical – I2C Code Composer Studio example for MSP430G2553

i2clibrarymsp430ti-ccstudio

I've been scouring the forums for a complete I2C implementation for MSP430G2553 using Code Composer Studio. All I can find are code snippets out of context or single byte examples.

I need to figure out how to do the following using Code Composer Studio 7x On an MSP430G2553 with I2C:

  1. Write a byte of data to a specific register.
  2. I need to do the above on 2 different I2C slaves.
  3. I need to read MULTIPLE bytes from a single I2C slave.

I am new to controller programming. I have been programming in Windows for 20 years, but the low level controller programming is just one huge paradigm shift for me. If somebody could point me to a good example of the above 3 operations that will work in Code Composer Studio 7.x, I'd be very grateful.

I'm not asking somebody to write my code. I'm just having trouble with the basic concepts of how things work when programming controllers in CCS. I'm used to calling a function like:

SetPinMode(14,OUTPUT);

The above, when called would set pin 14 as an output pin.

However, when I see something in a TI example like:

UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;   // I2C Master, synchronous mode

I can't make any sense of it. It's all abbreviated. Setting values is acting like calling a function. It's nice and compact, but for a guy used to calling a function with a meaningful name, it's incomprehensible… Looks like jibberish. I cannot read that code and make out what parts of it are doing what.. I'm thinking I might just need some 'Intro to Controller Programming' class to put me in the mode to decipher the above code.

It appears to me that the world of controller programming uses 'short-hand' instead of calling functions. I'm sure there's good reasons for this, but it's really hard to follow when first starting out. Any useful help with some explanations that would be useful to somebody like me who doesn't already know the answer would be greatly appreciated.

Anybody can say that they know how to do something. A truly gifted person can actually teach it to somebody that doesn't already know. That's what I'm asking for here. Or at least guide me to some source where the examples ARE spoon fed to start with. I just don't get the whole paradigm at this point, so it's hard for me to decipher…

Best Answer

SetPinMode(14, OUTPUT) likely as well only sets a value in the register that controls the pin (in pseudocode: pin[14].output=true) . In C that's often done with binary arithmetic (bit manipulation). The registers in the MSP are memory mapped, so writing to these predefined memory regions is writing directly to the machine registers, to which the machine reacts accordingly, as explained in the set of reference manuals (search by chip family and part number). To get an intro on the hardware, any book on MSP or 8-bit microcontrolers in general should be enough.

I'm sure open source implementations for I2C exist, already, e.g. in msp430ware from TI, or other open source libraries, so you wouldn't have to roll your own. If you do try to, though, experimenting is expected, as the official documentation only goes so far.