I am trying to learn basic programming of ds1307Your code is not correct... The write to the I2C bus is a specific sequence..
If you want to write to the device you have to:
setup a start condition ( if bus is ready )
write device address ( wait for ack )
write register address ( wait for ack )
write device data ( wait for ack )
send nack ( to stop device )
send stop ( to free bus )
If you want to read from the device you have to:
setup a start condition ( if bus is ready )
write device address ( wait for ack )
write register address ( wait for ack )
send re-start( wait for ack )
read device ( send ack if more data needed )
send nack ( to stop device )
send stop ( to free bus )
Without this the device won't respond....
setup a start condition ( if bus is ready )
Code:
void I2CStart()
{
SDA = 0;
SCL = 0;
}
Code:
void I2CStop()
{
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}
Code:
void I2CNak()
{
SDA = 1;
SCL = 1;
SCL = 0;
SDA = 1;