官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 浪卡子县| 奉节县| 景东| 成武县| 黔江区| 自贡市| 尼勒克县| 蒙阴县| 辽宁省| 沧州市| 克拉玛依市| 永年县| 宽城| 凤翔县| 万山特区| 兴仁县| 当阳市| 容城县| 翁源县| 孝义市| 五家渠市| 洱源县| 安福县| 巨鹿县| 祁东县| 昌平区| 曲松县| 红河县| 包头市| 汉寿县| 丹东市| 惠来县| 台湾省| 晋城| 滁州市| 江永县| 防城港市| 新民市| 仙游县| 汨罗市| 双流县|