Hardware Reference
In-Depth Information
The full command to load the module will look like this; once again your I2C bus may be different, so use the bus
that you worked with in the previous steps. In my case, this is bus 0.
# echo ds1307 0x68 > /sys/class/i2c-adapter/ i2c-0/new_device
You can see in Figure 8-17 the dmesg output and that an RTC was found and that a new device node was created
at /dev/rtc0 .
Figure 8-17. dmesg listing for the new device
Now that your hardware RTC is installed, it might be a good idea to read from it. Issue the following command:
# hwclock -r
The date will be a little bit off; after all, the RTC has never been used. Take a look at Figure 8-18 ; you can see the
very wrong date on my RTC.
Figure 8-18. Invalid date and time on RTC
It would be a good idea to set the correct date. If you issue the date command, you will notice the date and time
have been set back to the date and time in the RTC. Set the correct date and time with the date command:
# date MMDDHHMMYYYY
This command breaks down as follows: MM is the month, zero padded; DD is the day, also zero padded; HH is
the hour in 24-hour format; MM is minutes, also zero padded; and YYYY is the full four-digit year number. After you
have done that, set the current system date and time to be the current date and time in the RTC. To do this, use this
command:
# hwclock -w
This will write the system date and time into the hardware clock; it's best to check that the previous command
has worked with the hwclock -r command so that you can read the date and time from the RTC. Give your Raspberry
Pi a reboot to see your new RTC in action. As expected, nothing happens. The RTC was not even detected. The
reason for this is that by default the Linux kernel will not look on the I2C bus for any form of RTC. You are also using
a userspace tool to create the device node; the Linux kernel has no way to detect devices on an I2C bus. For the Linux
 
Search WWH ::




Custom Search