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

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.

主站蜘蛛池模板: 通化市| 晋江市| 呼图壁县| 茂名市| 固阳县| 靖西县| 遂溪县| 新和县| 临猗县| 华坪县| 浦东新区| 陕西省| 铁岭市| 荆州市| 八宿县| 泊头市| 固镇县| 文昌市| 体育| 陇西县| 彭水| 荃湾区| 泸水县| 安庆市| 新乐市| 尉犁县| 武鸣县| 长汀县| 方正县| 敦化市| 正蓝旗| 黔南| 巴南区| 泸溪县| 九江县| 溆浦县| 乌鲁木齐市| 岢岚县| 漳平市| 英吉沙县| 万宁市|