Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
void I2Cwrite(){
/* Initialize I2C Port */
I2CStart(); /* Send Start condition */
I2CSend(0xD0); /* Send DS1307 slave address */
I2CSend(0x00);
for(i=0;i<8;i++) { /* Loop to write 8 bytes */
I2CSend(I2CInitval[i]);
}
I2CStop();
}
I2Cstart();
I2CSend(0xD1);
I2CAck();
I2CData[0]=I2CRead();
I2CNak();
I2CStop();
if (!(I2CData[0] & (1<<7)))..... // true if bit7 is 0
void I2Cread(){
for(i=0;i<8;i++){
I2CStart();
I2CSend(0xD0);
I2CSend(i);
I2CRestart();
I2CSend(0xD1);
I2CData[i] = I2CRead(); /* read a byte */
/* ACK if its not the last byte to read */
}
I2CStop(); /* Send stop */
}
I2CStart();
I2CSend(0xD1);
I2CAck();
I2CSend(0);
for(i=0; i<8; i++) {
I2CAck();
I2CData[i]=I2CRead();
}
I2CNak();
I2CStop(); /* Send stop */
I2CStart();
I2CSend(0xD0); // write mode
I2CAck();
I2CSend(0); // set address pointer to 0
I2CRestart();
I2CSend(0xD1); // read mode
for(i=0; i<8; i++) { // read the registers
I2CAck();
I2CData[i]=I2CRead();
}
I2CNak();
I2CStop(); /* Send stop */
sec=rtc_get(0); //get sec
min=rtc_get(1); //get min
hrs=rtc_get(2); //get hours
day=rtc_get(3); //get day
date=rtc_get(4); //get date
month=rtc_get(5); //get month
year=rtc_get(6); //get year
Dear alex,
Thanks for reply
Actually I set the address pointer (I2CSend(0)); but it is reading 0 location only which is second and if I set address pointer as (I2CSend (1) Then It is reading only location 1 which is minute. Therefore I put all read loop under for loop and address pointer changed as I2CSend(i); i is for loop variable then it is working fine
I2CStart();
I2CSend(0xD0); // write mode
I2CAck();
I2CSend(0); // set address pointer to 0
I2CRestart();
I2CSend(0xD1); // read mode
for(i=0; i<8; i++) { // read the registers
I2CAck();
I2CData[i]=I2CRead();
}
I2CNak();
I2CStop(); /* Send stop */
Dear alex,
The values from I2CData [1] to I2Cdata [7] ?? ?? but only I2CData[0] = seconds and and update nicely
Dear alex as per your example code in the post number 32, it does not increment address pointer by codes and it is increasing address pointer automatically in side the DS1307 as per codes
any helps
tw_start();
tw_write_data(0xd0);
tw_write_data(0);
tw_start();
tw_write_data(0xd1);
*sec=bcd2bin(tw_read(1));
*min=bcd2bin(tw_read(1));
*hour=bcd2bin(tw_read(0));
tw_stop();
I2CStart();
I2CSend(0xD0); // write mode
I2CAck();
I2CSend(0); // set address pointer to 0
[COLOR="#FF0000"]I2CStart(); // use start instead of restart[/COLOR]
I2CSend(0xD1); // read mode
for(i=0; i<8; i++) { // read the registers
I2CAck();
I2CData[i]=I2CRead();
}
I2CNak();
I2CStop(); /* Send stop */
Dear All
step3: Hour digit is incrementing But it dose not rest to 0
void I2Cwrite(){
I2CStart();
I2CSend(0xD0);
I2CSend(0x00);
for(i=0;i<8;i++) {
I2CSend(I2CInitval[i]);
}
I2CStop();
}
The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or
24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with
logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours). The hours value must be
re-entered whenever the 12/24-hour mode bit is changed.
void I2Cinitval(){
I2CStart();
I2CSend(0xD0);
I2CSend(0x02);
I2CSend(0x40);
I2CStop();
}