Your 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....
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 )
ok I saw that tread , now I am trying to make some code myself
Code:
void I2C_Init() //
{
SDA = 1;
SCL = 1;
}
void I2C_Start() // start I2C
{
SDA = 0;
SCL = 0;
}
I2C_write() // send data to Ds1307
{
I2C_write(0xD0); // address of the DS1307 )
I2C_write(0x00); // address of seconds register
I2C_write(0x10); // 10 data as 10 second
}
void I2C_Ack()
{
SDA = 0;
SCL = 1;
SCL = 0;
SDA = 1;
void I2C_Stop() // stop I2C
{
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}
void I2C_Start()
{
SDA = 0;
SCL = 0;
}
I2C_read()
{
I2C_write(0xD1); // address of the DS1307 )
I2C_write(0x00); // address of seconds register
I2C_write(0x10); // 10 data as 10 second
}
void I2C_Nak()
{
SDA = 1;
SCL = 1;
SCL = 0;
SDA = 1;
}
void I2C_Stop() // stop I2C
{
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}