Tags:
tag this topic
create new tag
view all tags
---+ The Realtime Clock ---++ Goal: The real time clock and eeprom module uses the [[https://datasheets.maximintegrated.com/en/ds/DS1307.pdf][DS1307 ]]real time clock chip which can be programmed using its I2C bus interface. The pigpio library contains I2C access functions perfectly adapted to programming the chip. In this exercise we will write a program that allows to set the Realtime Clock (RTC) and to read the current date and time. In order to set the time we must be able to transmit time and date value into the program which we do through program arguments. This is done through the getopt function, which is part of the C library. | <img alt="rtcfront.png" height="343" src="%ATTACHURL%/rtcfront.png" title="rtcfront.png" width="351" /> | <img alt="rtcCircuit.png" height="469" src="%ATTACHURL%/rtcCircuit.png" title="rtcCircuit.png" width="568" /> | | RTC circuit board | Circuit diagram | You can connect the RTC board to the Raspberry Pi either on P1 or P2. DS is the signal line of a DS18B20 digital temperature chip, which is not mounted on the board and therefore not used. You just neew Vcc and ground and the SCL and SDA signals from the I2C bus. The !DS1307 RTC chip is the bottom one, right to the 32 kHz quartz (metallic cylinder). The other chip is an [[Atmel%20AT24C32%20I2C%20EEProm][Atmel AT24C32 I2C EEPROM]], which we use in another exercise. ---++ Getting access to the chip The RTC card uses a [[https://datasheets.maximintegrated.com/en/ds/DS1307.pdf][DS1307]] realtime clock chip from Maxim. It is interfaced to the Raspberry Pi through the I2C bus. From the datasheet we can find out its default I2C address which we verify with the _i2cdetect 1_ command (the chip is on bus 1). Try to see if you can access the chip correctly by just setting a single register and reading it back. ---++ getopt In order to allow the user of your program (which is probably yourself) to enter the date and time setting, you must provide a method to define which parameter is to be set (e.g. sec or min or h) and to which value it is to be set. This can be done using command line arguments which can be treated with the getopt library call. Have a look on the WEB how this is done. ---++ The full program The full program will allows to set any of the RTC parameters and/or to read back date and time. Since the RTC uses a battery, once set it will keep the correct time for very long. The is a function in my own solution, which prints a "usage" message, explaining how the program is to be used: <verbatim>void printUsage() { printf("The rtc program, called without parameters, will print the\n"); printf("current date and time\n"); printf("If called with arguments it will set the realtime clock\n"); printf("arguments are:\n"); printf(" long argument, short argument, value\n"); printf(" --help, ? n/a\n"); printf(" --seconds -s 0..59\n"); printf(" --minutes -m 0..59\n"); printf(" --weekday -w 1..7\n"); printf(" or \"mon\",\"tue\",\"wed\"...\n"); printf(" --date -D date within month\n"); printf(" --month -M 1..12\n"); printf(" or \"jan\",\"feb\",\"mar\"...\n"); printf(" --year -Y 0..99\n"); }</verbatim> -- %USERSIG{UliRaich - 2017-04-06}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
png
rtcCircuit.png
r1
manage
37.6 K
2017-04-06 - 11:59
UnknownUser
png
rtcfront.png
r1
manage
2290.3 K
2017-04-06 - 11:45
UnknownUser
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2017-04-06
-
uli
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
Embedded_Systems Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback