

I was recently finding an attempt to communicate between a master and slave PIC unsuccessful, and I had a DS1307 lying around, so I whipped up some code. You can read in a multibyte burst, sequentially, or a single byte and then send a STOP and start the process over again at a different register location. Looking at you code, I don't see anything glaringly wrong, but if we look at the DS1307 datasheet, page 13, it specifies that to do a data read from a specific location you write the address, the location in the DS1307 registers, then initiate a "Repeated Start" routine, send the address again, then read the data. This line simply is checking any bits that signify that the peripheral is busy, (such as an active start or stop condition, currently clocking out data, etc. The IdleI2C2() function is simply the following: while(I2C2CONbits.SEN || I2C2CONbits.PEN || I2C2CONbits.RSEN || I2C2CONbits.RCEN || I2C2CONbits.ACKEN || I2C2STATbits.TRSTAT)

NotAckI2C2() // Master Aknodledge End of transfer MasterWriteI2C2(0圎1) // Send slave address with read bit MasterWriteI2C2(0圎0) // Send slave address with write bit An example is shown below: StartI2C2() // Send the Start Bit Using the Microchip PLIB legacy libraries for I2C, you need to manually poll for the bus to be idle after each operation.
#DS1307 CODEVISIONAVR CODE#
This code works: rtc_init(0,1,0) // output pin for debugging I worked this RTC with ATMega128 and CodeVisionAVR
