EP-0059: Difference between revisions
Line 74: | Line 74: | ||
---- | ---- | ||
==How to configure in terminal== | ==How to configure in terminal== | ||
===Using Overlays=== | |||
* Overlays are loaded using the "dtoverlay" config.txt setting. | |||
As an example,consider I2C Real Time Clock drivers. In the pre-DT world these would be loaded | |||
by writing a magic string comprising a device identifier and an I2C address to | |||
a special file in /sys/class/i2c-adapter, having first loaded the driver for | |||
the I2C interface and the RTC device - something like this: | |||
<pre> | |||
modprobe i2c-bcm2835 | |||
modprobe rtc-ds1307 | |||
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device | |||
</pre> | |||
With DT enabled, this becomes a line in config.txt: | |||
<pre> | |||
dtoverlay=i2c-rtc,ds1307 | |||
</pre> | |||
This causes the file /boot/overlays/i2c-rtc.dtbo to be loaded and a "node" | |||
describing the DS1307 I2C device to be added to the Device Tree for the Pi. By | |||
default it usees address 0x68, but this can be modified with an additional DT | |||
parameter: | |||
<pre> | |||
dtoverlay=i2c-rtc,ds1307,addr=0x68 | |||
</pre> | |||
Parameters usually have default values, although certain parameters are | |||
mandatory. See the list of overlays below for a description of the parameters | |||
and their defaults. | |||
===For Raspberry Pi 4B === | ===For Raspberry Pi 4B === | ||
Here we assume that you have already burned the Raspbian Image into TF card and connect to your PC and logged in. | Here we assume that you have already burned the Raspbian Image into TF card and connect to your PC and logged in. | ||
Line 84: | Line 109: | ||
please ensure that /boot/config.txt file include two paramaters: | please ensure that /boot/config.txt file include two paramaters: | ||
<pre> | <pre> | ||
dtoverlay=i2c-rtc,ds1307 | dtoverlay=i2c-rtc,ds1307 | ||
dtparam=i2c_arm=on | dtparam=i2c_arm=on | ||
</pre> | </pre> |
Revision as of 15:42, 28 February 2020
DS1307 RTC Module with BAT for Raspberry Pi
Description
The RTC module is specifically designed for Raspberry Pi. It communicated with Raspberry Pi through I2C bus. There is a Maxim DS1307 and CR1220 button cell on the board to keep the real time for a long time after the Raspberry Pi has it’s power off. In order to offering a convenient way to debug, there are five pin has been setup which are 5v, 3.3v, Rxd,Txd on board.
Compatibility List
- Compatibility
Platform | DS1307 RTC Module | Notes |
---|---|---|
Raspberry Pi 4 Model B | √ | |
Raspberry Pi 3 Model B Plus | √ | |
Raspberry Pi zero | √ | |
Raspberry Pi zero W | √ | |
Raspberry Pi 3 Model B | √ | |
Raspberry Pi 2 Model B | √ | |
Raspberry Pi Model B+ | √ |
Feature
- Use Maxim DS1307 chip
- Extends CR1220 button cell backup
- Can be operated with shell command
- Include a serial port connector
- Programmable square-wave output signal
- Consumes Less than 500nA in Battery-Backup Mode
- Automatic Power-Fail Detect and Switch Circuitry
- Programmable Square-Wave Output Signal
Parameters:
- Accuracy ±20ppm from 0°C to +40°C
- Work voltage 5V
- Battery Backup Input for Continuous Time keeping
- Real-Time Clock Counts Seconds, Minutes, Hours, Day, Date, Month, and Year with Leap Year Compensation Valid Up to 2100
- Work temperature 0°C to +70°C
- Ports:
- Raspberry Pi A+/B+/2 module 2X13 connection port
- Raspberry Pi 3, Mode B, 1GB RAM 2x20 connection port
- 2*5pin 2.54mm connector
Packages
- 1 x RTC Module
- 1x CR1220 Battery
Document
- Mechanical Drawing:
How to Connect:
- 1.Software Requirement:Base Raspbian Operating System
- 2. Connection: Just insert the module into Raspberry Pi
- 3. USB-to-TTL cable wire connect to RTC
- 4. Finally
Note: RTC 5v pin connect to USB-to-TTL Red wire(5v) RTC GND pin connect to USB-to-TTL black wire(GND) RTC TX pin connect to USB-to-TTL Green wire(TX) RTC RX pin connect to USB-to-TTL white wire(RX)
How to configure in terminal
Using Overlays
- Overlays are loaded using the "dtoverlay" config.txt setting.
As an example,consider I2C Real Time Clock drivers. In the pre-DT world these would be loaded by writing a magic string comprising a device identifier and an I2C address to a special file in /sys/class/i2c-adapter, having first loaded the driver for the I2C interface and the RTC device - something like this:
modprobe i2c-bcm2835 modprobe rtc-ds1307 echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
With DT enabled, this becomes a line in config.txt:
dtoverlay=i2c-rtc,ds1307
This causes the file /boot/overlays/i2c-rtc.dtbo to be loaded and a "node" describing the DS1307 I2C device to be added to the Device Tree for the Pi. By default it usees address 0x68, but this can be modified with an additional DT parameter:
dtoverlay=i2c-rtc,ds1307,addr=0x68
Parameters usually have default values, although certain parameters are mandatory. See the list of overlays below for a description of the parameters and their defaults.
For Raspberry Pi 4B
Here we assume that you have already burned the Raspbian Image into TF card and connect to your PC and logged in. Open a terminal and modify /boot/config.txt file using what you favorate editor such as vim.tiny or nano, add parameters as following picture:
You can read /boot/overlay/README and find this info to add support for ds1307 I2C Real Time Clock device.
please ensure that /boot/config.txt file include two paramaters:
dtoverlay=i2c-rtc,ds1307 dtparam=i2c_arm=on
After that, please make sure you have disabled the "fake hwclock" which interferes with the 'real' hwclock
sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove
Now with the fake-hw clock off, you can start the original 'hardware clock' script.
Edit the script file /lib/udev/hwclock-set with nano or vim editor and comment out these three lines:
if [ -e /run/systemd/system ] ; then exit 0 fi
Finally result like this:
save and reboot your RPi.
For Raspberry Pi 3B
Here we assume that you have already burned the Raspbian Image into TF card and connect to your PC and logged in. Open a terminal and modify /boot/config.txt file using what you favorate editor such as vim.tiny or nano, add parameters as following picture:
You can read /boot/overlay/README and find this info to add support for ds1307 I2C Real Time Clock device.
Name: i2c-rtc Info: Adds support for a number of I2C Real Time Clock devices Load: dtoverlay=i2c-rtc,<param>=<val> Params: ds1307 Select the DS1307 device
please ensure that /boot/config.txt file include those three paramaters:
device_tree=bcm2710-rpi-3-b.dtb dtoverlay=i2c-rtc,ds1307 dtparam=i2c_arm=on
After that, please make sure you have disabled the "fake hwclock" which interferes with the 'real' hwclock
sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove
Now with the fake-hw clock off, you can start the original 'hardware clock' script.
Edit the script file /lib/udev/hwclock-set with nano or vim editor and comment out these three lines:
if [ -e /run/systemd/system ] ; then exit 0 fi
Finally result like this:
save and reboot your RPi.
How to Check it
After reboot and log in, open a terminal and typing this command to check if RTC module is functional.
dmesg |grep rtc
if you can see this picture means that your RTC module is working properly.
and then you can adjust your system clock as following command:
Note: 051014302016.20 is equal to mmDDHHMMYYYY.ss, more information please using ‘man date’ command. Last step, set the Hardware Clock to the current System Time.
ok, finished. Have fun.
FAQ
- Question: Why does my RTC module running a wrong time when i reboot my Pi ?
- Answer: Please do remember to disable the "fake hwclock" which interferes with the 'real' hwclock as following commands:
- Answer: Please do remember to disable the "fake hwclock" which interferes with the 'real' hwclock as following commands:
sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove