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.

DS3231 Init

Status
Not open for further replies.

Suraj143

Active Member
I'm doubt on "Enable Oscillator (EOSC\) Bit" in control register. The Datsheet also says the "Oscillator Stop Flag (OSF)" bit in status register.

1) What do I have to check on power up?

2) Is it ok to configure the control register on every power up?

3)Do I need to configure it everytime when I adjust my time?
 

Attachments

  • 3231.jpg
    3231.jpg
    336.1 KB · Views: 191
Just download the Arduino library, and see what that does - it's often far easier to 'borrow' bit's of code from Arduino libraries than write your own from scratch.
 
HI, are you looking the arduino code using your XC8 compiler? I mean to look what is inside in the library functions.
 
If the OSF is set when you powerup then something stopped the clock and the time can't be relied upon. If the flag is set then warn the user that the time is incorrect and the battery may need replacing.

Mike.
 
If the OSF is set when you powerup then something stopped the clock and the time can't be relied upon. If the flag is set then warn the user that the time is incorrect and the battery may need replacing.

Mike.
Good point.Just thinking no point of checking the OSF flag bits.Because the Control bit is automatically sets when battery is placed.So no point of reading it every time power up?
 
I'm not quite sure what you're saying. However, if the unit is powered down for a long time and the battery goes flat during this time then the OSF bit will be set and the time will be wrong. That is the purpose of this flag.

Mike.
 
I'm making clock to my room.circuit is powered from a power pack.and there is small power cuts in day today not longer power cuts.In this case I am wondering do I need to check status flags and control bits in the initialisation part?
 
If the OSF bit is set then your time is probably wrong and you need to reset it. The battery will probably last a couple of years with intermittent power cuts so when it's set you probably need to replace it.

Mike.
 
I wrote some code to read and write the registers in a DS3231 using a PIC12F1840 about 3 years ago. I did not bother to write anything to the config register and it worked keeping time. (I have just had a look at the code and confirmed that I did not write to the config register.) You may have to write to it when you first set the clock but even if the external power fails all the registers will retain their data as thy are powered from the lithium battery. (I have just checked the battery in the module which has not had any external power for about three years and it is still just over 3 volts.) The code I wrote is in assembler so it will probably be no help to you.

Les.
 
I wrote some code to read and write the registers in a DS3231 using a PIC12F1840 about 3 years ago. I did not bother to write anything to the config register and it worked keeping time. (I have just had a look at the code and confirmed that I did not write to the config register.) You may have to write to it when you first set the clock but even if the external power fails all the registers will retain their data as thy are powered from the lithium battery. (I have just checked the battery in the module which has not had any external power for about three years and it is still just over 3 volts.) The code I wrote is in assembler so it will probably be no help to you.

Les.
Good points.I am also an assembler.I like to see your coding if you like.
 
Hi,
This code was modified from some code I wrote to read INA219 voltage and current monitor chips. I use HC-12 RF modules to get data from various remote sensors. Each sensor has a unique ID This code had an ID of #F So to get a reading I just send the ID characters and that remote sensor sends back the data as text. In this code it skips past looking for the "F" character so just sending an "#" character sends all the time and date information. The code starts by setting the DS3231 to a fixed time and date. Which you will see at the start of the code. so from then on you just send the # character to display the time. You can just use a terminal emulator program such as Tera Term running on a PC.
The .asm file is just a text file so you should be able to read it using any text editor program.

Les.
 

Attachments

  • DS3231_driverr05.asm
    26.1 KB · Views: 185
It's not clear from the discussion if you have a backup battery. I use a CR2032 to keep the clock chip running in case of power failure. With the power off or even disconnected for an extended period (weeks or more), when power is applied, the correct time is displayed.

I've had less than a minute of drift in a year's time with the DS3231. As I recall, a CR2032 cell should keep the clock chip running for over 10 years.

It's awesome to have a clock where the time is correct when it's plugged in. I did not implement automatic daylight time adjustment since the dates to make the switches seems to be more variable these days, and there is much discussion of eliminating the twice-yearly change. A simple standard time / standard time switch makes the change easy.
 
Hi,
This code was modified from some code I wrote to read INA219 voltage and current monitor chips. I use HC-12 RF modules to get data from various remote sensors. Each sensor has a unique ID This code had an ID of #F So to get a reading I just send the ID characters and that remote sensor sends back the data as text. In this code it skips past looking for the "F" character so just sending an "#" character sends all the time and date information. The code starts by setting the DS3231 to a fixed time and date. Which you will see at the start of the code. so from then on you just send the # character to display the time. You can just use a terminal emulator program such as Tera Term running on a PC.
The .asm file is just a text file so you should be able to read it using any text editor program.

Les.
Many Thanks.It has wrtten to the hardware MSSP module (I2C Codes).I did from a software I2C Routines from nigels tutorials.Worked fine.
AFter reading the datasheet many many times I got to know that no need of writing to control register on Its very first power ON stage. Its initial values are ok for a normal run.
 
This is a nice little DS3231 modual and also has eeprom 24L32 . Vcc ( 3-5v ) led and pullups I usually check the OSF bit , and initialize if active.
ds3231.jpg
 
I've got a few of the DS1307 modules with the eeprom added. They also have a place for a DS OW chip. My latest LCD backpack works well with them.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top