Jump to content
Sign in to follow this  
joeyeisinger

Inconsistent behavior

Recommended Posts

Hello,

I am having some trouble with using my msp430g2231 on a breadboard. I am trying to get some I2C code running, and have found that when the chip is plugged into the launchpad, the code runs as expected. When I plug into a breadboard and hook up Vcc, GND, and RST, the code does not run properly. It seems to get stuck in an ISR. However, if I run a wire from P1.6 (clock signal) on the chip to the corresponding spot on the launchpad, the code runs correctly. Does anyone know what is behind this? Does the emulator on the launchpad do something with the clock signal? Any ideas to get the thing to run correctly without hooking a wire into the launchpad?

Thanks,

Joey

Share this post


Link to post
Share on other sites
when the chip is plugged into the launchpad, the code runs as expected. When I plug into a breadboard and hook up Vcc, GND, and RST, the code does not run properly.

 

the difference for P1.6 between launchpad and breadboarded is that on the launchpad it is connected to a LED (unless u removed the jumper).

 

may be to need to setup your pull-up / pull-down for P1.6 and P1.7 (if these are your SDA/SCLs) if u haven't done so

 

typical i2c requires the bus master to have pull-ups, if u don't breadboard them physically, u should use internal pull-ups

 

P1OUT |= 0xc0; // p1.6, p1.7 as pull-up high

P1REN |= 0xc0; // enable resistor for the two pins

Share this post


Link to post
Share on other sites

Thanks, I forgot about the jumper pin. An interesting note though:

I had internal pull-ups enabled on SDA and SCL, but the code wouldn't run right until I externally pulled up SCL as well. Not sure what that is about.

Share this post


Link to post
Share on other sites
Thanks, I forgot about the jumper pin. An interesting note though:

I had internal pull-ups enabled on SDA and SCL, but the code wouldn't run right until I externally pulled up SCL as well. Not sure what that is about.

 

Hmm Interesting. Are you using your own I2C code? With the USI or software i2c implementation? Mine? TI's? The P1.6 led and its resistor, if the jumper is still on it, will cause the i2c to get stuck. Same with holding a finger on the jumper pins. But the layout means the pin is the source then the resistor and led to ground, no pullups.

 

How long is the cable you are using to bridge the i2c pins on the msp430 to the other chips? Do the cross with power lines? Twisted pair? I2C has a maximum bus capacitance, and if that is exceeded, it can cause issues. Same with too strong or weak pullups. The internal pullups are 30k from what I remember, so who knows.

 

Now I need to breadboard my msp430 with my i2c code and see if it works without external pullups. Hmm.

Share this post


Link to post
Share on other sites

I am using a version of the TI code, an example that I found in slac080, file msp430x20x3_usi_07.c

I have had a lot of trouble with this code, for instance I am using CCS and it doesn't seem to compile the switch block correctly, once the code encounters the first break statement, it exits the block without checking that i2c_state has changed to a new number and that it should now run the next case, so it just exits the ISR. At least that is what I am seeing with the debugger. Anyone else see this?

So I stripped the code down quite a bit just to try and get it to send the address and a write bit.

I also have an msp430g2231 as the slave receiver, and have not had any luck receiving the address. cde, I haven't tried your code yet, anyone know of some example code that definitely works out of the box on masp430g2231 compiled with CCSv4? I would love to just get one thing to work correctly. I don't have a bus pirate or logic analyzer or scope, so I have been pretty frustrated trying to get this to work, but I will keep plugging away and let you know if I get anywhere.

I am not using a twisted pair, are you sure I want to twist the clock and data together? the SCL and SDA wire are about 4" long, not running very near power. what values should i be using for external pullups?

Share this post


Link to post
Share on other sites
it doesn't seem to compile the switch block correctly,

Do you have any optimizations turned on?

 

once the code encounters the first break statement, it exits the block without checking that i2c_state has changed to a new number and that it should now run the next case, so it just exits the ISR. At least that is what I am seeing with the debugger. Anyone else see this?

i'm unable to understand this, could you explain with some code.

Share this post


Link to post
Share on other sites
once the code encounters the first break statement, it exits the block without checking that i2c_state has changed to a new number and that it should now run the next case, so it just exits the ISR.

 

isn't it supposed to be like so? for each isr call it does something (load address, data, toggle led, etc) and sets i2c_state for the next thing to do "after" some time (i.e. next interrupt when isr got called again), not at the same time.

 

i don't know about the debugger, can u use it to debugging real-time events? does your code work on the breadboard?

 

did u change anything from the original example? the example looks fine to me, i am not trying it though, too much setup for me, my few chips are all in my projects.

 

if u have any i2c device (rtc, temp sensor, etc), try and talk to them 1st. u are doing both master and slave at it same time and who knows if it's the master or the slave's problem. i2c timing should be quite tolerant.

 

i do have software i2c code that talks to a rtc (pcf8563), i did not use usi because of layout issues (cannot use p1.6 and p1.7). but i do not have slave side code. if u want it, i can post it here, it's about 150 lines.

Share this post


Link to post
Share on other sites

I am not using a twisted pair, are you sure I want to twist the clock and data together? the SCL and SDA wire are about 4" long, not running very near power. what values should i be using for external pullups?

 

Recommended wiring for i2c breakout cables is supposed to be vcc,sda,scl,gnd and twisted pair is recommended, but that's for a length I don't remember. For my LCD-I2C currently on a breadboard, I do have sda and scl twisted, on a roughly 4" long cable, so ymmv.

 

As for the pullup resistors, 4.7k~10k.

Share this post


Link to post
Share on other sites

ok, thanks for the advice.

I thought I would try the TI code examples in the slac080h zip, since they are published by TI, I figured they would work no problem.

It doesn't work for me. The lights indicating a nack come on for both master and slave. Has anyone else experienced this? I used the code exactly from the example, except I changed the header file to msp430g2231. I am no longer using external pullup resistors, just internal, my multimeter suggests that they are at the right level, perhaps my problem was hooking up the sda and scl to a microcontroller that was off.

Does anyone know if this code is supposed to work, has anyone verified it?

I am now working on writing my own i2c from scratch, since i can't get any examples to work. I am sure I will have some questions about it.

Thank you for your help.

Share this post


Link to post
Share on other sites

i just tried the ...usi08.c under avrgcc and it works.

[EDIT] example code should be msp430x20x3_usi_07.c (master example)

 

i don't have a slave and hooked it up instead to a pcf8563 rtc chip and changed the slave address (0xa2)

 

it may be confusing as the time delay is 5000 counts between transmissions and it's like 200Hz, u may think that the led is constant on. i changed the time delay count to 50000 and it clearly shows on-off-on.

 

  while(1)
 {
   USICTL1 |= USIIFG;                 // Set flag and start communication
   LPM0;                              // CPU off, await USI interrupt
   _NOP();                            // Used for IAR
   for (i = 0; i < 50000; i++);        // Dummy delay between communication cycles, change to 50000 for better visual
 }

 

i also verify by changing the slave address to something else and got constant led on. this verifies the master code works.

 

post-83-135135493047_thumb.jpg

 

can u try to change your delay count to eliminate the led flicking confusion?

 

if that still doesn't work, may be it's a slave side problem.

 

 

personally i won't use this code unless i am doing i2c all the time, software i2c is a lot more flexible and does not take up much space. and u can do it w/ any pins.

Share this post


Link to post
Share on other sites

Hmm, I tried that and now the TI examples are working. I don't understand what was wrong before, but oh well. I am still working on my own code for I2c, so I will let you all know how it goes.

thanks

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...