Jump to content

  • Log In with Google      Sign In   
  • Create Account

Photo

i2c Explorer


  • Please log in to reply
36 replies to this topic

#1 cde

cde

    Enigmatic Decadence

  • Members
  • 863 posts

Posted 15 October 2010 - 12:19 PM

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.co...plorer/?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.

Attached Files

  • Attached File  i2c.zip   58.38KB   802 downloads

  • JMLB, V0JT4, maujabur and 2 others like this

#2 gatesphere

gatesphere

    Level 3

  • Members
  • 430 posts

Posted 15 October 2010 - 01:17 PM

Awesome! Thanks for sharing!
MSPhere - a framework of functions for rapid prototyping with the LaunchPad platform
My other pages: home page/portfolio || development blog

#3 simpleavr

simpleavr

    Level 3

  • Members
  • 642 posts
  • Locationtoronto


Posted 16 October 2010 - 04:35 AM

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
}
www.simpleavr.com :: breadboard good, use breadboard

#4 displacedtexan

displacedtexan

    Member

  • Members
  • PipPip
  • 29 posts

Posted 26 February 2011 - 04:09 PM

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!

#5 cde

cde

    Enigmatic Decadence

  • Members
  • 863 posts

Posted 28 February 2011 - 09:15 AM

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.

#6 JMLB

JMLB

    Level 2

  • Members
  • 221 posts
  • LocationOttawa

Posted 28 February 2011 - 06:09 PM

neat thanks
I am back. I have been busy and did not have internet for a few months and a few other personal issues that are settling down.

My exploration in micro controllers (STM32 And Eval bot for now)
http://hobbymc.blogspot.com/

#7 displacedtexan

displacedtexan

    Member

  • Members
  • PipPip
  • 29 posts

Posted 02 March 2011 - 05:45 PM

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!

#8 maujabur

maujabur

    Noob Class

  • Members
  • 5 posts

Posted 11 March 2011 - 01:12 PM

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.

#9 maujabur

maujabur

    Noob Class

  • Members
  • 5 posts

Posted 11 March 2011 - 10:56 PM

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 ÿíÿÿíÿ

I even used another ftdi cable and tried with another msp430g2231 chip and the situation didn't change.

Any ideas?

Thanks a lot

#10 bluehash

bluehash

    Site Admin

  • Administrators
  • 5,165 posts

Posted 12 March 2011 - 12:17 AM

Xon/Xoff


Hardware handshake should be off.

Stellarisiti - Join the new Tiva-C/Stellaris ARM Forums discussing Stellaris Microcontroller.

C2kCentral - C2000 News, Projects and Forums
43oh - MSP430 Discussion, News, Projects and Hacks
MachineGrid - Robots, Hacks and Technology!


#11 maujabur

maujabur

    Noob Class

  • Members
  • 5 posts

Posted 12 March 2011 - 12:32 AM

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÷çNWwçÿ.



Thanks for the fast response! In a few minutes I'll post back the results for the code at http://www.msp430lau... ... chpad.html

I've got the ds3232 wired to the setup, as soon as I get it working, will share the results.

#12 maujabur

maujabur

    Noob Class

  • Members
  • 5 posts

Posted 12 March 2011 - 07:38 PM

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

#13 bluehash

bluehash

    Site Admin

  • Administrators
  • 5,165 posts

Posted 13 March 2011 - 03:23 AM

Thanks for the update. I'm sure someone will find it useful.

Stellarisiti - Join the new Tiva-C/Stellaris ARM Forums discussing Stellaris Microcontroller.

C2kCentral - C2000 News, Projects and Forums
43oh - MSP430 Discussion, News, Projects and Hacks
MachineGrid - Robots, Hacks and Technology!


#14 cde

cde

    Enigmatic Decadence

  • Members
  • 863 posts

Posted 17 March 2011 - 08:15 AM

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?

#15 maujabur

maujabur

    Noob Class

  • Members
  • 5 posts

Posted 17 March 2011 - 11:37 AM

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.

#16 lastaid

lastaid

    Level 1

  • Members
  • 73 posts

Posted 19 March 2011 - 06:58 PM

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 ]

#17 cde

cde

    Enigmatic Decadence

  • Members
  • 863 posts

Posted 19 March 2011 - 09:30 PM

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?

#18 lastaid

lastaid

    Level 1

  • Members
  • 73 posts

Posted 05 April 2011 - 10:01 PM

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 :)

#19 anindo

anindo

    Noob Class

  • Members
  • 2 posts

Posted 02 August 2012 - 10:09 AM

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!

#20 cde

cde

    Enigmatic Decadence

  • Members
  • 863 posts

Posted 02 August 2012 - 03:38 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users