Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

RTC DS1307 crystal pins

Status
Not open for further replies.

skmdmasud

Member
Hi.
This is from the datasheet
Code:
Connections for Standard 32.768kHz Quartz Crystal. The internal oscillator circuitry is 
designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF. 
X1 is the input to the oscillator and can optionally be connected to an external 32.768kHz oscillator. 
The output of the internal oscillator, X2, is floated if an external oscillator is connected to X1.
X1 and X2 are the two pins where we connect a crystal.

1. If i connect 1 leg of crystal in X1 only & leave the other leg disconnected then will my RTC start to give accurate time.
2. X2 becomes floated so what happens if i ground it. As i remember we dont want to keep pins in floating state.

i am asking this because I am receiving some noise in my RTC most probable from the crystal side.

Regards...:)
 
hi,

The X2 pin should only be left disconnected IF you are using an external 38KHz source to drive X1, else the 38KHz crystal should be across X1 and X2.

How is the DS1307 connected to the PIC pins.??
 

Attachments

  • AAesp01.gif
    AAesp01.gif
    4.3 KB · Views: 277
hi,

The X2 pin should only be left disconnected IF you are using an external 38KHz source to drive X1, else the 38KHz crystal should be across X1 and X2.

How is the DS1307 connected to the PIC pins.??

I see the external source means not a crystal.

The RTC is connected with Atmega8 using I2C bus. I have grounded the crystal but still i get some noise and times to time it gets all wacky specially when my relays tick tack.

My grounding the crystal may not be that good i will check it again. Other that that if i disconnect he RTC my uC works smooth no matter how many time i turn on off the relays.
 
I see the external source means not a crystal.

The RTC is connected with Atmega8 using I2C bus. I have grounded the crystal but still i get some noise and my times gets all wacky time to time specially when my relays tick tack.

hi,
Do you have the pull up resistor on the DS1307 SCA and SCL pins.?

Also is your MCU well decoupled on the power lines.?
 
hi,
Do you have the pull up resistor on the DS1307 SCA and SCL pins.?

Also is your MCU well decoupled on the power lines.?
Yes i have 4k7 in the both SCA SLC.

Did not connected a decouple capacitor forgot about it. I will put a 0.1uf across the power pins of RTC.
 
Last edited:
hello all
How do I enable the internal oscillator ds1307?
//Initialize I2C Bus
I2CInit();
//Clear CH bit of RTC
DS1307Read(0x00,&temp2);
//When this bit is set to 1, the oscillator is disabled. When cleared to 0, the oscillator is enabled.
//Clear CH Bit to 0 to enable the rtc oscillator
temp2&=(~(1<<CH)); //turns the rtc on
DS1307Write(0x00,temp2);

//Set 24 Hour Mode
DS1307Read(0x02,&temp2);
temp2&=~(0b01000000); // set bit 6 to 0 for 24 hr mode
//Set 24Hour BIT
//Write Back to DS1307
DS1307Write(0x02,temp2);


this is the code for the I2C library i am using.

just a note---They are very reliable i have been using 3 chips in my different aquariums for over 1 year without any issue. although there is some time drifts due to temperature i guess.
 
Last edited:
thanks
I managed to activate the internal oscillator, but when I ordered the activation of
It will be zero, then the second!
I'm going to activate the internal oscillator zero bit ch.
It is true?
 
thanks
I managed to activate the internal oscillator, but when I ordered the activation of
It will be zero, then the second!
I'm going to activate the internal oscillator zero bit ch.
It is true?

I dont understand what you are trying to say. Can you please explain it again.

share you code as well
 
i'm sorry !!
I am from Iran and i speak persian.
Sorry if I can not rightly tell you my wishes.
In fact, I want this piece to start the internal oscillator.
I have a problem.
 
I am using BASCOM-AVR.
My problem is that enabling this bit causes the value of seconds is zero.
Therefore to enable the oscillator is forced to change the amount of seconds.
 
If the oscillator isn't running and you read the seconds register... Then write back the same value but changing the ch bit, you wont affect the seconds.... Similarly you could only drop half a second if the oscillator is running and you want to stop it...

Are you using the DS1307 as a timer?
 
Then I don't understand your problem....

When a DS1307 is first initialised, we send the time to it... Once this is done we then can read back the real time whenever we need... There is no need to stop / start the oscillator...

Set up a time array Sec, Min, Hour, Day, Date, Mon,Year..... And just write the whole array to and from the chip..
You will also need a binary ~ BCD routine and the BCD ~ binary routine as the DS1307 stores the information in BCD format!
C:
void bcdBin(char* array)
    {
    char x;
    unsigned char tmp;
    for(x=0;x<8;x++)
        {
        tmp = *array  >> 4;
        tmp *= 10;
        tmp = tmp + (*array & 0xf);
        *array++ = tmp;
        }
    }

void binBcd(char* array)
    {
    char x;
    unsigned char tmp;
    for(x=0;x<8;x++)
        {
        tmp = *array  / 10;
        tmp = tmp << 4;
        tmp = tmp + (*array % 10);
        *array++ = tmp;
        }
    }

void WriteClock(char *array)
    {
    char x;
    for(x=0;x<8;x++)
        WriteRTC(x,array[x]);  
    }  

void ReadClock(char *array)
    {
    char x;
    for(x=0;x<8;x++)
        array[x] = ReadRTC(x);  
    }

From this you should get the idea!!!
 
I guess his problem is that the Second remains in ZERO, so he think that his oscillator is disabled.
What speed crystal do you have on pin 1 and 2... You need to use a 32khz one... you also need a 3v battery across pins 3 and 4... Have you a scope to check the crystal is running???
I guess his problem is that the Second remains in ZERO, so he think that his oscillator is disabled.
I think he got it fixed after you told him to use a 32khz crystal and a battery.

Just wondering what happens if we connect a 1Mhz crystal to DS1307??will it fly ??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top