vijaya_narayana
Full Member level 3
Dear All
Here with i am attaching the read sequence for DS1307 currently i am trying to read DS1307 but the DS1307 is responding with only 00
i am working on simulation
pls let me know what is wrong in this code i am running a Proteus simulation for the same
Here with i am attaching the read sequence for DS1307 currently i am trying to read DS1307 but the DS1307 is responding with only 00
i am working on simulation
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //////////reading DS1307 for a specific address unsigned char DS1307_read(unsigned char address) { unsigned char ch; I2CStart(); /* Send a start condition */ I2CSend(0XD0); /* Send slave address with write */ I2CSend(address); /* this address is actually where we are going to read from */ I2CRestart(); /* Send a repeated start, after a dummy write to start reading */ I2CSend(0xD1); /* send slave address with read bit set */ ch = I2CRead(); // Read Data from DS1307 I2CNak(); // No Acknowledge I2CStop(); // Raise Stop condition in I2C bus return ch; // Return Read value } /*************** To send Data in I2C Bus ********************/ void I2CSend(unsigned char dat) { SSPBUF = dat; /* Move data to SSPBUF */ while(BF); /* wait till complete data is sent from buffer */ I2CWait(); /* wait for any pending transfer */ } /////////////To read Data from I2C Bus unsigned char I2CRead(void) { unsigned char temp; RCEN = 1; /* Enable data reception */ while(!BF); /* wait for buffer full */ temp = SSPBUF; /* Read serial buffer and store in temp register */ I2CWait(); /* wait to check any pending transfer */ return temp; /* Return the read data from bus */ }
pls let me know what is wrong in this code i am running a Proteus simulation for the same