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.

DS1307 rtc not working

Status
Not open for further replies.

MUKESH.K.S

Full Member level 1
Full Member level 1
Joined
Jan 31, 2014
Messages
98
Helped
14
Reputation
28
Reaction score
13
Trophy points
1,288
Location
KERALA
Visit site
Activity points
1,891
I completed a project based on ds1307 and pic16f877a. It works very well in proteus but its not working in hardware. I have tried many times with changing pull up res value ,connecting vbat to gnd etc but it still not working ....here is my pgm



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 11059000
#endif
__CONFIG(FOSC_HS & WDTE_OFF& PWRTE_OFF & BOREN_OFF &
LVP_OFF & WRT_OFF & DEBUG_OFF & CPD_OFF & CP_OFF);
void I2CMASTER(void);
void I2CSTART(void);
void I2CSTOP(void);
void I2CREPSTART(void);
int I2CTRANSMIT(unsigned char temp5);
unsigned char I2CRECEIVE( int);
void main()
{
TRISD7=1;
OPTION_REG=0X38;    //TIMER CONFIG
PSA=1;
TRISB=0XFF;
TRISD=0X00;
PORTB=0XFF;
TMR0=0X00;
TRISB=0X00;
I2CMASTER();
__delay_ms(1000);
while(1)
{
if(RB7==0)
{
while(RB7==0);
I2CSTART();
I2CTRANSMIT(0XD0);
I2CTRANSMIT(0X00);
I2CTRANSMIT(0X00);
I2CSTOP();
I2CSTART();
I2CTRANSMIT(0XD0);
I2CTRANSMIT(0X07);
I2CTRANSMIT(0X10);
I2CSTOP();
}
 
 
}
}
 
 
 
 
 
void I2CMASTER(void)
{
SSPADD=0Xff;
WCOL=0;
CKP=1;
SSPM3=1;
SSPM2=0;
SSPM1=1;
SSPM0=1;
SSPEN=1;
TRISC=0X00;
TRISC4=1;
TRISC3=1;
}
 
void I2CSTART(void)
{
SEN=1;
while(SEN==1);
}
void I2CSTOP(void)
{
PEN=1;
while(PEN==1);
}
void I2CREPSTART(void)
{
RSEN=1;
while(RSEN==1);
}
 
 int I2CTRANSMIT(unsigned char temp5)
{
ACKSTAT=0;
SSPBUF=temp5;
while(R_W==1);
return(ACKSTAT);
}

 
Last edited by a moderator:

hello,


Do you have pull up resitor on SCL and SDA lines ? (2,7K is a usual value)

How do you set the I2C bus speed ?
SSPADD=0xFF seems a strange value..

Strange value also for the quartz 11.059 MHz ?<br>
in this case SSPADD must be around value 27 not 255 ..for 100Khz I2C bus speed
 
Last edited:
How about PORTC Configuration

Why don't you post whole codes with proteus
 
You need to un-tick the sync pc clock function to see if it's working correctly, only it will use the PC clock to tick
 

Is the ds1307 only woks on 100khz?
I choose sspadd=oxff for reducing the bus speed to minimum. I thought that 100khz is the ds1307's max speed.
I usually uses 11.059MHz quarts crystal in all my projects & its works well.
I have used many values of pull up resister like 1.8k,2.2k,10k etc but its not working...
can you suggest a best choice for crystal , i2c speed, pull up etc.
 

Is the ds1307 only woks on 100khz?
I choose sspadd=oxff for reducing the bus speed to minimum. I thought that 100khz is the ds1307's max speed.
I usually uses 11.059MHz quarts crystal in all my projects & its works well.
I have used many values of pull up resister like 1.8k,2.2k,10k etc but its not working...
can you suggest a best choice for crystal , i2c speed, pull up etc.


i2c speed.JPG

post you project folder for more help
read page 99 of pic16f877a data sheet
 

Attachments

  • i2c.pdf
    658.2 KB · Views: 82
hello,


The DS1307 operates in the regular mode (100kHz) only.

Is your 32Khz quartz compliant with Crystal Specified Load Capacitance = 12,5pF
if you valid the SQWE bit in the DS1307 init ,
CTRL register at adress 7 = 0x10

SQWE (Square Wave Enable): This bit, when set to a logic 1, will enable the oscillator output. The
frequency of the square wave output depends upon the value of the RS0 and RS1 bits. With the square
wave output set to 1Hz, the clock registers update on the falling edge of the square wave.

you must get 1hz output on pin SQWE if init is OK
Without getting 1Hz , go not further..PB is in init of DS1307..
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
here is my project folder

This is your whole codes but you said that in your first post it is working well with Proteus
How do you say it using this code
How do you display the result LCD or SSD?
I think this is incomplete

Code:
#include <htc.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000
#endif
__CONFIG(FOSC_HS & WDTE_OFF& PWRTE_OFF & BOREN_OFF &
LVP_OFF & WRT_OFF & DEBUG_OFF & CPD_OFF & CP_OFF);
void I2CMASTER(void);
void I2CSTART(void);
void I2CSTOP(void);
void I2CREPSTART(void);
int I2CTRANSMIT(unsigned char temp5);
unsigned char I2CRECEIVE( int);
void main()
{
TRISB=0xff;
TRISB6=0;
OPTION_REG=0X38;    //TIMER CONFIG
PSA=1;
TMR0=0X00;
I2CMASTER();
__delay_ms(1000);
while(1)
{
if(RB7==0)
{
while(RB7==0);
here:
I2CSTART();
if((I2CTRANSMIT(0XD0)))
{
goto here;
}
while(I2CTRANSMIT(0X00));
while(I2CTRANSMIT(0X00));
I2CSTOP();
I2CSTART();
while(I2CTRANSMIT(0XD0));
while(I2CTRANSMIT(0X07));
while(I2CTRANSMIT(0X10));
I2CSTOP();
}

RB6=~RB6;
__delay_ms(1000);


}
}



void I2CMASTER(void)
{
TRISC4=1;
TRISC3=1;
SSPADD=0X31;
WCOL=0;
CKP=1;
SMP=0;
CKE=0;
SSPM3=1;
SSPM2=0;
SSPM1=1;
SSPM0=1;
SSPEN=1;

}

void I2CSTART(void)
{
SEN=1;
while(SEN==1);
}
void I2CSTOP(void)
{
PEN=1;
while(PEN==1);
}
void I2CREPSTART(void)
{
RSEN=1;
while(RSEN==1);
}

 int I2CTRANSMIT(unsigned char temp5)
{
ACKSTAT=0;
SSPBUF=temp5;
while(R_W==1);
return(ACKSTAT);
}

This way we can not help you

Try on this link
https://www.edaboard.com/threads/257054/
 
Last edited:
  • Like
Reactions: MUKESH.K.S

    V

    Points: 2
    Helpful Answer Positive Rating

    MUKESH.K.S

    Points: 2
    Helpful Answer Positive Rating
Thanks a lot . You saved my life !!!!!!!
It worked when i changed SSPSTAT to 0x80 and SSPCON to 0x28 as in your pgm.
The code i have posted above was only to test the square wave o/p of rtc . My actual project is digital clock/calender and its all complete ,the only problem was about the rtc
but rtc is now working ...THANK U VERY MUCH
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top