rtc24 2.2.0
Loading...
Searching...
No Matches
rtc24.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef RTC24_H
29#define RTC24_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define RTC24_REG_SECONDS 0x00
74#define RTC24_REG_MINUTES 0x01
75#define RTC24_REG_HOURS 0x02
76#define RTC24_REG_DAY 0x03
77#define RTC24_REG_DATE 0x04
78#define RTC24_REG_MONTH 0x05
79#define RTC24_REG_YEAR 0x06
80#define RTC24_REG_CONTROL 0x07
81#define RTC24_REG_RAM_START 0x08
82#define RTC24_REG_RAM_END 0x3F
83 // rtc24_reg
85
90
95
100#define RTC24_CONTROL_OUT_LOW 0x00
101#define RTC24_CONTROL_OUT_HIGH 0x80
102#define RTC24_CONTROL_OUT_MASK 0x80
103#define RTC24_CONTROL_SQWE_DIS 0x00
104#define RTC24_CONTROL_SQWE_EN 0x10
105#define RTC24_CONTROL_SQWE_MASK 0x10
106#define RTC24_CONTROL_RS_1HZ 0x00
107#define RTC24_CONTROL_RS_4_096KHZ 0x01
108#define RTC24_CONTROL_RS_8_192KHZ 0x02
109#define RTC24_CONTROL_RS_32_768KHZ 0x03
110#define RTC24_CONTROL_RS_MASK 0x03
111
116#define RTC24_MONDAY 0x00
117#define RTC24_TUESDAY 0x01
118#define RTC24_WEDNESDAY 0x02
119#define RTC24_THURSDAY 0x03
120#define RTC24_FRIDAY 0x04
121#define RTC24_SATURDAY 0x05
122#define RTC24_SUNDAY 0x06
123
128#define RTC24_DUMMY_RAM 0xA5
129
135#define RTC24_DEVICE_ADDRESS 0x68
136 // rtc24_set
138
143
148
153#define RTC24_MAP_MIKROBUS( cfg, mikrobus ) \
154 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
155 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
156 cfg.sqw = MIKROBUS( mikrobus, MIKROBUS_INT )
157 // rtc24_map // rtc24
160
165typedef struct
166{
167 // Input pins
168 digital_in_t sqw;
169
170 // Modules
171 i2c_master_t i2c;
172
173 // I2C slave address
175
176} rtc24_t;
177
182typedef struct
183{
184 pin_name_t scl;
185 pin_name_t sda;
186
187 pin_name_t sqw;
188
189 uint32_t i2c_speed;
190 uint8_t i2c_address;
191
193
199typedef struct
200{
201 uint8_t second;
202 uint8_t minute;
203 uint8_t hour;
204
206
212typedef struct
213{
214 uint8_t day_of_week;
215 uint8_t day;
216 uint8_t month;
217 uint8_t year;
218
220
225typedef enum
226{
229
231
237
248
262err_t rtc24_init ( rtc24_t *ctx, rtc24_cfg_t *cfg );
263
277
290err_t rtc24_write_regs ( rtc24_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
291
304err_t rtc24_read_regs ( rtc24_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
305
317err_t rtc24_write_reg ( rtc24_t *ctx, uint8_t reg, uint8_t data_in );
318
330err_t rtc24_read_reg ( rtc24_t *ctx, uint8_t reg, uint8_t *data_out );
331
340uint8_t rtc24_get_sqw_pin ( rtc24_t *ctx );
341
352
364err_t rtc24_set_time ( rtc24_t *ctx, rtc24_time_t *time );
365
378
390err_t rtc24_set_date ( rtc24_t *ctx, rtc24_date_t *date );
391
404
405#ifdef __cplusplus
406}
407#endif
408#endif // RTC24_H
409 // rtc24
411
412// ------------------------------------------------------------------------ END
err_t rtc24_read_time(rtc24_t *ctx, rtc24_time_t *time)
RTC 24 read time function.
err_t rtc24_check_communication(rtc24_t *ctx)
RTC 24 check communication function.
err_t rtc24_write_regs(rtc24_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 24 write multiple registers function.
err_t rtc24_default_cfg(rtc24_t *ctx)
RTC 24 default configuration function.
err_t rtc24_set_time(rtc24_t *ctx, rtc24_time_t *time)
RTC 24 set time function.
uint8_t rtc24_get_sqw_pin(rtc24_t *ctx)
RTC 24 get square wave pin function.
err_t rtc24_read_reg(rtc24_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 24 read single register function.
err_t rtc24_write_reg(rtc24_t *ctx, uint8_t reg, uint8_t data_in)
RTC 24 write single register function.
err_t rtc24_set_date(rtc24_t *ctx, rtc24_date_t *date)
RTC 24 set date function.
err_t rtc24_init(rtc24_t *ctx, rtc24_cfg_t *cfg)
RTC 24 initialization function.
err_t rtc24_read_regs(rtc24_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 24 read multiple registers function.
void rtc24_cfg_setup(rtc24_cfg_t *cfg)
RTC 24 configuration object setup function.
err_t rtc24_read_date(rtc24_t *ctx, rtc24_date_t *date)
RTC 24 read date function.
rtc24_return_value_t
RTC 24 Click return value data.
Definition rtc24.h:226
@ RTC24_OK
Definition rtc24.h:227
@ RTC24_ERROR
Definition rtc24.h:228
RTC 24 Click configuration object.
Definition rtc24.h:183
uint32_t i2c_speed
Definition rtc24.h:189
pin_name_t sqw
Definition rtc24.h:187
pin_name_t scl
Definition rtc24.h:184
pin_name_t sda
Definition rtc24.h:185
uint8_t i2c_address
Definition rtc24.h:190
RTC 24 Click date object.
Definition rtc24.h:213
uint8_t month
Definition rtc24.h:216
uint8_t day
Definition rtc24.h:215
uint8_t year
Definition rtc24.h:217
uint8_t day_of_week
Definition rtc24.h:214
RTC 24 Click context object.
Definition rtc24.h:166
i2c_master_t i2c
Definition rtc24.h:171
digital_in_t sqw
Definition rtc24.h:168
uint8_t slave_address
Definition rtc24.h:174
RTC 24 Click time object.
Definition rtc24.h:200
uint8_t second
Definition rtc24.h:201
uint8_t minute
Definition rtc24.h:202
uint8_t hour
Definition rtc24.h:203