Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

How to I2C for many data?

Status
Not open for further replies.

slurp

Newbie level 6
Joined
Apr 19, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,491
Dear Eda-board-ians,

From a past thread , i received the links such as below.

http://ww1.microchip.com/downloads/e...tes/00976A.pdf

Here is the assembler code example

http://ww1.microchip.com/downloads/e...otes/AN976.zip

I have read them, and have followed the I2C PDF presentaiton by Microchip from one of the links above.

However, the presentation shows I2C in assembly language
(which is the language I want to use) but it only Write/Read a data
(in this case, 34h written into 12h and then read and displayed to PORTB)

The problem occured when I re-edit it to write in more data into the external EEPROM 24LC04B.
but it turns out, the whole code was SUCCESSFULLY SIMULATED by MPLAB IDE but became malfunction when I plug it into the circuitry...no LEDs light up.

I wrote a Loop using INDR and FSR to place in 3 data. (for example into location23h,24h,25h with vaules 33h,44h,55h.)

then after each location, i would light up the LED to indicate it has written.
and also the same when i wrote the looping for READ.

Is there a certain register/ SETTING THAT i need to define, or set?

thanking you all for your great help and time.
PLease advise,
Cheers,
Slurp
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,148
Reputation
4,302
Reaction score
2,088
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097
As per i2c you have to give the starting address of memory,,, if it is sequential write or read it increments the counter by itself and writes or read the data. If it is random read or write then everytime you have to soecify the memory location before you read or write data.......
it is not adviced to interrupt the i2c frame sequence by doing other thing in between i2c routine... but after every data you write you can blink led but dont waste i2c routine timing, and see that the timing is not affected.............
 

slurp

Newbie level 6
Joined
Apr 19, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,491
;the part hightlighted in different color are added by myself

call Data_Seq

Data_Seq
movlw LC01ADDR ;ADDRESS LOCATION 12H
movwf FSR ;fSR = 12h
movlw 34h
movwf INDF ;@12h = 34h
incf FSR,F
movlw 44h
movwf INDF ;@13h = 44h
incf FSR,F
movlw 55h ;@14h = 55h
movwf INDF

return

;**************************************************
I2CWrite
movlw 0x0F
movwf PORTB
call DELAY_V_LONG
call DELAY_V_LONG
clrf PORTB
banksel SSPCON2
bsf SSPCON2,SEN
call WaitMSSP

; Send and Check CONTROL BYTE
movlw LC01CTRLIN ;LOAD CONTROL BYTE FOR input mode
call Send_I2C_Byte ;SEND BYTE
call WaitMSSP ;WAIT FOR I2C OPERATION

BANKSEL SSPCON2
btfsc SSPCON2,ACKSTAT ;CHECK ACK STATUS BIT
goto I2CFail ;FAILED, SKIP IF SUCCEED

;Send and Check ADDRESS BYTE
movlw LC01ADDR ;LOAD THE ADDRESS location
call Send_I2C_Byte ;send byte
call WaitMSSP ;wait for the i2c operation

banksel SSPCON2
btfsc SSPCON2,ACKSTAT ;check ACK status bit
goto I2CFail ;failed, skip if success

;Send and Check Data byte
movlw LC01ADDR ;SENDING 0011-0100
movwf FSR
movlw buff_size
movwf N

I2CWrite_1
movf INDF,W ;Load Data Byte
call Send_I2C_Byte ;Send Byte
call WaitMSSP ;Wait for I2C operation

banksel SSPCON2
btfsc SSPCON2,ACKSTAT ;check ACK Status bit
goto I2CFail ;failed, skip if successful

incf FSR,F
decfsz N,F
goto I2CWrite_1

;Send and Check the STOP condition
banksel SSPCON2
bsf SSPCON2,PEN
call WaitMSSP

Done1
movlw 0xAA ; 1010-1010
movwf PORTB
call DELAY_V_LONG
call DELAY_V_LONG

;The WRITE has now completed successfully

;*********************************************************
I2CRead
;Send Restart Condition and wait for it to complete
movlw 0x0F
movwf PORTB
call DELAY_V_LONG
call DELAY_V_LONG
clrf PORTB
;ACK
banksel SSPCON2
bsf SSPCON2,RSEN
call WaitMSSP

;Send and Check CONTROL BYTE
movlw LC01CTRLIN
call Send_I2C_Byte
call WaitMSSP

;Now check to see if I2C EEPROM is ready
;ACK
banksel SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2CRead

;Send and Check ADDRESS BYTE
movlw LC01ADDR
call Send_I2C_Byte
call WaitMSSP
;ACK
banksel SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2CFail

;Send REPEATED START condition and wait for it to complete
bsf SSPCON2,RSEN
call WaitMSSP

;Send and Check Control BYTE (OUT)
movlw LC01CTRLOUT
call Send_I2C_Byte
call WaitMSSP
;ACK
banksel SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2CFail

;Switch MSSP module to I2C Receive MODE

I2CRead_1

movlw LC01ADDR ;@12h
movwf FSR ;fsr= 12H
movlw buff_size ;.4
movwf N ; N =.4

i2cread_1a
bsf SSPCON2,RCEN ;IN RECEIVE MODE, WHERE DATA IS STORED AT SSPBUF
call WaitMSSP
banksel SSPBUF
movf SSPBUF,W
movwf PORTB
call DELAY_V_LONG

incf FSR,F
decfsz N,F
goto I2CRead_2
I2CRead_2
;ACK
banksel SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2CFail
CLRF PORTB

goto I2CRead_1

;Send NACK but for Acknowledge Sequence
banksel SSPCON2
bsf SSPCON2,ACKDT
bsf SSPCON2,ACKEN
;once ACK or NACK is sent, ACKEN is automatically cleared

;Send and Check the STOP condition and wait for it
bsf SSPCON2,PEN
call WaitMSSP

;I2C Write and Read have both finished, value is on LEDs
banksel SSPBUF
movf SSPBUF,W
movwf PORTB
goto $

---------- Post added at 11:44 ---------- Previous post was at 11:34 ----------

Good-day [ckshivaram]

As you have suggested one of the Microchip links
with PDF FORMAT that teaches about I2C protocol,

I have edited, where the Red color
call Data_Seq refers to the transfer of the data
@12h = 34h
@13h = 44h
@14h = 55h

THEN WE COME TO THE
;sEND AND CHECK DATA byte,
where I intend to WRITE all three data bytes (34h,44h and 55h) into
the External EEPROM (12h,13h and 14h)

{this is done by the I2CWrite_1}

then the Blue area is on READING them.

Kindly advise.
cheers,
slurp
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top