joeyeisinger 0 Posted November 21, 2010 Share Posted November 21, 2010 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 Quote Link to post Share on other sites
bluehash 1,581 Posted November 21, 2010 Share Posted November 21, 2010 Is your code waiting for an event on P1.6? Quote Link to post Share on other sites
simpleavr 399 Posted November 22, 2010 Share Posted November 22, 2010 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 joeyeisinger 1 Quote Link to post Share on other sites
joeyeisinger 0 Posted November 22, 2010 Author Share Posted November 22, 2010 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. Quote Link to post Share on other sites
OCY 19 Posted November 22, 2010 Share Posted November 22, 2010 I think there is something fishy about the USICNT register. It is very sensitive to noise and does not count right. See, for example, http://e2e.ti.com/support/microcontroll ... 73486.aspx NJC also found something he could not explain when he set it to 10 in SPI Master mode. Quote Link to post Share on other sites
cde 334 Posted November 22, 2010 Share Posted November 22, 2010 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. Quote Link to post Share on other sites
joeyeisinger 0 Posted November 23, 2010 Author Share Posted November 23, 2010 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? Quote Link to post Share on other sites
bluehash 1,581 Posted November 23, 2010 Share Posted November 23, 2010 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. Quote Link to post Share on other sites
simpleavr 399 Posted November 23, 2010 Share Posted November 23, 2010 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. Quote Link to post Share on other sites
cde 334 Posted November 23, 2010 Share Posted November 23, 2010 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. Quote Link to post Share on other sites
joeyeisinger 0 Posted November 27, 2010 Author Share Posted November 27, 2010 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. Quote Link to post Share on other sites
simpleavr 399 Posted November 28, 2010 Share Posted November 28, 2010 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. 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. joeyeisinger 1 Quote Link to post Share on other sites
joeyeisinger 0 Posted December 1, 2010 Author Share Posted December 1, 2010 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 Quote Link to post Share on other sites
simpleavr 399 Posted December 1, 2010 Share Posted December 1, 2010 if u need reference i had i2c master code (software, can use any pair of pins) all contained in one .h file. i am using it to read / write a rtc chip. http://www.simpleavr.com/msp430-project ... tc-clock.c http://www.simpleavr.com/msp430-project ... lock/i2c.h Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.