Forums

I2C EEPROM question

Started by matthewbuza1 January 22, 2007
Hey guys,

I haven't posted in a long time. I program in assembler and use the
430f1612. I've never used the I2C, all UART interaction for serial
communication. I'm working on integrating my 1612 with a TUSB3410.
I'm a green newbie when it comes to USB and i2c.

My question is regarding the EEPROM. Im using a CAT24FC16 EEPROM.
I've been able to write all TUSB3410 code to the EEPROM. I can read
one byte at a time from the EERPOM. But i can't seem to read in
sequetial data from the EEPROM. I would like to read back all the
data, and xor'ing all the values for a checksum value, as a check to
see the EEPROM data is correct before the rest of my program
continues. I've looked at the sample code that TI offers regarding
I2C but i'm confused regarding sequential data reading.

The 24FC16's data sheet says all i have to do is transmit the slave
address, acknowledge ever bit sent.

I'm a little confused regarding this action. I've attached some of
my code to show you where i am currently. Ahead of time, Thanks for
your help. Best

-Matt

Just to help you read what i'm trying to do :). I'm first setting
the inital address of the EEPROM so that the sequential reading
begins at the beginning of the TUSB code. Once that is set i'm
trying to read in 137 straight values, xor'ing the values for a
checksum at the end. I've been just trying to read in two values let
alone 137. I'm sorry if any of my terminology is incorrect, all my
experience is through sample code, datasheets and this forum. Thanks.
CODE:

;********************************************************************
**********
#include "msp430x16x.h"

;--------------------------------
----------
ORG 02500h ; Progam Start
;--------------------------------
----------

RESET mov.w #0A00h,SP ; Initialize stackpointer
mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop Watchdog Timer
SetupP3 bis.b #04Ah,&P3SEL ; Assign I2C pins to
module
bis.b #040h,&P4OUT
;bis.b #I2CSTP,&I2CTCTL
mov.b #000h,R5
mov.b #000h,R6

Mainloop nop
jmp Mainloop
call #READPOINTSET
;bic.b #I2CTRX,&I2CTCTL
call #I2CREADSETUP
bis.b #MST,&U0CTL ; Master mode
bis.b #I2CSTT+I2CSTP,&I2CTCTL ; Initiate transfer
bis.b #LPM0+GIE,SR ; Enter LPM0, enable interrupts
nop
;####################################################################
######################
I2C_ISR; Common ISR for I2C Module
;####################################################################
######################

add &I2CIV,PC ; Add I2C offset vector
reti ; No interrupt
reti ; Arbitration Lost
reti ; No Acknowledge
reti ; Own Address
reti ; Register Access Ready
jmp RXRDY_ISR ; Receive Ready
reti ; Transmit Ready
reti ; General Call
reti ; Start Condition
RXRDY_ISR mov.b &I2CDRB,R5 ; RX data in R5
xor.b R5,R6
bic #LPM0,0(SP) ; Clear LPM0

;####################################################################
######################
I2CWRITESETUP;
;####################################################################
######################

bis.b #I2C+SYNC,&U0CTL ; Switch USART0 to I2C
mode
bic.b #I2CEN,&U0CTL ; Disable I2C
mov.b #I2CSSEL0+I2CTRX+I2CRM,&I2CTCTL; S/W controls
data flow, SMCLK
;bic.b #,&I2CTCTL
mov.w #050h,&I2CSA ; Slave address
mov.b #TXRDYIE,&I2CIE ; Enable I2C interrupts
bis.b #I2CEN,&U0CTL ; Enable I2C

ret

;####################################################################
######################
I2CREADSETUP;
;####################################################################
######################
bis.b #I2C+SYNC,&U0CTL ; Recommended init
procedure
bic.b #I2CEN,&U0CTL ; Recommended init
procedure
bis.b #I2CSSEL0,&I2CTCTL ; SMCLK
;mov.b #008h,&I2CNDAT ; Read one byte
mov #0050h,&I2CSA ; Slave Address is 048h
bic.b #I2CTRX,&I2CTCTL
bis.b #RXRDYIE,&I2CIE ; Enable RXRDYIE
bis.b #I2CEN,&U0CTL ; Enable I2C

ret

;####################################################################
######################
READPOINTSET;
;####################################################################
######################

nop
call #I2CWRITESETUP
nop
nop

;Start/Slave
bis.b #MST,&U0CTL
bis.b #I2CSTT,&I2CTCTL ;Write, slave code

;Address
Addressp bit.b #TXRDYIFG,&I2CIFG ;check for ready bit
jz Addressp
mov.b #001h,&I2CDRB ;Write Addressing bit
bis.b #I2CSTP,&I2CTCTL
ret

Beginning Microcontrollers with the MSP430