rtc18  2.0.0.0
rtc18.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 
28 #ifndef RTC18_H
29 #define RTC18_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define RTC18_REG_100TH_SECONDS 0x00
60 #define RTC18_REG_SECONDS 0x01
61 #define RTC18_REG_MINUTES 0x02
62 #define RTC18_REG_HOURS 0x03
63 #define RTC18_REG_WEEKDAY 0x04
64 #define RTC18_REG_DATE 0x05
65 #define RTC18_REG_MONTH 0x06
66 #define RTC18_REG_YEAR 0x07
67 #define RTC18_REG_MINUTES_ALARM 0x08
68 #define RTC18_REG_HOURS_ALARM 0x09
69 #define RTC18_REG_DATE_ALARM 0x0A
70 #define RTC18_REG_TIMER_VALUE_0 0x0B
71 #define RTC18_REG_TIMER_VALUE_1 0x0C
72 #define RTC18_REG_STATUS 0x0D
73 #define RTC18_REG_TEMPERATURE_LSB 0x0E
74 #define RTC18_REG_TEMPERATURE_MSB 0x0F
75 #define RTC18_REG_CONTROL_1 0x10
76 #define RTC18_REG_CONTROL_2 0x11
77 #define RTC18_REG_CONTROL_3 0x12
78 #define RTC18_REG_TIME_STAMP_CONTROL 0x13
79 #define RTC18_REG_CLOCK_INT_MASK 0x14
80 #define RTC18_REG_EVI_CONTROL 0x15
81 #define RTC18_REG_TLOW_THRESHOLD 0x16
82 #define RTC18_REG_THIGH_THRESHOLD 0x17
83 #define RTC18_REG_TS_TLOW_COUNT 0x18
84 #define RTC18_REG_TS_TLOW_SECONDS 0x19
85 #define RTC18_REG_TS_TLOW_MINUTES 0x1A
86 #define RTC18_REG_TS_TLOW_HOURS 0x1B
87 #define RTC18_REG_TS_TLOW_DATE 0x1C
88 #define RTC18_REG_TS_TLOW_MONTH 0x1D
89 #define RTC18_REG_TS_TLOW_YEAR 0x1E
90 #define RTC18_REG_TS_THIGH_COUNT 0x1F
91 #define RTC18_REG_TS_THIGH_SECONDS 0x20
92 #define RTC18_REG_TS_THIGH_MINUTES 0x21
93 #define RTC18_REG_TS_THIGH_HOURS 0x22
94 #define RTC18_REG_TS_THIGH_DATE 0x23
95 #define RTC18_REG_TS_THIGH_MONTH 0x24
96 #define RTC18_REG_TS_THIGH_YEAR 0x25
97 #define RTC18_REG_TS_EVI_COUNT 0x26
98 #define RTC18_REG_TS_EVI_100TH_SECONDS 0x27
99 #define RTC18_REG_TS_EVI_SECONDS 0x28
100 #define RTC18_REG_TS_EVI_MINUTES 0x29
101 #define RTC18_REG_TS_EVI_HOURS 0x2A
102 #define RTC18_REG_TS_EVI_DATE 0x2B
103 #define RTC18_REG_TS_EVI_MONTH 0x2C
104 #define RTC18_REG_TS_EVI_YEAR 0x2D
105 #define RTC18_REG_PASSWORD_0 0x39
106 #define RTC18_REG_PASSWORD_1 0x3A
107 #define RTC18_REG_PASSWORD_2 0x3B
108 #define RTC18_REG_PASSWORD_3 0x3C
109 #define RTC18_REG_EEPROM_ADDRESS 0x3D
110 #define RTC18_REG_EEPROM_DATA 0x3E
111 #define RTC18_REG_EEPROM_COMMAND 0x3F
112 #define RTC18_REG_USER_RAM_16B 0x40
113 
118 #define RTC18_EEPROM_PMU 0xC0
119 #define RTC18_EEPROM_OFFSET 0xC1
120 #define RTC18_EEPROM_CLKOUT_1 0xC2
121 #define RTC18_EEPROM_CLKOUT_2 0xC3
122 #define RTC18_EEPROM_TREF_0 0xC4
123 #define RTC18_EEPROM_TREF_1 0xC5
124 #define RTC18_EEPROM_PASSWORD_0 0xC6
125 #define RTC18_EEPROM_PASSWORD_1 0xC7
126 #define RTC18_EEPROM_PASSWORD_2 0xC8
127 #define RTC18_EEPROM_PASSWORD_3 0xC9
128 #define RTC18_EEPROM_PW_ENABLE 0xCA
129 #define RTC18_EEPROM_USER_MEMORY_32B 0xCB
130  // rtc18_reg
132 
147 #define RTC18_STATUS_THF 0x80
148 #define RTC18_STATUS_TLF 0x40
149 #define RTC18_STATUS_UF 0x20
150 #define RTC18_STATUS_TF 0x10
151 #define RTC18_STATUS_AF 0x08
152 #define RTC18_STATUS_EVF 0x04
153 #define RTC18_STATUS_PORF 0x02
154 #define RTC18_STATUS_VLF 0x01
155 
160 #define RTC18_CONTROL1_RESERVED 0x20
161 #define RTC18_CONTROL1_USEL 0x10
162 #define RTC18_CONTROL1_TE 0x08
163 #define RTC18_CONTROL1_EERD 0x04
164 #define RTC18_CONTROL1_TD_4096HZ 0x00
165 #define RTC18_CONTROL1_TD_64HZ 0x01
166 #define RTC18_CONTROL1_TD_1HZ 0x02
167 #define RTC18_CONTROL1_TD_1_60HZ 0x03
168 #define RTC18_CONTROL1_TD_BIT_MASK 0x03
169 
174 #define RTC18_CONTROL2_CLKIE 0x40
175 #define RTC18_CONTROL2_UIE 0x20
176 #define RTC18_CONTROL2_TIE 0x10
177 #define RTC18_CONTROL2_AIE 0x08
178 #define RTC18_CONTROL2_EIE 0x04
179 #define RTC18_CONTROL2_STOP 0x01
180 
185 #define RTC18_CONTROL3_BSIE 0x10
186 #define RTC18_CONTROL3_THE 0x08
187 #define RTC18_CONTROL3_TLE 0x04
188 #define RTC18_CONTROL3_THIE 0x02
189 #define RTC18_CONTROL3_TLIE 0x01
190 
195 #define RTC18_MONDAY 0x00
196 #define RTC18_TUESDAY 0x01
197 #define RTC18_WEDNESDAY 0x02
198 #define RTC18_THURSDAY 0x03
199 #define RTC18_FRIDAY 0x04
200 #define RTC18_SATURDAY 0x05
201 #define RTC18_SUNDAY 0x06
202 
207 #define RTC18_TEMPERATURE_RESOLUTION 0.0625
208 #define RTC18_TEMPERATURE_LSB_TEMP_BIT_MASK 0xF0
209 #define RTC18_TEMPERATURE_LSB_EEF 0x08
210 #define RTC18_TEMPERATURE_LSB_EEBUSY 0x04
211 #define RTC18_TEMPERATURE_LSB_CLKF 0x02
212 #define RTC18_TEMPERATURE_LSB_BSF 0x01
213 
218 #define RTC18_EECMD_UPDATE 0x11
219 #define RTC18_EECMD_REFRESH 0x12
220 #define RTC18_EECMD_WRITE_ONE_BYTE 0x21
221 #define RTC18_EECMD_READ_ONE_BYTE 0x22
222 
228 #define RTC18_DEVICE_ADDRESS 0x51
229  // rtc18_set
231 
246 #define RTC18_MAP_MIKROBUS( cfg, mikrobus ) \
247  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
248  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
249  cfg.evi = MIKROBUS( mikrobus, MIKROBUS_CS ); \
250  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
251  // rtc18_map // rtc18
254 
259 typedef struct
260 {
261  // Output pins
262  digital_out_t evi;
264  // Input pins
265  digital_in_t int_pin;
267  // Modules
268  i2c_master_t i2c;
270  // I2C slave address
271  uint8_t slave_address;
273 } rtc18_t;
274 
279 typedef struct
280 {
281  pin_name_t scl;
282  pin_name_t sda;
284  pin_name_t evi;
285  pin_name_t int_pin;
287  uint32_t i2c_speed;
288  uint8_t i2c_address;
290 } rtc18_cfg_t;
291 
297 typedef struct
298 {
299  uint8_t second_100th;
300  uint8_t second;
301  uint8_t minute;
302  uint8_t hour;
303 
304 } rtc18_time_t;
305 
311 typedef struct
312 {
313  uint8_t day_of_week;
314  uint8_t day;
315  uint8_t month;
316  uint8_t year;
317 
318 } rtc18_date_t;
319 
324 typedef enum
325 {
326  RTC18_OK = 0,
327  RTC18_ERROR = -1
328 
330 
347 
361 err_t rtc18_init ( rtc18_t *ctx, rtc18_cfg_t *cfg );
362 
375 err_t rtc18_default_cfg ( rtc18_t *ctx );
376 
391 err_t rtc18_generic_write ( rtc18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
392 
407 err_t rtc18_generic_read ( rtc18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
408 
422 err_t rtc18_write_register ( rtc18_t *ctx, uint8_t reg, uint8_t data_in );
423 
436 err_t rtc18_read_register ( rtc18_t *ctx, uint8_t reg, uint8_t *data_out );
437 
447 void rtc18_set_evi_pin ( rtc18_t *ctx, uint8_t state );
448 
457 uint8_t rtc18_get_int_pin ( rtc18_t *ctx );
458 
470 
483 err_t rtc18_set_time ( rtc18_t *ctx, rtc18_time_t *time );
484 
497 err_t rtc18_read_time ( rtc18_t *ctx, rtc18_time_t *time );
498 
511 err_t rtc18_set_date ( rtc18_t *ctx, rtc18_date_t *date );
512 
525 err_t rtc18_read_date ( rtc18_t *ctx, rtc18_date_t *date );
526 
538 err_t rtc18_read_temperature ( rtc18_t *ctx, float *temperature );
539 
553 err_t rtc18_write_eeprom ( rtc18_t *ctx, uint8_t address, uint8_t data_in );
554 
567 err_t rtc18_read_eeprom ( rtc18_t *ctx, uint8_t address, uint8_t *data_out );
568 
569 #ifdef __cplusplus
570 }
571 #endif
572 #endif // RTC18_H
573  // rtc18
575 
576 // ------------------------------------------------------------------------ END
rtc18_read_register
err_t rtc18_read_register(rtc18_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 18 read register function.
rtc18_set_evi_pin
void rtc18_set_evi_pin(rtc18_t *ctx, uint8_t state)
RTC 18 set EVI pin function.
rtc18_read_date
err_t rtc18_read_date(rtc18_t *ctx, rtc18_date_t *date)
RTC 18 read date function.
rtc18_cfg_t::i2c_address
uint8_t i2c_address
Definition: rtc18.h:288
rtc18_cfg_t::scl
pin_name_t scl
Definition: rtc18.h:281
rtc18_time_t::second_100th
uint8_t second_100th
Definition: rtc18.h:299
rtc18_time_t::minute
uint8_t minute
Definition: rtc18.h:301
rtc18_return_value_t
rtc18_return_value_t
RTC 18 Click return value data.
Definition: rtc18.h:325
rtc18_read_eeprom
err_t rtc18_read_eeprom(rtc18_t *ctx, uint8_t address, uint8_t *data_out)
RTC 18 read eeprom function.
rtc18_time_t::hour
uint8_t hour
Definition: rtc18.h:302
rtc18_date_t::year
uint8_t year
Definition: rtc18.h:316
rtc18_init
err_t rtc18_init(rtc18_t *ctx, rtc18_cfg_t *cfg)
RTC 18 initialization function.
rtc18_write_eeprom
err_t rtc18_write_eeprom(rtc18_t *ctx, uint8_t address, uint8_t data_in)
RTC 18 write eeprom function.
rtc18_set_time
err_t rtc18_set_time(rtc18_t *ctx, rtc18_time_t *time)
RTC 18 set time function.
rtc18_default_cfg
err_t rtc18_default_cfg(rtc18_t *ctx)
RTC 18 default configuration function.
rtc18_cfg_t::evi
pin_name_t evi
Definition: rtc18.h:284
rtc18_date_t::day_of_week
uint8_t day_of_week
Definition: rtc18.h:313
rtc18_generic_read
err_t rtc18_generic_read(rtc18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 18 I2C reading function.
rtc18_cfg_t::int_pin
pin_name_t int_pin
Definition: rtc18.h:285
rtc18_t
RTC 18 Click context object.
Definition: rtc18.h:260
rtc18_time_t
RTC 18 Click time object.
Definition: rtc18.h:298
rtc18_cfg_t::sda
pin_name_t sda
Definition: rtc18.h:282
rtc18_t::slave_address
uint8_t slave_address
Definition: rtc18.h:271
rtc18_cfg_setup
void rtc18_cfg_setup(rtc18_cfg_t *cfg)
RTC 18 configuration object setup function.
rtc18_date_t::day
uint8_t day
Definition: rtc18.h:314
rtc18_read_temperature
err_t rtc18_read_temperature(rtc18_t *ctx, float *temperature)
RTC 18 read temperature function.
rtc18_write_register
err_t rtc18_write_register(rtc18_t *ctx, uint8_t reg, uint8_t data_in)
RTC 18 write register function.
rtc18_cfg_t
RTC 18 Click configuration object.
Definition: rtc18.h:280
rtc18_date_t
RTC 18 Click date object.
Definition: rtc18.h:312
rtc18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rtc18.h:287
rtc18_time_t::second
uint8_t second
Definition: rtc18.h:300
rtc18_set_date
err_t rtc18_set_date(rtc18_t *ctx, rtc18_date_t *date)
RTC 18 set date function.
rtc18_clear_periodic_interrupt
err_t rtc18_clear_periodic_interrupt(rtc18_t *ctx)
RTC 18 clear periodic interrupt function.
rtc18_date_t::month
uint8_t month
Definition: rtc18.h:315
rtc18_t::i2c
i2c_master_t i2c
Definition: rtc18.h:268
rtc18_read_time
err_t rtc18_read_time(rtc18_t *ctx, rtc18_time_t *time)
RTC 18 read time function.
RTC18_OK
@ RTC18_OK
Definition: rtc18.h:326
rtc18_get_int_pin
uint8_t rtc18_get_int_pin(rtc18_t *ctx)
RTC 18 get int pin function.
rtc18_t::int_pin
digital_in_t int_pin
Definition: rtc18.h:265
rtc18_t::evi
digital_out_t evi
Definition: rtc18.h:262
rtc18_generic_write
err_t rtc18_generic_write(rtc18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 18 I2C writing function.
RTC18_ERROR
@ RTC18_ERROR
Definition: rtc18.h:327