1
\$\begingroup\$

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...

\$\endgroup\$
  • 2
    \$\begingroup\$ This is not a code writing service. Read chapter 17 of the User's Guide and TI's I²C examples. If you do not understand some particular piece of code, ask a specific question about that. \$\endgroup\$ – CL. Feb 28 '17 at 8:51
  • 1
    \$\begingroup\$ You will find that all of those 'short hand' constants/macros/register names (usually) match the bit field names or registers listed in the User Guide (UG) and Datasheet (DS) for each uC. I learned quickly that whenever programming for a TI uC, one must have constant access to both the UG and DS. You must be familiar with the relevant sections of these docs before even starting to program. \$\endgroup\$ – Chris Knudsen Apr 3 '17 at 19:02
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

TI's code examples are all you need. slac485h (zip file download) has multiple i2c examples for both slave and master, single and multiple reads, writes, etc.

I2C in general is pretty simple, and repetitive. Write the device address, then the page address, then the value. Repeat writing values until you send a stop. For read, its the same thing. Keep reading by sending an ack until you are done so you send a nack. That's it.

\$\endgroup\$
  • \$\begingroup\$ None of TI's examples show a repeated start condition. \$\endgroup\$ – CL. Feb 28 '17 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.