cde 334 Posted October 15, 2010 Share Posted October 15, 2010 NOTE: This was built using IAR, for an msp430 with the USI peripheral. It will need editing to work on USCI peripherals or if compiled in CCS or GCC. Updated 12/12/12: http://forum.43oh.com/topic/126-i2c-explorer/?p=25918 I like i2c, and have one main project I want to create based on turning a scrolling led display into a computer/net/micro controller accessible one (it has an i2c eeprom, and its original mc is still in use).Having gotten the launchpad, it was one step closer to completion. The next step was getting i2c protocol working and such. With the builtin USI of the launchpad, and Joby's SPI explorer (which uses NJ's uart to boot), I was able to make an i2c Explorer.It uses the UART code without modification (except that I am using IAR instead of mspgcc or CCS) and modified Joby's command processing, with the i2c USI built from scratch.There are a handful of commands.[- i2c STARTbx or 0bx- Transmit Binary numberhx or 0x- Transmit Hex numberx- Transmit Decimal numberr read with Acknowledge (Ack)n read with No-Acknowledge (Nack)s Search for i2c Slaves]- i2c STOPNearly the same commands as the buspirate/busninja/spi-explorer. I broke out the nack read because it was easier, allows more control, and not all i2c slaves want/expect a nack on the last read.It is not completely refined. Still some stuff that needs to be removed/polished (Slave search should only output on responded addresses, instead of needing someone to search through all 255 address tests responses.)Bus speed is non-standard as far as I can see (USI Clock is SMCLK at 1mhz, divided at 128 as per TI's USI application note. 1mhz/128 = 7812hz = ~8khz???) This needs to be fixed, and a TI introduction to USI/USCI powerpoint shows that the bus can be driven at 500khz at 1mhz clock. Probably just needs the correct divider selection (Divide clock by 2 for 500k (400k i2c speed) or by 8 for 125k (100k i2c speed).This is beta/preliminary release. Only been tested with a PCF8574. Code clocks in at 1920 bytes, with no optimization (Standard IAR project with no defaults changed). UART at 9600 like normal, pin 1.7 is sda, pin 1.6 is scl (can't be changed due to USI so remove the p1.6 led jumper) and p1.0 is a status light.Will be testing with faster speed and more i2c devices soon. i2c.zip V0JT4, maujabur, larsie and 2 others 5 Quote Link to post Share on other sites
gatesphere 45 Posted October 15, 2010 Share Posted October 15, 2010 Awesome! Thanks for sharing! Quote Link to post Share on other sites
simpleavr 399 Posted October 16, 2010 Share Posted October 16, 2010 since u mentioned that u are using some of joby's code. just a heads-up, if u ever need to run w/ 8Mhz at 9600+, u will start to lose bit6 and bit7 for every byte u send. inside uart.c timer interrupt handler the add offset (ie. CCR0 += BIT_TIME) need to be moved to top as the 1st statement to run in the handler. otherwise after shifting out the 1st 6 bits, the time will be off enough for u to loss the last 1 or 2 bits. it is because the "if (!isReceiving)" check takes a few cycles to run. #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { if(!isReceiving) { CCR0 += BIT_TIME; // Add Offset to CCR0 <<<<<<< move this line to top of function if ( bitCount == 0) // If all bits TXed { TACTL = TASSEL_2; // SMCLK, timer off (for power consumption) CCTL0 &= ~ CCIE ; // Disable interrupt } Quote Link to post Share on other sites
displacedtexan 1 Posted February 26, 2011 Share Posted February 26, 2011 Truly excellent work. I finally managed to get it working. Kind of like an i2c buspirate for the MSP430. On to my question. I am testing your i2c Explorer with a DS3232 RTC. It uses the same address registers as the more popular DS1307 RTC. I am having trouble reading back the time. Code to set time: i2c> [hxd0 0 0 hx30 hx09 hx02 hx07 hx09 hx09] i2c START WRITE: 0xD0 Ack WRITE: 0x00 Ack WRITE: 0x00 Ack WRITE: 0x30 Ack WRITE: 0x09 Ack WRITE: 0x02 Ack WRITE: 0x07 Ack WRITE: 0x09 Ack WRITE: 0x09 Ack i2c STOP Code to read time: i2c> [hxd0 0 [hxd1 r r r r r r r r] i2c START WRITE: 0xD0 Ack WRITE: 0x00 Ack i2c START WRITE: 0xD1 Ack READ: 0xFF Ack READ: 0xFF Ack READ: 0xFF Ack READ: 0xFF Ack READ: 0xFF Ack READ: 0xFF Ack READ: 0xFF Ack READ: 0xFF Ack i2c STOP I have wired pin 18(SCL) of the DS3232 to the MSP430 P1.6 with a 4.7k pullup resistor. I also wired pin 17 (SDA) to P1.7 with a 4.7k pullup. The LED2 jumper for P1.6 has been removed. Any ideas what I have done wrong? Thanks! Quote Link to post Share on other sites
cde 334 Posted February 28, 2011 Author Share Posted February 28, 2011 Truly excellent work. I finally managed to get it working. Kind of like an i2c buspirate for the MSP430. I have wired pin 18(SCL) of the DS3232 to the MSP430 P1.6 with a 4.7k pullup resistor. I also wired pin 17 (SDA) to P1.7 with a 4.7k pullup. The LED2 jumper for P1.6 has been removed. Any ideas what I have done wrong? Thanks! Hmm, your not the first to have this issue. Not really sure, of what is going on. I will be doing a rtc related project soon, so I can fully suss out the issue, but the first thing to ask, did you change the i2c.c code to disable the internal pullups? If you have both internal and external pullups, something might be amiss. Quote Link to post Share on other sites
JMLB 24 Posted February 28, 2011 Share Posted February 28, 2011 neat thanks Quote Link to post Share on other sites
displacedtexan 1 Posted March 2, 2011 Share Posted March 2, 2011 Hmm, your not the first to have this issue. Not really sure, of what is going on. I will be doing a rtc related project soon, so I can fully suss out the issue, but the first thing to ask, did you change the i2c.c code to disable the internal pullups? If you have both internal and external pullups, something might be amiss. Thanks for taking the time to look at it cde. I had not commented out the internal pullups in i2c.c, but just did and get the exact same result. Thanks! Quote Link to post Share on other sites
maujabur 1 Posted March 11, 2011 Share Posted March 11, 2011 I've been experimenting with the ds3232 recently, but with a atmega328. I had a similar problem, in the end it was using a 7 bit addressing scheme. It responds on the address 0x68. Later this week I'll try to use it with the msp430 and post back the results. Quote Link to post Share on other sites
maujabur 1 Posted March 11, 2011 Share Posted March 11, 2011 So I'm trying to get it working... The serial is not working properly for me, I tried to use putty under windows, configured it to 9600 8n1 Xon/Xoff When I type, I get some strange echo characters, like Quote Link to post Share on other sites
bluehash 1,581 Posted March 12, 2011 Share Posted March 12, 2011 Xon/Xoff Hardware handshake should be off. Quote Link to post Share on other sites
maujabur 1 Posted March 12, 2011 Share Posted March 12, 2011 trying without the Xon/Xoff. same error, I must be doing something wrong! I used IAR for the project, as I understand it was originally used. I'll try the original uart code and see what happens. When I try to send { console_puts("session begin"); } I get back 77 Quote Link to post Share on other sites
maujabur 1 Posted March 12, 2011 Share Posted March 12, 2011 Now I got it working! In order to get a response from the ds3232 I had to do the following (not what the datasheet says - weird) i2c> [0xd0 0x0 0x30 0x15 0x08 ] i2c START WRITE: 0xD0 Ack WRITE: 0x00 Ack WRITE: 0x30 Ack WRITE: 0x15 Ack WRITE: 0x08 Ack i2c STOP i2c> [0xd0 0 ] i2c START WRITE: 0xD0 Ack WRITE: 0x00 Ack i2c STOP i2c> [0xd1 r r n] i2c START WRITE: 0xD1 Ack READ: 0x41 Ack READ: 0x15 Ack READ: 0x08 Nack! i2c STOP bluehash 1 Quote Link to post Share on other sites
bluehash 1,581 Posted March 13, 2011 Share Posted March 13, 2011 Thanks for the update. I'm sure someone will find it useful. Quote Link to post Share on other sites
cde 334 Posted March 17, 2011 Author Share Posted March 17, 2011 Now I got it working! In order to get a response from the ds3232 I had to do the following (not what the datasheet says - weird) ~snip~ What is the actual difference from the datasheet? Is it that you did a full stop between the second and third sequence, instead of a restart? Quote Link to post Share on other sites
maujabur 1 Posted March 17, 2011 Share Posted March 17, 2011 What is the actual difference from the datasheet? Is it that you did a full stop between the second and third sequence, instead of a restart? Yes, that's the difference. Not actually a problem, and I don't know if the issue is with de chip or the code, didn't check that yet. I'm using the subroutines in i2c.c in a project for a clock, but just posted that reply in order to try and help displacedtexan that was trying to get the ds3232 working with the scanner. 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.