• Announcements

    • bluehash

      Forum Upgrade   03/11/2017

      Hello Everyone, Thanks for being patient while the forums were being fixed and upgraded. Please see details and report issues in this thread. Thanks!
Sign in to follow this  
Followers 0
cde

i2c Explorer

37 posts in this topic

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 START
bx or 0bx- Transmit Binary number
hx or 0x- Transmit Hex number
x- Transmit Decimal number
r read with Acknowledge (Ack)
n read with No-Acknowledge (Nack)
s Search for i2c Slaves
]- i2c STOP

Nearly 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

larryfraz, larsie, maujabur and 2 others like this

Share this post


Link to post
Share on other sites

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

}

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 likes this

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Hi :)

 

I finally got the i2c Explorer working but i dont seem to get any data nor find the device when scanning all ports.

 

The device is definitivly working, its a RV-3029-C2 RTC from Microchip. I can access it with my BusPirate without any Problems, but i have no idea why i dont get valid responses. When i scan for devices i get ACK from 0x00 to 0xFF.

 

Any ideas? [ i checked for pullups ]

Share this post


Link to post
Share on other sites
Hi :)

 

I finally got the i2c Explorer working but i dont seem to get any data nor find the device when scanning all ports.

 

The device is definitivly working, its a RV-3029-C2 RTC from Microchip. I can access it with my BusPirate without any Problems, but i have no idea why i dont get valid responses. When i scan for devices i get ACK from 0x00 to 0xFF.

 

Any ideas? [ i checked for pullups ]

 

Did you remove the p1.6 led jumper? Common ground?

Share this post


Link to post
Share on other sites

yeah, did that.

now idea why it doesnt work, will try to hack around a little bit in a few days.

might upload a version where you can toggle pullups :)

Share this post


Link to post
Share on other sites

I notice that this project thread has not had any posts in 2012, so wondering if there is a more current version of the i2c explorer project I can find somewhere.

 

I tried building this on the current IAR, only to be faced with a slew of errors, mostly undefined symbols. Now, if there is an updated build someplace, it would save me some drudging through errors.

 

Also, has anyone built i2c explorer on CCS? I found Kerry Wong's blog post "MSP-EXP430G2 I2C Master Examples", but that's limited to the i2c library, not the console / parser / UART part.

 

Thanks in advance!

Share this post


Link to post
Share on other sites

No updates to it, but how are you building it? Debug or final? And what msp are you using it on?

Share this post


Link to post
Share on other sites
No updates to it, but how are you building it? Debug or final? And what msp are you using it on?

 

Debug build on CCS, tried with both G2231 and G2553 (separate Launchpad boards). On the 2553, of course, the USI defines don't exist, and this project seems to have no USCI support.

 

Gave up on the Launchpad for now, moved the i2c device to an Arduino, and I'm up and running. It's refreshing how smoothly things work there.

 

Thanks anyway.

Share this post


Link to post
Share on other sites
No updates to it, but how are you building it? Debug or final? And what msp are you using it on?

 

Debug build on CCS, tried with both G2231 and G2553 (separate Launchpad boards). On the 2553, of course, the USI defines don't exist, and this project seems to have no USCI support.

 

Gave up on the Launchpad for now, moved the i2c device to an Arduino, and I'm up and running. It's refreshing how smoothly things work there.

 

Thanks anyway.

 

Ah, well, that's the problem. I built it on IAR, not CCS. I ended up ordering a bunch of stuff from TI, so I'll be installing CCS 5 when that arrives, I'll try porting it.

Share this post


Link to post
Share on other sites

Hello,

 

I am looking at this code and i have the msp430 launchpad with msp430g2553. If I am comminicating for example to another chip that i know the commands I dont need this right? can I simply learn how to use i2c. commands to read and right?

 

I am a total newbie thanks!

Share this post


Link to post
Share on other sites
Hello,

 

I am looking at this code and i have the msp430 launchpad with msp430g2553. If I am comminicating for example to another chip that i know the commands I dont need this right? can I simply learn how to use i2c. commands to read and right?

 

I am a total newbie thanks!

You can test out your comms by using this.

Share this post


Link to post
Share on other sites
Hello,

 

I am looking at this code and i have the msp430 launchpad with msp430g2553. If I am comminicating for example to another chip that i know the commands I dont need this right? can I simply learn how to use i2c. commands to read and right?

 

I am a total newbie thanks!

 

This won't work for the g2553. It has a USCI peripheral, while this code was made for the USI.

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
Sign in to follow this  
Followers 0