Between the PORTC.1 = 1 and the PORTC.1 = 0 lines it seems the code never returns because the LED on PORTC bit 1 stays on.
I am building a clock. It will work fine for several minutes then it will stop updating because the call to this routine never returns.
What might I be doing wrong?
NOTE: The PIC is still running because I have an interrupt routine that mutiplexes the 7SEGs and they continue to update the last read time.
If nothing else, at the very least, can someone tell me if there is anyway the I2C_Rd routine might get in a loop and not return? This is really bugging me because it works for several (up to 15-20) minutes before it hangs.
Thanks in advance for the help.
Code: Select all
sub function DS1307_GetDateTime(dim byref ts as DS1307_DateTime) as byte
dim temp as byte ' a temporary variable
'
result = DS1307_I2C_ERROR ' Set default error
if I2C_Start = 0 then ' Start and continue if ok
if I2C_Wr(%11010000) = 0 then ' Send chip address and WRITE
if I2C_Wr(0x00) = 0 then ' Send pointer address
I2C_Repeated_Start ' Send Repeated Start
PORTC.1 = 1
I2C_Wr(%11010001) ' Send chip address and READ
ts.Sec = I2C_Rd(1) ' Get seconds -- ACK
ts.Min = I2C_Rd(1) ' Get minutes -- ACK
ts.Hr = I2C_Rd(1) ' Get hours -- ACK
ts.DOW = I2C_Rd(1) ' Get day of week -- ACK
ts.Day = I2C_Rd(1) ' Get day -- ACK
ts.Mnth = I2C_Rd(1) ' Get month -- ACK
ts.Yr = I2C_Rd(0) ' Get year -- NAK
PORTC.1 = 0
result = DS1307_OK ' Set result to OK
end if '
end if '
I2C_Stop ' Stop
end if '
end sub '