Jump to content
ElectricCowboy

Question about I2C, DriverLib and MSP-EXP430F5529LP

Recommended Posts

Hello,

 

I want to connect my MSP-EXP430F5529LP ("MSP430") LaunchPad to an external device via I2C.

 

Which I2C port should I use?

 

(1) The MSP430 Quick Start Guide (slau536.pdf) includes a diagram of the BoosterPack connector showing two sets of I2C ports:

 

-set#1-

I2C - SCL - PM_UCB1SOMI - PM_UCB1SCL - P4.2

I2C - SDA - PM_UCB1SIMO - PM_UCB1SDA - P4.1

 

-set#2-

UCB0SDA - UCB0SIMO - P3.0

UCB0SCL - UCB0SOMI - P3.1

 

(2) I am using the sample project, usci_b_i2c_ex3_masterTxSingle.c.

MSP430ware->Libraries->Driver Library->MSP430F5xx_6xx->Example Projects->USCI_B_I2C->usci_b_i2c_ex3_masterTxSingle

The source file references "USCI_B0_Base" throughout (and not "USCI_B1_Base").

 

Question: Should I use SCL on P4.2 and SDA on P4.1 and change all software to "USCI_B1_Base"?

Question: Or should I use SCL on P3.1 and SDA on P3.0 and use "USCI_B0_Base"?  If I do, do I configure the pinmux?  How would I do that?

 

It seems to me that the sample project is assuming that the I2C is connected to UCB0 (and not UCB1), but the MSP430 LaunchPad, in its standard configuration, is using UCB0 for I2C.

 

I appreciate any help from the community!

 

ElectricCowboy

Share this post


Link to post
Share on other sites

If you want to use I2C then you will want to use:

-set#1-

I2C - SCL - PM_UCB1SOMI - PM_UCB1SCL - P4.2

I2C - SDA - PM_UCB1SIMO - PM_UCB1SDA - P4.1

 

or you could use P3.0 (UCB0SDA) and P3.1 (USCB0SCL). That other set is for the SPI port. 

 

Remember to install pull up resistors on the SDA and SCL lines. 

 

Assuming you are talking to a simple, straightforward I2C slave device, you will want to setup the MSP430 as the I2C Master and command the I2C slave device with its set of commands.

 

Most of the time, you will get 8 bit data back from the device. Sometimes you will get 16 or 32 bit data back from the slave. In those cases, you will have to read the device two or more times to pull all the data from, then shift and logically AND the bytes together to construct 16 or 32 bit wide samples.

 

As you have already discovered, there are many code examples from TI that demonstrate the usage of the I2C peripherals. You will have success if you mimic them. 

 

Tell us more about your external sensor IC. What is the part number?

What are your intentions? What do you want to accomplish?

 

Let's see if we can get you talking with your I2C sensor.

Share this post


Link to post
Share on other sites

The external I2C device I wish to connect is Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack at the following:

http://www.adafruit.com/product/902

 

I have attached the Holtek HT16K33 datasheet, ht16K33v110.pdf, to this forum thread.

 

My four hardware connections include:

  1. 5V to the Matrix device VCC (Operating voltage is 4.5V to 5.5V)
  2. GND to the Matrix device GND
  3. P4.1 I2C SDA to the Matrix device SDA
  4. P4.2 I2C SCL to the Matrix device SCL

No, I have not yet inserted any pull-up resistors between the MSP430 and the Matrix Device.  What resistor value should I use? I am using an experimenter board and can add resistors (if I can acquire them...)

 

The Matrix device's slave address is 0x70 and is hard-wired (confirmed).

The Matrix device's I2C clock frequency is 400kbps (confirmed).

 

Yes, I am attempting to use the MSP430 as the Master and the Matrix device as the Slave.

Therefore I am modifying a copy of the file, usci_b_i2c_ex3_masterTxSingle.c, mentioned in my thread.

 

Background:  I successfully used this Matrix device and the TI BeagleBone Black device.  Now I am attempting to use the Matrix device and the TI MSP430 LaunchPad.  It is a 8x8 LED matrix device that is capable of illuminating 3 colors.  So it is a simple display-output type of project.  The pull-up resistor comment made me think about my BeagleBone exercise.  I did not use external pull-up resistors in that project.  But you are saying that I need them for the TI MSP430 LaunchPad.  Perhaps I was using an internal pull-up resistor on the BeagleBone that is not available on the MSP430 LaunchPad.  I can't confirm; I don't know.

 

I attached my working source file, main.c.

I can step through the source file until I readh line 56 - USCI_B_I2C_masterSendSingleByte(USCI_B1_BASE,0x21);

Stepping into that function, I hang in usci_b_i2c.c when polling for the transmit interrupt flag.  I never escape.

Below is the function call and I bolded where I hang.

 

I am currently stymied!!!!

 

void USCI_B_I2C_masterSendSingleByte (uint16_t baseAddress,
    uint8_t txData
    )
{
    //Store current TXIE status
    uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE;

    //Disable transmit interrupt enable
    HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);

    //Send start condition.
    HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT;

    //Poll for transmit interrupt flag.
    while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;

    //Send single byte data.
    HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;

    //Poll for transmit interrupt flag.
    while (!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG)) ;


    //Send stop condition.
    HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;

    //Clear transmit interrupt flag before enabling interrupt again
    HWREG8(baseAddress + OFS_UCBxIFG) &= ~(UCTXIFG);

    //Reinstate transmit interrupt enable
    HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus;
}

 

main.c

ht16K33v110.pdf

8x8 Bi-Color LED Matrix BL-M12A883xx.pdf

 

Share this post


Link to post
Share on other sites

The first thing that I can see is the ht16k33 controller is a 5 volt part. This is a problem because the msp430 is a 3 volt part.

 

You will have to use a bidirectional level shifter on the SDA and SCL lines to keep the msp430 from having a fit.

 

Adafruit has 3 to 5 volt level shifter ie: http://www.adafruit.com/products/757

 

Without the level shifter, your code will think the i2c bus is locked up.

Share this post


Link to post
Share on other sites

Many thanks Zeke!

 

I now see in the ht16k33 datasheet, page 6, that the input voltage for the SDL and SDA is typically VDD, which is 5V in my case.

Indeed, I need pull up resistor or the Logic Level Converter that you mentioned (Adafruit product 757).

Ok, so I will order the Logic Level Converter and suspend my project until I can get it on my experimental board.

 

But I'll sure to post my progress moving forward.  I can't be the only person interested in this area.

 

With kind regards,

Electric Cowboy!

Share this post


Link to post
Share on other sites

@ElectricCowboy: You are very welcome! Just tap on the thanks button and let us know how things work out for you. We are definitely interested in what you are doing. You may even need to make us a video of your circuit in action so we can check it out with you!

Share this post


Link to post
Share on other sites

Hello,

 

I purchased a 4x bi-directional level-shifter from Adafruit (http://www.adafruit.com/products/757).

I soldered the header and mounted it and the 8x8 LED Matrix to an experimenter board.

I created the attached schematic diagram, 20141210 - TI MSP430 I2C Diagram 8x8 BiColor LED Matrix.pdf, to this thread.

I believe the electrical connections are correct.

I added blue wires (really, they are blue!).

I attempted to enable I2C communications in mid-November. 

Although my software was not correct, I did see that the 8x8 LED Matrix was "alive", because some of the LEDs in the Matrix illuminated; this is certainly a good sign.

I will continue to try changes to my software and will update the thread soon.  (Full-time job takes precendence over hobbies...)

 

Is anyone in the community willing to eye-ball and check my attached schematic diagram? Thanks in advance.

 

Electric Cowboy

Share this post


Link to post
Share on other sites

Schematic Issues:

1)  No pull-up resistors.  Start by adding 10k pull-ups to both lines.  (Shouldn't matter which side of the level shifter you add them, but I'd try the 5v side first.)

2)  No decoupling capacitors.  Add in caps between the 3v & 5v lines and GND.  Otherwise a spike/lull cuased by your LED matrix can cause all sorts of wierd issues.  Better safe than sorry.

3)  You have no way to reset your slave device.  I'd recommend you use a GPIO with a transistor (high side switch) to allow your program to power-cycle the LED driver.  I haven't used that specific device, but I've seen other I2C devices get stuck holding down the SCL, and if you can't  power cycle it, it will block all I2C communications.  Remember that your slave doesn't reboot each time you restart your program.  Ideally, put the pull-up resisters after the switch, because some devices can function with the juice from the data lines long enough to not reset when you cut their Vcc line.

4)  Consider adding points on your line to put an I2C sniffer.  (Hopefully, you have access to a logic analyser)  What you don't want is to have your lines getting wiggled every time you hook-up/remove testing tools.  

 

Suggestions:***

1)  Make sure everything is held securely while you get it working.  I use a chunk of cardboard and hot glue everything down to it.  You want to make sure nothing unexpected gets pulled out when things get bumped and cords get swapped.

2)  Don't assume ANYTHING is working like you think it is.  Test your wiring connections for continuity.  Test all four lines with a VMM.  Test any pins/sockets/headers to make sure every pin has good contact. Huge amount of "problems" with I2C are just basic wiring problems.  

3)  If you are starting from scratch, I'd recommend using the Energia code base and it's port of wire.h for I2C.  The TI I2C libraries are quite buggy (There are function in the driver library that simply don't work on an MSP430F5529 and will hang your program) and have an over-complicated programming model.  I'm currently trying to get wire.h to compile with the TI compiler, because I have some code that uses it 

4)  Unit test every I2C call you expect to make.  Make a project that atomically does each function so you can prove the basics work before you integrate them into your code.  It is a bit of work, but much less work than trying to debug a program when you don't know which of the components are actually doing what you think they are.

5)  Document every time things work correctly, preferably with source control.  If/when you break something as you add to the code, you want a clear place to return to if you don't like how your change turned out.

6)  If you find a loose connector, etc.  Toss it out and use a better one.  Just because you can wiggle it and get it to work again for the moment, doesn't mean you won't spend more time & effort testing and wiggling it than it is worth.  (This advice might be more for me than you.  Can't tell you how many times I've been dumb enough to throw a bad connecter back into my parts bin so that I get to have the same problems again the next time I pull it out.)

 

***These suggestions mostly come from experiencing the pain of not using them.  Hope they help.  Troubleshooting I2C can be maddeningly complex if you don't work hard to ensure that your building blocks are solid.

 

Share this post


Link to post
Share on other sites

@ElectricCowboy: Your schematic looks good to me. 

 

I agree with @@SvdSinner that you need to put pullup resistors on the SDA and SCL lines.  But here's the catch, you have to put pullup resistors on both sides of the level translator to make it work.

 

I agree that 10K pullups will do the job well.

 

Do you have a logic analyzer? I use a Saleae Logic. It's the cat's meow.

 

My experience with TI's sample I2C is also negative so I wrote my own Bit Bang I2C Master routines. It ended up looking a lot like the Energia routines but more raw and not at all C++ like.

 

Don't worry about being perfect. Just enjoy the process of exploration. Ask us lots of questions. We're here to share the adventure.

Share this post


Link to post
Share on other sites

SUCCESS!

I added 10k-ohm pull-up resistors to the SCL and SDA lines on both sides of the level shifter.

I updated this thread with code, an updated schematic and a snapshot of my dev board including one test pattern showing Green, Red and Yellow pixels.

Many thanks to zeke and SvdSinner for their help and replies to this thread.

For me, this is a nice little accomplishment for a variety of reasons: TI Code Composer Studio, TI MSP430 LaunchPad, reuse of an 8x8 Bi-Color Matrix device, and using I2C (albeit via library APIs).

 

Onwards! 

 

I plan to expand this DIY project by adding timers for LED animation, adding additional LED matrices, and possibly employing the LaunchPads other I2C interface.  I would also like to explore the TI RTOS at a later time in 2015.  I would also like to employ switch debouncing and implement different animation modes, and harden the hardware design as suggested.  Perhaps I'll update my progress as progress is made...

 

Electric Cowboy

20141212 - TI MSP430 I2C Diagram 8x8 BiColor LED Matrix.pdf

post-38207-0-71921300-1419357346_thumb.jpg

main.c

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×