rtc11 2.0.0.0
rtc11.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 RTC11_H
29#define RTC11_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_spi_master.h"
52
73#define RTC11_RD_BIT_MASK 0x7F
74#define RTC11_WR_BIT_MASK 0x80
75
76#define RTC11_REG_HDT 0x00
77#define RTC11_REG_SEC 0x01
78#define RTC11_REG_MIN 0x02
79#define RTC11_REG_HRS 0x03
80#define RTC11_REG_DAT 0x04
81#define RTC11_REG_MON 0x05
82#define RTC11_REG_YRS 0x06
83#define RTC11_REG_WKD 0x07
84#define RTC11_REG_ALA_HDT 0x08
85#define RTC11_REG_ALA_SEC 0x09
86#define RTC11_REG_ALA_MIN 0x0A
87#define RTC11_REG_ALA_HRS 0x0B
88#define RTC11_REG_ALA_DAT 0x0C
89#define RTC11_REG_ALA_MON 0x0D
90#define RTC11_REG_ALA_WKD 0x0E
91#define RTC11_REG_STAT 0x0F
92#define RTC11_REG_CTL1 0x10
93#define RTC11_REG_CTL2 0x11
94#define RTC11_REG_INT_MSK 0x12
95#define RTC11_REG_SQW 0x13
96#define RTC11_REG_CAL_XT 0x14
97#define RTC11_REG_CAL_RC_HI 0x15
98#define RTC11_REG_CAL_RC_LOW 0x16
99#define RTC11_REG_INT_POL 0x17
100#define RTC11_REG_TMR_CTL 0x18
101#define RTC11_REG_TMR 0x19
102#define RTC11_REG_TMR_INIT 0x1A
103#define RTC11_REG_WDT 0x1B
104#define RTC11_REG_OSC_CTL 0x1C
105#define RTC11_REG_OSC_STAT 0x1D
106#define RTC11_REG_CFG_KEY 0x1F
107#define RTC11_REG_TRCK 0x20
108#define RTC11_REG_BREF_CTL 0x21
109#define RTC11_REG_BAT_MODE 0x27
110#define RTC11_REG_ID_0 0x28
111#define RTC11_REG_ID_1 0x29
112#define RTC11_REG_ID_2 0x2A
113#define RTC11_REG_ID_3 0x2B
114#define RTC11_REG_ID_4 0x2C
115#define RTC11_REG_ID_5 0x2D
116#define RTC11_REG_ID_6 0x2E
117#define RTC11_REG_ASTAT 0x2F
118#define RTC11_REG_OCTRL 0x30
119#define RTC11_REG_EXT_ADR 0x3F
120#define RTC11_REG_RAM 0x40
121
122 // rtc11_reg
123
138#define RTC11_CTL1_STOP 0x80
139#define RTC11_CTL1_12_HRS 0x40
140#define RTC11_CTL1_OUTB 0x20
141#define RTC11_CTL1_OUT 0x10
142#define RTC11_CTL1_ARST 0x04
143#define RTC11_CTL1_WRTC 0x01
144
145#define RTC11_ACS_OSC_CTL 0xA1
146#define RTC11_SW_RST 0x3C
147#define RTC11_ACS_AN_CTL_REG 0x9D
148
149#define RTC11_CEB 0x80
150#define RTC11_BLIE 0x10
151#define RTC11_TIE 0x08
152#define RTC11_AIE 0x04
153#define RTC11_EX2E 0x02
154#define RTC11_EX1E 0x01
155
156#define RTC11_PROP_DIS 0x00
157#define RTC11_PROP_EN 0x01
158
159 // rtc11_set
160
175#define RTC11_MAP_MIKROBUS( cfg, mikrobus ) \
176 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
177 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
178 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
179 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
180 cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_AN ); \
181 cfg.exi = MIKROBUS( mikrobus, MIKROBUS_RST ); \
182 cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
183 cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT )
184
185 // rtc11_map
186 // rtc11
187
192typedef struct
193{
194 // Output pins
195 digital_out_t wdi;
196 digital_out_t exi;
198 // Input pins
199 digital_in_t it2;
200 digital_in_t it1;
202 // Modules
203 spi_master_t spi;
205 pin_name_t chip_select;
207} rtc11_t;
208
213typedef struct
214{
215 // Communication gpio pins
216 pin_name_t miso;
217 pin_name_t mosi;
218 pin_name_t sck;
219 pin_name_t cs;
221 // Additional gpio pins
222 pin_name_t wdi;
223 pin_name_t exi;
224 pin_name_t it2;
225 pin_name_t it1;
227 // static variable
228 uint32_t spi_speed;
229 spi_master_mode_t spi_mode;
230 spi_master_chip_select_polarity_t cs_polarity;
233
238typedef struct
239{
240 uint8_t hours;
241 uint8_t min;
242 uint8_t sec;
244
249typedef struct
250{
251 uint8_t year;
252 uint8_t month;
253 uint8_t day;
254 uint8_t day_of_week;
256
261typedef enum
262{
264 RTC11_ERROR = -1
265
267
284
299err_t rtc11_init ( rtc11_t *ctx, rtc11_cfg_t *cfg );
300
312void rtc11_generic_write ( rtc11_t *ctx, uint8_t reg, uint8_t *wr_data, uint16_t n_len );
313
325void rtc11_generic_read ( rtc11_t *ctx, uint8_t reg, uint8_t *rd_data, uint16_t n_len );
326
335uint8_t rtc11_check_irq_1 ( rtc11_t *ctx );
336
345uint8_t rtc11_check_irq_2 ( rtc11_t *ctx );
346
356void rtc11_wdi ( rtc11_t *ctx, uint8_t state );
357
367void rtc11_ext_int ( rtc11_t *ctx, uint8_t state );
368
377void rtc11_set_time_hundredths ( rtc11_t *ctx, uint8_t hundredths );
378
387void rtc11_set_time_seconds ( rtc11_t *ctx, uint8_t seconds );
388
397void rtc11_set_time_minutes ( rtc11_t *ctx, uint8_t minutes );
398
407void rtc11_set_time_hours ( rtc11_t *ctx, uint8_t hours );
408
417
426
435
444
453
462void rtc11_set_date_day ( rtc11_t *ctx, uint8_t date_day );
463
472
481void rtc11_set_date_month ( rtc11_t *ctx, uint8_t date_mth );
482
491
500void rtc11_set_date_year ( rtc11_t *ctx, uint16_t date_yrs );
501
510
519
528void rtc11_set_day_of_the_week ( rtc11_t *ctx, uint8_t w_day );
529
538void rtc11_set_ala_time_hundredths ( rtc11_t *ctx, uint8_t hundredths );
539
548void rtc11_set_ala_time_seconds ( rtc11_t *ctx, uint8_t seconds );
549
558void rtc11_set_ala_time_minutes ( rtc11_t *ctx, uint8_t minutes );
559
568void rtc11_set_ala_time_hours ( rtc11_t *ctx, uint8_t hours );
569
578
587
596
605
614
623void rtc11_set_ala_date_day ( rtc11_t *ctx, uint8_t date_day );
624
633
642void rtc11_set_ala_date_month ( rtc11_t *ctx, uint8_t date_mth );
643
652
661void rtc11_set_ala_day_of_the_week ( rtc11_t *ctx, uint8_t w_day );
662
671
684err_t rtc11_set_time ( rtc11_t *ctx, rtc11_time_t rtc_time );
685
695void rtc11_get_time ( rtc11_t *ctx, rtc11_time_t *rtc_time );
696
709err_t rtc11_set_date ( rtc11_t *ctx, rtc11_date_t rtc_date );
710
720void rtc11_get_date ( rtc11_t *ctx, rtc11_date_t *rtc_date );
721
730void rtc11_stp_sys_slk ( rtc11_t *ctx, uint8_t state );
731
740void rtc11_auto_rst ( rtc11_t *ctx, uint8_t state );
741
750void rtc11_write_rtc ( rtc11_t *ctx, uint8_t state );
751
761void rtc11_cen_en ( rtc11_t *ctx, uint8_t state );
762
772void rtc11_bat_low_int_en ( rtc11_t *ctx, uint8_t state );
773
783void rtc11_timer_int_en ( rtc11_t *ctx, uint8_t state );
784
794void rtc11_alarm_int_en ( rtc11_t *ctx, uint8_t state );
795
805void rtc11_xt2_int_en ( rtc11_t *ctx, uint8_t state );
806
816void rtc11_xt1_int_en ( rtc11_t *ctx, uint8_t state );
817
827void rtc11_bat_mode_en ( rtc11_t *ctx, uint8_t state );
828
829#ifdef __cplusplus
830}
831#endif
832#endif // RTC11_H
833
834 // rtc11
835
836// ------------------------------------------------------------------------ END
void rtc11_write_rtc(rtc11_t *ctx, uint8_t state)
Write RTC enable function.
void rtc11_generic_write(rtc11_t *ctx, uint8_t reg, uint8_t *wr_data, uint16_t n_len)
RTC 11 data writing function.
uint8_t rtc11_check_irq_2(rtc11_t *ctx)
Check Interrupt 2 pin function.
void rtc11_set_ala_time_minutes(rtc11_t *ctx, uint8_t minutes)
Set alarm time minutes function.
uint8_t rtc11_get_ala_date_month(rtc11_t *ctx)
Get alarm time month function.
void rtc11_set_ala_time_seconds(rtc11_t *ctx, uint8_t seconds)
Set alarm time seconds function.
void rtc11_cen_en(rtc11_t *ctx, uint8_t state)
Century Enable function.
uint8_t rtc11_get_time_minutes(rtc11_t *ctx)
Get minutes function.
void rtc11_set_time_minutes(rtc11_t *ctx, uint8_t minutes)
Set minutes function.
void rtc11_set_ala_day_of_the_week(rtc11_t *ctx, uint8_t w_day)
Set alarm time day of the week function.
uint8_t rtc11_check_irq_1(rtc11_t *ctx)
Check Interrupt 1 pin function.
void rtc11_bat_low_int_en(rtc11_t *ctx, uint8_t state)
Battery Low Interrupt Enable function.
uint8_t rtc11_get_time_seconds(rtc11_t *ctx)
Get seconds function.
uint8_t rtc11_get_ala_time_minutes(rtc11_t *ctx)
Get alarm time minutes function.
void rtc11_wdi(rtc11_t *ctx, uint8_t state)
Watchdog reset function.
uint8_t rtc11_get_date_year(rtc11_t *ctx)
Get year function.
void rtc11_timer_int_en(rtc11_t *ctx, uint8_t state)
Timer Interrupt Enable function.
void rtc11_set_ala_date_month(rtc11_t *ctx, uint8_t date_mth)
Set alarm time month function.
uint8_t rtc11_get_ala_day_of_the_week(rtc11_t *ctx)
Get alarm time day of the week function.
void rtc11_set_ala_time_hundredths(rtc11_t *ctx, uint8_t hundredths)
Set alarm time hundredths function.
uint8_t rtc11_get_ala_time_seconds(rtc11_t *ctx)
Get alarm time seconds function.
uint8_t rtc11_get_ala_time_hundredths(rtc11_t *ctx)
Get alarm time hundredths function.
void rtc11_set_ala_date_day(rtc11_t *ctx, uint8_t date_day)
Set alarm time day function.
err_t rtc11_set_time(rtc11_t *ctx, rtc11_time_t rtc_time)
Set time hours, minutes and seconds function.
uint8_t rtc11_get_day_of_the_week(rtc11_t *ctx)
Get day of the week function.
void rtc11_cfg_setup(rtc11_cfg_t *cfg)
RTC 11 configuration object setup function.
void rtc11_get_date(rtc11_t *ctx, rtc11_date_t *rtc_date)
Get date day of the week, day, month and year function.
err_t rtc11_init(rtc11_t *ctx, rtc11_cfg_t *cfg)
RTC 11 initialization function.
void rtc11_ext_int(rtc11_t *ctx, uint8_t state)
External interrupt function.
void rtc11_auto_rst(rtc11_t *ctx, uint8_t state)
Auto reset enable function.
void rtc11_bat_mode_en(rtc11_t *ctx, uint8_t state)
Batmode enable function.
void rtc11_set_day_of_the_week(rtc11_t *ctx, uint8_t w_day)
Set day of the week function.
uint8_t rtc11_get_century_flag(rtc11_t *ctx)
Get century flag function.
void rtc11_soft_rst(rtc11_t *ctx)
Software Reset function.
void rtc11_set_time_hours(rtc11_t *ctx, uint8_t hours)
Set hours function.
void rtc11_get_time(rtc11_t *ctx, rtc11_time_t *rtc_time)
Get time hours, minutes and seconds function.
void rtc11_stp_sys_slk(rtc11_t *ctx, uint8_t state)
Stop the clocking system function.
void rtc11_set_ala_time_hours(rtc11_t *ctx, uint8_t hours)
Set alarm time hours function.
void rtc11_set_time_seconds(rtc11_t *ctx, uint8_t seconds)
Set seconds function.
void rtc11_generic_read(rtc11_t *ctx, uint8_t reg, uint8_t *rd_data, uint16_t n_len)
RTC 11 data reading function.
void rtc11_set_date_year(rtc11_t *ctx, uint16_t date_yrs)
Set year function.
uint8_t rtc11_get_date_month(rtc11_t *ctx)
Get month function.
void rtc11_xt2_int_en(rtc11_t *ctx, uint8_t state)
XT2 Interrupt Enable function.
void rtc11_set_date_month(rtc11_t *ctx, uint8_t date_mth)
Set month function.
uint8_t rtc11_get_time_hours(rtc11_t *ctx)
Get hours function.
uint8_t rtc11_get_time_hundredths(rtc11_t *ctx)
Get hundredths function.
void rtc11_set_time_hundredths(rtc11_t *ctx, uint8_t hundredths)
Set hundredths function.
void rtc11_alarm_int_en(rtc11_t *ctx, uint8_t state)
Alarm Interrupt Enable function.
uint8_t rtc11_get_ala_date_day(rtc11_t *ctx)
Get alarm time days function.
uint8_t rtc11_get_date_day(rtc11_t *ctx)
Get day function.
err_t rtc11_set_date(rtc11_t *ctx, rtc11_date_t rtc_date)
Set date day of the week, day, month and year function.
uint8_t rtc11_get_ala_time_hours(rtc11_t *ctx)
Get alarm time hours function.
void rtc11_set_date_day(rtc11_t *ctx, uint8_t date_day)
Set day function.
void rtc11_xt1_int_en(rtc11_t *ctx, uint8_t state)
XT1 Interrupt Enable function.
rtc11_return_value_t
RTC 11 Click return value data.
Definition rtc11.h:262
@ RTC11_OK
Definition rtc11.h:263
@ RTC11_ERROR
Definition rtc11.h:264
RTC 11 Click configuration object.
Definition rtc11.h:214
pin_name_t it2
Definition rtc11.h:224
pin_name_t wdi
Definition rtc11.h:222
pin_name_t it1
Definition rtc11.h:225
spi_master_chip_select_polarity_t cs_polarity
Definition rtc11.h:230
pin_name_t sck
Definition rtc11.h:218
spi_master_mode_t spi_mode
Definition rtc11.h:229
pin_name_t mosi
Definition rtc11.h:217
uint32_t spi_speed
Definition rtc11.h:228
pin_name_t miso
Definition rtc11.h:216
pin_name_t exi
Definition rtc11.h:223
pin_name_t cs
Definition rtc11.h:219
RTC 11 Click date object.
Definition rtc11.h:250
uint8_t month
Definition rtc11.h:252
uint8_t day
Definition rtc11.h:253
uint8_t year
Definition rtc11.h:251
uint8_t day_of_week
Definition rtc11.h:254
RTC 11 Click context object.
Definition rtc11.h:193
spi_master_t spi
Definition rtc11.h:203
digital_in_t it2
Definition rtc11.h:199
digital_out_t exi
Definition rtc11.h:196
pin_name_t chip_select
Definition rtc11.h:205
digital_out_t wdi
Definition rtc11.h:195
digital_in_t it1
Definition rtc11.h:200
RTC 11 Click time object.
Definition rtc11.h:239
uint8_t hours
Definition rtc11.h:240
uint8_t min
Definition rtc11.h:241
uint8_t sec
Definition rtc11.h:242