slurp
Newbie level 6

How to I2C for many data?
;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 $
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
;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 $
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