Hi everyone!
I’m trying to connect a pic16F877 with a DS1307 using I2C, but I’m getting some problems, and I can’t find what I’m doing wrong.
I’m using the next program.
DSaddress =0D0h
Pointeradd = 00h
BRG= 9h
In attachement is the circuit that I’m using to test the communication. Hope that is noting wrong with it.
I had make a simulation in Proteus and I can’t get any data from de DS1307.
The 1º memory address from DS1307 should be save to the DS_data register but instead I only get 00000000, even running the simulation for over then 1 min.
Did anyone can tell me what I’m doing wrong??
Tanks!!
I’m trying to connect a pic16F877 with a DS1307 using I2C, but I’m getting some problems, and I can’t find what I’m doing wrong.
I’m using the next program.
Init_I2C:
movlw b'00101000'
movwf SSPCON
call membank1
bsf PORTC,sda
bsf PORTC,scl ; asegura que as portas estam a input
bcf SSPSTAT,7 ;Enabled slew rate
clrf SSPCON2
movlw BRG
movwf SSPADD ; Configura 100khz I2C clock a 4Mhz
call membank0
return
StartI2C:
call membank1
bsf SSPCON2,0
btfsc SSPCON2,0
goto $-1
call membank0
return
StopI2C:
call membank1
bsf SSPCON2,2
btfsc SSPCON2,2
goto $-1
call membank0
return
RestartI2C:
call membank1
bsf SSPCON2,1
btfsc SSPCON2,1
goto $-1
call membank0
return
Txbyte:
movwf SSPBUF
call membank1
bsf SSPCON2,6
btfsc SSPSTAT,2
goto $-1
btfsc SSPCON2,6
goto $-1
call membank0
return
Rxbyte:
;clrf SSPBUF
call membank1
bsf SSPCON2,3
btfsc SSPCON2,3
goto $-1
call membank0
movf SSPBUF,0
return
SetDSpointer:
call StartI2C
movlw DSaddress
call Txbyte
movf pointeradd,0
call Txbyte
call StopI2C
return
ACK:
call membank1
bcf SSPCON2,5
bsf SSPCON2,4
btfsc SSPCON2,4
goto $-1
call membank0
return
NACK:
call membank1
bsf SSPCON2,5
bsf SSPCON2,4
btfsc SSPCON2,4
goto $-1
call membank0
return
I2cinforead:
;call Wait_T1_1ms
call StartI2C
movlw DSaddress
call Txbyte
movf pointeradd,0
call Txbyte
call RestartI2C
movlw DSaddress+1
call Txbyte
call membank1
call Rxbyte
movwf DS_data
call NACK
call StopI2C
return
DSaddress =0D0h
Pointeradd = 00h
BRG= 9h
In attachement is the circuit that I’m using to test the communication. Hope that is noting wrong with it.
I had make a simulation in Proteus and I can’t get any data from de DS1307.
The 1º memory address from DS1307 should be save to the DS_data register but instead I only get 00000000, even running the simulation for over then 1 min.
Did anyone can tell me what I’m doing wrong??
Tanks!!