Hi everyone!
I've got a Chronodot v2.1 hooked up to my Raspberry Pi.
The hardware clock itself is working well, but I'm wanting to configure the SQW pin to 1Hz, in the hopes of using it as a Pulse Per Second discipline for my NTP clock.
Does anyone have any docs, advice or sample code whether it will work like this, and how to do it?
Thanks in advance!
Setting the Chronodot SQW frequency
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Setting the Chronodot SQW frequency
The frequency of the SQW output is controlled by the RS1 and RS2 bits of Control Register 0x0E. See page 13 of the datasheet:
http://datasheets.maximintegrated.com/en/ds/DS3231.pdf
http://datasheets.maximintegrated.com/en/ds/DS3231.pdf
- enigmait
- Posts: 6
- Joined: Wed Aug 06, 2014 5:13 pm
Re: Setting the Chronodot SQW frequency
Thanks Rick.
So, would using the ReadU8 and WriteU8 functions in the Adafruit_I2C.py library be the best way to set these?
So, would using the ReadU8 and WriteU8 functions in the Adafruit_I2C.py library be the best way to set these?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Setting the Chronodot SQW frequency
Yes. You would read the register with ReadU8, set the bits, and then write the register back with WriteU8
- enigmait
- Posts: 6
- Joined: Wed Aug 06, 2014 5:13 pm
Re: Setting the Chronodot SQW frequency
For anyone else looking for the solution to this, the code I use is:
-----------------------
#!/usr/bin/python
import RPi.GPIO as GPIO # import RPi.GPIO module
from Adafruit_I2C import Adafruit_I2C
# choose BOARD or BCM
GPIO.setmode(GPIO.BCM) # BCM for GPIO numbering
# Set up Inputs
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input with pull-up
# Configure ChronoDot SQW
chronodot = Adafruit_I2C(0x68)
chronodot.write8(0x0E,192)
-----------------------
The python script needs to be run at boot up in rc.local, BEFORE creating the I2C device. I'm using GPIO pin 4, which is why the "4" is there on the GPIO.setup line
After that's run, you can use the rpi_gpio_ntp program (once you've built it) to create a user mode SHM driver for ntp. I'll post a link to my blog once I've finished writing it. :)
-----------------------
#!/usr/bin/python
import RPi.GPIO as GPIO # import RPi.GPIO module
from Adafruit_I2C import Adafruit_I2C
# choose BOARD or BCM
GPIO.setmode(GPIO.BCM) # BCM for GPIO numbering
# Set up Inputs
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input with pull-up
# Configure ChronoDot SQW
chronodot = Adafruit_I2C(0x68)
chronodot.write8(0x0E,192)
-----------------------
The python script needs to be run at boot up in rc.local, BEFORE creating the I2C device. I'm using GPIO pin 4, which is why the "4" is there on the GPIO.setup line
After that's run, you can use the rpi_gpio_ntp program (once you've built it) to create a user mode SHM driver for ntp. I'll post a link to my blog once I've finished writing it. :)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Setting the Chronodot SQW frequency
Nice - thanks for posting that!
Please be positive and constructive with your questions and comments.