- 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.
- 觸摸屏實用技術與工程應用
- 辦公通信設備維修
- 計算機組裝·維護與故障排除
- 嵌入式系統設計教程
- Artificial Intelligence Business:How you can profit from AI
- 分布式系統與一致性
- 計算機組裝與維修技術
- Apple Motion 5 Cookbook
- 深入理解序列化與反序列化
- STM32自學筆記
- USB應用分析精粹:從設備硬件、固件到主機端程序設計
- Building Machine Learning Systems with Python
- The Applied Artificial Intelligence Workshop
- 基于S5PV210處理器的嵌入式開發完全攻略
- ARM接口編程