Forums

I2C communication problem

Started by Vasant May 29, 2006
Hi,
i have been trying to work with the I2C module present in eZ430-F2013,

i am not getting an acknowledgment back from the connected slave device.

i have tried connecting ATMEL 24C04 EEPROM chip & Philips PCF8574P as
slave devices, but still no resluts!

my program is written in assembly and it gets struck while waiting for
the acknowledgment.

i downloaded some example programs offerd online by TI, but there is
no program for I2C! 

is it necessary for me to enable to port pins and their direction???

i have pasted the program that i have been trying to, so if any one
out there can help with this would be great! 

thanx in advance

-vasant 

*********************************************************

#include "msp430x20x3.H"

		 ORG 0F800H
main	         MOV.W #0280h,SP			; Initilize the stack pointer
		 MOV.W #WDTPW+WDTHOLD,&WDTCTL 		; stop the watchdog timer
		 
		 
		 MOV.B #00000010B,&USICKCTL
		 MOV.B #11001110B,&USICTL0
		 MOV.B #01000000B,&USICTL1
                 BIS.W #0008,SR
		
		
		 CALL #START
		 MOV.B #01000000B,&USISRL
		 BIS.B #02,&USICTL0
		 MOV.B #8,&USICNT
		 CALL #TX_ACK
		 
		 MOV.B #55H,&USISRL 			; SELECT MEMORY ADDRESS
		 MOV.B #8,&USICNT
		 CALL #TX_ACK
		 
		 MOV.B #01H,&USISRL
		 MOV.B #8,&USICNT
		 CALL #TX_ACK
		 
		 CALL #RECEIVE
		 
		 JMP main

RECEIVE		MOV.B #01000001B,&USISRL
		MOV.B #11101000B,&USICTL0		;RECEIVE A BYTE FROM SLAVE
		BIC.B #02,&USICTL0
		MOV.B #8,&USICNT
  	        CALL #TX_ACK
		
		 MOV.B #55H,&USISRL 			; SELECT MEMORY ADDRESS
		 CALL #TX_ACK
		 
		 CALL #RX_ACK
		 MOV.B &USISRL,R6
		 RET
		 
		 

			;transmit ACK/NACK
			
TX_ACK		BIC.B #USIOE,&USICTL0			; SDA input
		MOV.B #01h,&USICNT 			; USICNTx = 1
		
TEST_USIIFG1	BIT.B #USIIFG,&USICTL1 			; Test USIIFG
		JZ TEST_USIIFG1
		
HANDLE_NACK	BIT.B #01h,&USISRL			; Test received ACK bit
		JNZ HANDLE_NACK 			; Handle if NACK
		RET
		
			; Receive ACK
	
RX_ACK		BIS.B #USIOE,&USICTL0 			; SDA output
		MOV.B #00h,&USISRL 			; MSB = 0
TEST_USIIFG 	BIT.B #USIIFG,&USICTL1 			; Test USIIFG
		JNZ TEST_USIIFG		
		RET
	
		

START	        MOV.B #000h,&USISRL 				; MSB = 0
		BIS.B #USIGE+USIOE,&USICTL0 			; Latch/SDA output enabled
		BIC.B #USIGE,&USICTL0				; Latch disabled
		RET


ORG 0FFFEH						; initilize the reset 
DW  main
    END




Beginning Microcontrollers with the MSP430

Vasant,

Read the F2xx's Family User's Guide & understand the workings, Chapter 13:
http://www-s.ti.com/sc/psheets/slau144b/slau144b.pdf

The I2C samples are available, albeit for different family but similar:
http://www-s.ti.com/sc/techzip/slac014.zip

HTH.

Regards,
KF

----- Original Message ----- 
From: "Vasant" <vasant.p@vasa...>
To: <msp430@msp4...>
Sent: Monday, May 29, 2006 12:12
Subject: [msp430] I2C communication problem


| Hi,
| i have been trying to work with the I2C module present in eZ430-F2013,
| 
| i am not getting an acknowledgment back from the connected slave device.
| 
| i have tried connecting ATMEL 24C04 EEPROM chip & Philips PCF8574P as
| slave devices, but still no resluts!
| 
| my program is written in assembly and it gets struck while waiting for
| the acknowledgment.
| 
| i downloaded some example programs offerd online by TI, but there is
| no program for I2C! 
| 
| is it necessary for me to enable to port pins and their direction???
| 
| i have pasted the program that i have been trying to, so if any one
| out there can help with this would be great! 
| 
| thanx in advance
| 
| -vasant 
| 
| *********************************************************
| 
| #include "msp430x20x3.H"
| 
| ORG 0F800H
| main          MOV.W #0280h,SP ; Initilize the stack pointer
| MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop the watchdog timer
| 
| 
| MOV.B #00000010B,&USICKCTL
| MOV.B #11001110B,&USICTL0
| MOV.B #01000000B,&USICTL1
|                  BIS.W #0008,SR
| 
| 
| CALL #START
| MOV.B #01000000B,&USISRL
| BIS.B #02,&USICTL0
| MOV.B #8,&USICNT
| CALL #TX_ACK
| 
| MOV.B #55H,&USISRL ; SELECT MEMORY ADDRESS
| MOV.B #8,&USICNT
| CALL #TX_ACK
| 
| MOV.B #01H,&USISRL
| MOV.B #8,&USICNT
| CALL #TX_ACK
| 
| CALL #RECEIVE
| 
| JMP main
| 
| RECEIVE MOV.B #01000001B,&USISRL
| MOV.B #11101000B,&USICTL0 ;RECEIVE A BYTE FROM SLAVE
| BIC.B #02,&USICTL0
| MOV.B #8,&USICNT
|           CALL #TX_ACK
| 
| MOV.B #55H,&USISRL ; SELECT MEMORY ADDRESS
| CALL #TX_ACK
| 
| CALL #RX_ACK
| MOV.B &USISRL,R6
| RET
| 
| 
| 
| ;transmit ACK/NACK
| 
| TX_ACK BIC.B #USIOE,&USICTL0 ; SDA input
| MOV.B #01h,&USICNT ; USICNTx = 1
| 
| TEST_USIIFG1 BIT.B #USIIFG,&USICTL1 ; Test USIIFG
| JZ TEST_USIIFG1
| 
| HANDLE_NACK BIT.B #01h,&USISRL ; Test received ACK bit
| JNZ HANDLE_NACK ; Handle if NACK
| RET
| 
| ; Receive ACK
| 
| RX_ACK BIS.B #USIOE,&USICTL0 ; SDA output
| MOV.B #00h,&USISRL ; MSB = 0
| TEST_USIIFG BIT.B #USIIFG,&USICTL1 ; Test USIIFG
| JNZ TEST_USIIFG 
| RET
| 
| 
| 
| START         MOV.B #000h,&USISRL ; MSB = 0
| BIS.B #USIGE+USIOE,&USICTL0 ; Latch/SDA output enabled
| BIC.B #USIGE,&USICTL0 ; Latch disabled
| RET
| 
| 
| ORG 0FFFEH ; initilize the reset 
| DW  main
|     END
| 


Hi KF,

thanx for the speedy response and the links.

i have alread downloaded the FX2XX user guide slau144b.

the problem is the IAR which i got along with the eZ430-F2013 dosnt
have  the description about the control registers assosiated with the
USI as mentioned in slau144b version of the user guide.

but the fx2xx famil user guide version1 slau144a does provide the same
decsriptions as available with the IAR! so now i am confused as to
which one to follow!

yeah i have been trying to go thru programs which i downloaded from
the link provided from u! i havent yet tried those with respect to F2013! 

i will keep u all posted regarding that!

now in between if any one worked on this and can tell me what is
USIIFG flag and is it necessary to use it in the program??

regards
-vasant




Vasant,

Please check out App note SLAA208. It has what you are looking for.

As for the Family User's Guide, it seems that the Rev. C is a bit messed up.
The Chapters 11-13 were talking about some future products which has TWO USI
modules, whereas the F20xx has only ONE USI module.

The descriptions pertaining to the USCI_Bx modules should be relevant to
F20xx, which has only SPI & I2C modes only. Or if you're confuse, refer to
Rev. B docs only until TI comes out with some new revision of the guide.

HTH.

Regards,
KF

----- Original Message -----
From: "Vasant" <vasant.p@vasa...>
To: <msp430@msp4...>
Sent: Monday, May 29, 2006 17:44
Subject: Re: [msp430] I2C communication problem


Hi KF,

thanx for the speedy response and the links.

i have alread downloaded the FX2XX user guide slau144b.

the problem is the IAR which i got along with the eZ430-F2013 dosnt
have  the description about the control registers assosiated with the
USI as mentioned in slau144b version of the user guide.

but the fx2xx famil user guide version1 slau144a does provide the same
decsriptions as available with the IAR! so now i am confused as to
which one to follow!

yeah i have been trying to go thru programs which i downloaded from
the link provided from u! i havent yet tried those with respect to F2013!

i will keep u all posted regarding that!

now in between if any one worked on this and can tell me what is
USIIFG flag and is it necessary to use it in the program??

regards
-vasant


--- In msp430@msp4..., "KF Leong" <kfleong@...> wrote:
>
> Vasant,
> 
> Please check out App note SLAA208. It has what you are looking for.
> 
> As for the Family User's Guide, it seems that the Rev. C is a bit
messed up.
> The Chapters 11-13 were talking about some future
products which has
TWO USI
> modules, whereas the F20xx has only ONE USI
module.
> 
> The descriptions pertaining to the USCI_Bx modules should be relevant to
> F20xx, which has only SPI & I2C modes only. Or if you're confuse,
refer to
> Rev. B docs only until TI comes out with some new
revision of the guide.
> 
> HTH.
> 
> Regards,
> KF
> 
> ----- Original Message -----
> From: "Vasant" <vasant.p@...>
> To: <msp430@msp4...>
> Sent: Monday, May 29, 2006 17:44
> Subject: Re: [msp430] I2C communication problem
> 
> 
> Hi KF,
> 
> thanx for the speedy response and the links.
> 
> i have alread downloaded the FX2XX user guide slau144b.
> 
> the problem is the IAR which i got along with the eZ430-F2013 dosnt
> have  the description about the control registers assosiated with the
> USI as mentioned in slau144b version of the user guide.
> 
> but the fx2xx famil user guide version1 slau144a does provide the same
> decsriptions as available with the IAR! so now i am confused as to
> which one to follow!
> 
> yeah i have been trying to go thru programs which i downloaded from
> the link provided from u! i havent yet tried those with respect to
F2013!
> 
> i will keep u all posted regarding that!
> 
> now in between if any one worked on this and can tell me what is
> USIIFG flag and is it necessary to use it in the program??
> 
> regards
> -vasant
>

Hi.
Hope I'm not too late and it helps:
The description of the USI Module (Chapter 9 of part-manual)
describes the USIIFG as USICounter interrupt flag. It's possible to
predefine a number of bit to be received or transmitted.
If this is reached, the USIIFG-Flag is set and if enabled, an
interrupt occurs.

BTW Anybody out there having an AN for IIC with USI?
I'm working on this, but need some mor time.
Regards




Hi,
i am now able to work with the I2C module of the f2013! 
 i have been using, philips PCF8574P as the slave device and have been
able to interface an LCD unit and a keypad,

now the strange thing i had to do to get the communication going is
that  for every byte (address or data) i send to the slave,a START
condition is required! 

according to what i understand about I2C is that a start condition is
required only when we are sending the address of a slave, after that
we can send as many byte of data as we want, but without a start
condition. in order to communicate with the oter slaves in the
network, just another start condition followed by address of 2nd slave
 is sufficient.

but in my project i have to send first a start, address of slave,
start ( again) data, to communicate with other slave in the setup i
have to send a stop, then a start, address of slave 2, start, data.

can anyone out there, can explain this???

thanx in advance
-vasant





I recall vaguely trying out the I2C in MSP430 and it not working properly,
I had to do
something similar to you, but I can't recall the details of it.
There was an errata on it at that time, where TI suggested the workaround was to
use the
I2C
ONLY with interrupts.
I don't know if that silicon issue is resolved in the meantime.
Have a look around at the errata on it, there might be something there.

B rgds
Kris

>-----Original Message-----
>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Vasant
>Sent: Friday, 2 June 2006 1:28 PM
>To: msp430@msp4...
>Subject: [msp430] Re: I2C communication problem
>
>Hi,
>i am now able to work with the I2C module of the f2013!
> i have been using, philips PCF8574P as the slave device and have been
>able to interface an LCD unit and a keypad,
>
>now the strange thing i had to do to get the communication going is
>that  for every byte (address or data) i send to the slave,a START
>condition is required!
>
>according to what i understand about I2C is that a start condition is
>required only when we are sending the address of a slave, after that
>we can send as many byte of data as we want, but without a start
>condition. in order to communicate with the oter slaves in the
>network, just another start condition followed by address of 2nd slave
> is sufficient.
>
>but in my project i have to send first a start, address of slave,
>start ( again) data, to communicate with other slave in the setup i
>have to send a stop, then a start, address of slave 2, start, data.
>
>can anyone out there, can explain this???
>
>thanx in advance
>-vasant
>
>
>
>
>
>
>
>.
>
>
>Yahoo! Groups Links
>
>
>
>
>



Kris,

i have gone thru the errata of I2C, that information mentioned is only
for MSP430 used as a slave.

in my application i have been using the MSP430 as the only master (
both  for Tx & Rx), so the errata information dosnt apply here.

i did contact TI regarding this, and they say they are working on it!

will keep you all posted once i get a response from them.

in the mean time, i tried to write a header file for I2C module. i
have included functions like START,STOP, TRANSMIT, TX_ACK, RX AND
RX_ACK in that. when i use this header file in my application, it
assembles and loads on the f2013 with out any problem, but when i try
make a call to a function defined in header file,it gives as error:
"driver error"

any idea what is this error? and is there any standards to be followed
to creat the header files?
i am using the IAR kick start version, which comes along with eZ430-F2013.

cheers
-vasant







Hi Vasant,

I'm quite sure the misbehavior I came across was when I was controlling an I2C
EEPROM as a
Master - where the errata mentioned using interrupts as a workaround...
I'll see if I can dig it up on the weekend.

"driver error" sounds exotic... That's not a compiler/linker error, is
it ?

For header files, there's no real standards as such, except to manage a project
with many
modules easier.
In general, I personally use this general rule of thumb, but that's taste and
method of
course :
- Each module gets its own header file if needed.
The header file typically will contain the prototypes of the functions that
could be
called from other        modules. It also declares any runtime constants, types
etc.
specific to the module.
You can use a single header file referencing global project stuff, like
common.h,
target.h, system.h or some such.
- Global variables needed for the module are declared in the particular module -
not in
main module, with externs to those variables in the module's header file.
This makes it a lot easier to later add that module in other projects by just
including
the header file
in other modules where you're referencing its functions or variables.

The ideal of course is to use everything as private as possible to the module.
For example, keeping functions static, and for the API you could make an init
call where
you provide a pointer to the data (structures) that you need operated on by the
module's
private functions.
This tends to chew a bit more RAM though, so sometimes I dont see the merit on
embedded
systems with small controllers for this.

This is of course one of many ways to skin this cat.

B rgds
Kris

>-----Original Message-----
>From: msp430@msp4... [mailto:msp430@msp4...] On Behalf Of Vasant
>Sent: Friday, 2 June 2006 5:22 PM
>To: msp430@msp4...
>Subject: [msp430] Re: I2C communication problem
>
>Kris,
>
>i have gone thru the errata of I2C, that information mentioned is only
>for MSP430 used as a slave.
>
>in my application i have been using the MSP430 as the only master (
>both  for Tx & Rx), so the errata information dosnt apply here.
>
>i did contact TI regarding this, and they say they are working on it!
>
>will keep you all posted once i get a response from them.
>
>in the mean time, i tried to write a header file for I2C module. i
>have included functions like START,STOP, TRANSMIT, TX_ACK, RX AND
>RX_ACK in that. when i use this header file in my application, it
>assembles and loads on the f2013 with out any problem, but when i try
>make a call to a function defined in header file,it gives as error:
>"driver error"
>
>any idea what is this error? and is there any standards to be followed
>to creat the header files?
>i am using the IAR kick start version, which comes along with eZ430-F2013.
>
>cheers
>-vasant
>
>
>
>
>
>
>
>
>
>.
>
>
>Yahoo! Groups Links
>
>
>
>
>