- Hands-On Embedded Programming with C++17
- Maya Posch
- 406字
- 2021-08-20 10:20:48
Adding an RTC
One can cheaply get RTCs as a ready-to-use module, often based around the DS1307 chip. This is a 5V module, which connects to the SBC (or MCU) via the I2C bus:

This image is of a small DS1307-based RTC module. As one can see, it has the RTC chip, a crystal, and an MCU. The last of these is used to communicate with the host system, regardless of whether it is an SoC or MCU-based board. All that one requires is the ability to provide the desired voltage (and current) the RTC module operates on, along with an I2C bus.
After connecting the RTC module to the SBC board, the next goal is to have the OS also use it. For this, we must make sure that the I2C kernel module is loaded so that we can use I2C devices.
Linux distributions for SBCs, such as Raspbian and Armbian, usually come with drivers for a number of RTC modules. This allows us to relatively quickly set up the RTC module and integrate it with the OS. With the module we looked at earlier, we require the I2C and DS1307 kernel modules. For a Raspbian OS on a first-generation Raspberry Pi SBC, these modules would be called i2c-dev, 2cbcm2708, and rtc-ds1307.
First, you have to enable these modules so that they are loaded when the system starts. For Raspbian Linux, one can edit the /etc/modules file to do so, as well as other configuration tools made available for this platform. After a reboot, we should be able to detect the RTC device on the I2C bus using an I2C scanner tool.
With the RTC device working, we can remove the fake-hwclock package on Raspbian. This is a simple module that fakes an RTC, but merely stores the current time in a file before the system is shut down so that on the next boot the filesystem dates and similar will be consistent due to resuming from that stored date and time, without any new files one creates suddenly being older than the existing files.
Instead, we'll be using the hwclock utility, which will use any real RTC to synchronize the system time with. This requires one to modify the way the OS starts, with the location of the RTC module passed as boot parameters in the following form:
rtc.i2c=ds1307,1,0x68
This will initialize an RTC (/dev/rtc0) device on the I2C bus, with address 0x68.
- 24小時學會電腦組裝與維護
- 筆記本電腦使用、維護與故障排除實戰
- Intel FPGA/CPLD設計(基礎篇)
- 微軟互聯網信息服務(IIS)最佳實踐 (微軟技術開發者叢書)
- Practical Machine Learning with R
- 固態存儲:原理、架構與數據安全
- Arduino BLINK Blueprints
- Python Machine Learning Blueprints
- FL Studio Cookbook
- 電腦橫機使用與維修
- 觸摸屏應用技術從入門到精通
- The Reinforcement Learning Workshop
- 從企業級開發到云原生微服務:Spring Boot實戰
- Learning Microsoft Cognitive Services
- FPGA進階開發與實踐