DS1307:
Read routine. |
|
The
DS1307 datasheet is quite confusing because
the read routine seems not to be the same as with an i²c EEPROM. However, it is, basically. So when reading from the DS1307 (=Slave) and seen by the
PIC's point of view (=Master), we have to: 1) Send a START, write the device address (0xd0) (last bit is 0 for write), wait for ACK. 2) Write the word address (sets the first register to read from, which is 0x00 here), wait for ACK. 3) Send a REPEATED START, write the device address again (0xd1) (last bit is 1 for read), wait for ACK. 4) Read the first byte, wait for ACK. 5) Repeat step 4) for next bytes. 6) Read the last byte, no wait for ACK, send STOP.
We have to repeat this whole cycle each time we start reading the DS1307 registers, otherwise they will be incremented automatically, and not set to zero. Also see the EEPROM 24C256 datasheet, and figure 8-2, Random Read. Only difference is we have to omit the "address low byte" part for the DS1307. |
Hi-Tech PICC: void rtc_read(unsigned char *rtc_buffer) SEN = 1;
//
1) send
start bit START // 5) RCEN = 1;
//
6) start
receiving READ LAST & NO ACK buffer 7 |