Skip to content

Commit 5ab626e

Browse files
committed
RV3028: C/C++ Library docs
1 parent a7e48ed commit 5ab626e

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

libraries/breakout_rtc/README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# RV3028 Breakout (C/C++)
2+
3+
An ultra-low-power ( ~100 nA), highly accurate real-time clock breakout. The RV3028 RTC breakout is perfect for adding timekeeping to your project and, thanks to the tiny on-board battery, it'll keep time when your device is powered off. Like all the best timepieces, it's Swiss-made!
4+
5+
Available here: https://shop.pimoroni.com/products/rv3028-real-time-clock-rtc-breakout
6+
7+
# **Example Program**
8+
9+
Example program shows how to setup the RV3028, set the date and time and output it once a second.
10+
11+
```
12+
#include "pico/stdlib.h"
13+
#include "breakout_rtc.hpp"
14+
15+
using namespace pimoroni;
16+
17+
I2C i2c(BOARD::BREAKOUT_GARDEN);
18+
BreakoutRTC rtc(&i2c);
19+
20+
int main() {
21+
22+
stdio_init_all();
23+
24+
if(!rtc.init()) {
25+
printf("Init failed! Check your connections and i2c pin choices.\n");
26+
}
27+
28+
rtc.enable_periodic_update_interrupt(true);
29+
30+
rtc.set_time(10, 10, 10, 7, 12, 9, 2024);
31+
32+
while(true) {
33+
if(rtc.read_periodic_update_interrupt_flag()) {
34+
rtc.clear_periodic_update_interrupt_flag();
35+
36+
if(rtc.update_time()) {
37+
printf("Date: %s, Time: %s\n", rtc.string_date(), rtc.string_time());
38+
39+
}
40+
}
41+
42+
sleep_ms(100);
43+
44+
}
45+
46+
return 0;
47+
48+
}
49+
```
50+
51+
# **Functions**
52+
53+
## `bool init()`
54+
55+
Initializes the RV3028. Returns `true` if successful or `false` if something went wrong.
56+
57+
**Example**
58+
59+
```
60+
I2C i2c(BOARD::BREAKOUT_GARDEN);
61+
BreakoutRTC rtc(&i2c);
62+
63+
rtc.init();
64+
```
65+
66+
## `bool setup()`
67+
68+
Sets the RTC to 24 Hour Mode, disables the Trickle Charge and sets Level Switching Mode to 3.
69+
70+
## `bool set_time(uint8_t sec, uint8_t min, uint8_t hour, uint8_t weekday, uint8_t date, uint8_t month, uint16_t year)`
71+
72+
Set the time and date on the RTC. Returns `true` if successful and `false` if something went wrong.
73+
74+
You can also set a time or date element individually with:
75+
76+
`set_seconds(uint8_t value)`, `set_minutes(uint8_t value)`, `set_hours(uint8_t value)`, `set_weekday(uint8_t value)`, `set_date(uint8_t value)`, `set_month(uint8_t value)` and `set_year(uint8_t value)`
77+
78+
79+
## `void set_24_hour()`
80+
81+
Set the RTC to output 0-23 Hours. This function will convert any current hour to 2 Hour Mode.
82+
83+
## `void set_12_hour()`
84+
85+
Set the RTC to output 1-12 Hours. This function will convert any current hour to 12 Hour Mode.
86+
87+
## `bool is_12_hour()`
88+
89+
Returns `true` if the RV3028 has been configured for 12 Hour mode.
90+
91+
## `bool is_pm()`
92+
93+
Returns `true` if the RTC has the PM bit set and the 12 Hour bit set
94+
95+
## `bool update_time()`
96+
97+
This function moves the data from the RV3028 registers to an array. You need to call this function before printing the time and date. The function returns `true` if successful and `false` if something went wrong.
98+
99+
## `char* string_time()`
100+
101+
Returns a pointer to array of chars that represents the time in hh:mm:ss format. Adds AM/PM if in 12 hour mode. You will need to call `update_time()` to get the current time from the RTC before using this function.
102+
103+
## `char* string_date()`
104+
105+
Returns a pointer to array of chars that are the date in dd/mm/yyyy format. You will need to call `update_time()` to get the current date from the RTC before using this function.
106+
107+
## `void enable_periodic_update_interrupt(bool every_second, bool enable_clock_output)`
108+
109+
Enables the periodic update interrupt.
110+
111+
## `void disable_periodic_update_interrupt()`
112+
113+
Disables the periodic update interrupt.
114+
115+
## `bool read_periodic_update_interrupt_flag()`
116+
117+
Read the periodic update interrupt flag. Returns a boolean value.
118+
119+
## `void clear_periodic_update_interrupt_flag()`
120+
121+
Clear the periodic update interrupt flag.
122+
123+
## `uint32_t get_unix()`
124+
125+
Get the UNIX Time from the RTC
126+
127+
## `bool set_unix(uint32_t value)`
128+
129+
Set the UNIX Time on the RTC. Returns `true` if successful and `false` if something went wrong.
130+
131+
**IMPORTANT:** The Real Time and the UNIX time are independent of each other. Setting the UNIX time will not update the Real Time (Hours, minutes, seconds etc)
132+
133+
## `bool set_backup_switchover_mode(uint8_t val)`
134+
135+
Set the backup switchover mode of the RTC. Accepts values 0-3.
136+
137+
0 = Switchover disabled
138+
1 = Direct Switching Mode
139+
2 = Standby Mode
140+
3 = Level Switching Mode
141+
142+
Function returns `true` if successful and `false` if something went wrong.
143+
144+
145+

0 commit comments

Comments
 (0)