rtc21  2.1.0.0
Main Page

RTC 21 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Filipovic
  • Date : Feb 2023.
  • Type : I2C type

Software Support

We provide a library for the RTC 21 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for RTC 21 Click driver.

Standard key functions :

Example key functions :

Example Description

This example demonstrates the use of RTC 21 click board by reading and displaying the time and date values.

The demo application is composed of two sections :

Application Init

Initializes the driver and logger and then sets the starting time and date.

void application_init ( void )
{
log_cfg_t log_cfg;
rtc21_cfg_t rtc21_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
rtc21_cfg_setup( &rtc21_cfg );
RTC21_MAP_MIKROBUS( rtc21_cfg, MIKROBUS_1 );
if ( I2C_MASTER_ERROR == rtc21_init( &rtc21, &rtc21_cfg ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
time.hour = 23;
time.minute = 59;
time.second = 50;
if ( RTC21_OK == rtc21_set_time ( &rtc21, &time ) )
{
log_printf( &logger, " Set time: %.2u:%.2u:%.2u\r\n",
( uint16_t ) time.hour, ( uint16_t ) time.minute, ( uint16_t ) time.second );
}
date.day_of_week = RTC21_SATURDAY;
date.day = 31;
date.month = 12;
date.year = 22;
if ( RTC21_OK == rtc21_set_date ( &rtc21, &date ) )
{
log_printf( &logger, " Set date: %s, %.2u.%.2u.20%.2u.\r\n",
rtc21_get_day_of_week_name ( date.day_of_week ),
( uint16_t ) date.day, ( uint16_t ) date.month, ( uint16_t ) date.year );
}
Delay_ms ( 100 );
log_info( &logger, " Application Task " );
}

Application Task

Reads and displays on the USB UART the current time and date values once per second.

void application_task ( void )
{
if ( RTC21_OK == rtc21_read_time ( &rtc21, &time ) )
{
log_printf( &logger, " Time: %.2u:%.2u:%.2u\r\n",
( uint16_t ) time.hour, ( uint16_t ) time.minute, ( uint16_t ) time.second );
}
if ( RTC21_OK == rtc21_read_date ( &rtc21, &date ) )
{
log_printf( &logger, " Date: %s, %.2u.%.2u.20%.2u.\r\n",
rtc21_get_day_of_week_name ( date.day_of_week ),
( uint16_t ) date.day, ( uint16_t ) date.month, ( uint16_t ) date.year );
}
Delay_ms ( 1000 );
}

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.RTC21

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.


rtc21_set_date
err_t rtc21_set_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 set date function.
RTC21_MAP_MIKROBUS
#define RTC21_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: rtc21.h:117
rtc21_cfg_setup
void rtc21_cfg_setup(rtc21_cfg_t *cfg)
RTC 21 configuration object setup function.
rtc21_date_t
RTC 21 Click date object.
Definition: rtc21.h:177
rtc21_set_time
err_t rtc21_set_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 set time function.
rtc21_time_t
RTC 21 Click time object.
Definition: rtc21.h:164
RTC21_SATURDAY
#define RTC21_SATURDAY
Definition: rtc21.h:91
application_task
void application_task(void)
Definition: main.c:91
RTC21_OK
@ RTC21_OK
Definition: rtc21.h:191
rtc21_read_date
err_t rtc21_read_date(rtc21_t *ctx, rtc21_date_t *date)
RTC 21 read date function.
rtc21_cfg_t
RTC 21 Click configuration object.
Definition: rtc21.h:147
application_init
void application_init(void)
Definition: main.c:41
rtc21_t
RTC 21 Click context object.
Definition: rtc21.h:130
rtc21_init
err_t rtc21_init(rtc21_t *ctx, rtc21_cfg_t *cfg)
RTC 21 initialization function.
rtc21_read_time
err_t rtc21_read_time(rtc21_t *ctx, rtc21_time_t *time)
RTC 21 read time function.