Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F887 and DS1307

Status
Not open for further replies.

vijaya_narayana

Full Member level 3
Joined
Jun 12, 2007
Messages
178
Helped
11
Reputation
22
Reaction score
1
Trophy points
1,298
Location
India
Activity points
2,182
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

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
 

This problem has been reported here in other discussions; You forgot to enable the CH bit at startup (by writing a Zero on it), a step necessary to make the clock start running. Indeed, you do not even have any init() routine for this RTC.
 

If it was running before, why he (or she?) should init it? It keep working from battery.
But anyway, topic is too popular to discus rather than google it.
 

If it was running before, why he (or she?) should init it? It keep working from battery.

In the above simulation environment (Proteus) it is not supposed to statically store the result of the last simulation, furthermore it was not indicated on initial post that worked before, so it would need to reset this bit every time each new simulation. Anyway, as you remarked, this is a very common question.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top