I don't understand in programming how to read DS1307. MCU 8051
This is my understanding to read DS1307
Basic steps
Start condition
7 Bit slave address + Read operation
After sending the 8 bits (7 address +R/W) the master generate Acknowledge
Slave ACKs indicate it got the data and the master can continue
Master Send Register address
After sending the register address master generate Acknowledge
Slave ACKs indicate it got the data and the master can continue
Master Send Data
After sending Data master generate Acknowledge
Slave NAKs indicate it wants no more data.
Stop Condition
I need routines to generate Start, Re Start, Stop conditions, read I2C, write I2C, check ACK or NAK and generate ACK or NAK.
I understand Start, stop Restart, ACK, NAK routine
Now I am looking help to make two routines
I2CSend(unsigned char Data)
Read_DS1307(void)
How to make these two routines ?
This is my understanding to read DS1307
Basic steps
Start condition
7 Bit slave address + Read operation
After sending the 8 bits (7 address +R/W) the master generate Acknowledge
Slave ACKs indicate it got the data and the master can continue
Master Send Register address
After sending the register address master generate Acknowledge
Slave ACKs indicate it got the data and the master can continue
Master Send Data
After sending Data master generate Acknowledge
Slave NAKs indicate it wants no more data.
Stop Condition
I need routines to generate Start, Re Start, Stop conditions, read I2C, write I2C, check ACK or NAK and generate ACK or NAK.
I understand Start, stop Restart, ACK, NAK routine
C:
#define SDA P0_0
#define SCL P0_1
void I2CInit()
{
SDA = 1;
SCL = 1;
}
void I2CStart()
{
SDA = 0;
SCL = 0;
}
void I2CRestart()
{
SDA = 1;
SCL = 1;
SDA = 0;
SCL = 0;
}
void I2CStop()
{
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}
void I2CAck()
{
SDA = 0;
SCL = 1;
SCL = 0;
SDA = 1;
}
void I2CNak()
{
SDA = 1;
SCL = 1;
SCL = 0;
SDA = 1;
}
Now I am looking help to make two routines
I2CSend(unsigned char Data)
Read_DS1307(void)
How to make these two routines ?
Attachments
Last edited: