Intermediate
30 min

Unlock the secrets of time with DS1343 combined with PIC32MZ1024EFH064

RTC: Time's trusted guardians in the digital age

RTC 12 Click with PIC32MZ clicker

Published Oct 21, 2023

Click board™

RTC 12 Click

Dev Board

PIC32MZ clicker

Compiler

NECTO Studio

MCU

PIC32MZ1024EFH064

Optimize your engineering projects with efficient real-time clock, delivering reliable and accurate timekeeping for critical operations

A

A

Hardware Overview

How does it work?

RTC 12 Click is based on the DS1343, a low-current RTC that consumes an extremely low timekeeping current, permitting longer life from a backup supply source from Analog Devices. The devices provide a full binary-coded decimal clock calendar accessed by a simple serial interface. The clock/calendar provides information on seconds, minutes, hours, days, dates, months, and years. The month's end date is automatically adjusted for months with fewer than 31 days, including corrections for the leap year through 2099. The clock operates in either a 24-hour or 12-hour format with an AM/PM indicator. As performed on this Click board™, the most common configuration is a battery-backed-up RTC, which maintains time and may hold data in 96 bytes of NV RAM provided for data storage. In addition to

the DS1343, the RTC 12 Click is equipped with a button cell battery holder compatible with the 3000TR battery holder, suitable for 12mm Coin Cell batteries. Furthermore, it has a built-in temperature-compensated power-sense circuit that detects power failures and automatically switches to the backup supply, thus allowing for uninterrupted operation. The DS1343 communicates with MCU using the standard SPI serial interface that supports modes 1 and 3 with a maximum frequency of 4 MHz. It also provides two programmable time-of-day alarms. Each alarm can generate an interrupt on a programmable combination of seconds, minutes, hours, and days, available on the INT pin of the mikroBUS™ socket. The interrupt selection can be made by positioning the SMD jumper labeled INT SEL to an

appropriate position. Both interrupt outputs operate when the device is powered by mikroBUS™ power rails or backup supply voltage. In addition to the features mentioned above, the user can use another indicator routed to the AN pin of the mikroBUS™ socket labeled as PF to indicate a loss of a primary power supply, VCC, from mikroBUS™ power rails. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

RTC 12 Click top side image
RTC 12 Click bottom side image

Features overview

Development board

PIC32MZ Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller with FPU from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access anywhere and under

any circumstances. Each part of the PIC32MZ Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the PIC32MZ Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current, which is more than enough to operate all onboard

and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. PIC32MZ Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

PIC32MZ clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

1024

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

Power-Fail Indicator
RE4
AN
NC
NC
RST
SPI Chip Select
RG9
CS
SPI Clock
RG6
SCK
SPI Data OUT
RG7
MISO
SPI Data IN
RG8
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RB5
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

RTC 12 Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the PIC32MZ clicker as your development board.

PIC32MZ clicker front image hardware assembly
Thermo 26 Click front image hardware assembly
Prog-cut hardware assembly
Micro B Connector clicker - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

After loading the code example, pressing the "DEBUG" button builds and programs it on the selected setup.

Application Output Step 1

After programming is completed, a header with buttons for various actions available in the IDE appears. By clicking the green "PLAY "button, we start reading the results achieved with Click board™.

Application Output Step 3

Upon completion of programming, the Application Output tab is automatically opened, where the achieved result can be read. In case of an inability to perform the Debug function, check if a proper connection between the MCU used by the setup and the CODEGRIP programmer has been established. A detailed explanation of the CODEGRIP-board connection can be found in the CODEGRIP User Manual. Please find it in the RESOURCES section.

Application Output Step 4

Software Support

Library Description

This library contains API for RTC 12 Click driver.

Key functions:

  • rtc12_set_time - RTC 12 set time function

  • rtc12_get_time - RTC 12 get time function

  • rtc12_get_date - RTC 12 get date function

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief Rtc12 Click example
 *
 * # Description
 * This is an example that demonstrates the use of the RTC 12 click board™.
 * 
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of SPI module, log UART and additional pins.
 * After driver initialization and default settings,
 * the app set the time to 23:59:50 and set the date to 27.05.'21.
 *
 * ## Application Task
 * This is an example that shows the use of a RTC 12 click board™.
 * In this example, we read and display the current time and date, 
 * which we also previously set.
 * Results are being sent to the Usart Terminal where you can track their changes.
 * All data logs write on USB changes every 1 sec.
 *
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "rtc12.h"

static rtc12_t rtc12;
static log_t logger;

static uint8_t new_sec = 255;
static rtc12_time_t time;
static rtc12_date_t date;


void application_init ( void ) {
    log_cfg_t log_cfg;      /**< Logger config object. */
    rtc12_cfg_t rtc12_cfg;   /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.

    rtc12_cfg_setup( &rtc12_cfg );
    RTC12_MAP_MIKROBUS( rtc12_cfg, MIKROBUS_1 );
    err_t init_flag  = rtc12_init( &rtc12, &rtc12_cfg );
    if ( init_flag == SPI_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    rtc12_default_cfg ( &rtc12 );
    log_info( &logger, " Application Task " );
    Delay_ms( 100 );
    
    date.day_of_week = 4;
    date.day = 27;
    date.month = 5;
    date.year = 21;
    rtc12_set_date( &rtc12, date );
    Delay_ms( 100 );
    
    time.hours = 23;
    time.min = 59;
    time.sec = 50;
    rtc12_set_time( &rtc12, time );
    Delay_ms( 100 );
}

void application_task ( void ) {   
    rtc12_get_time( &rtc12, &time );
    Delay_ms( 1 );
    rtc12_get_date( &rtc12, &date );
    Delay_ms( 1 );
    
    if ( time.sec != new_sec ) {
        log_printf( &logger, "  Date      : %.2d-%.2d-%.2d\r\n", ( uint16_t ) date.day, ( uint16_t ) date.month, ( uint16_t ) date.year );
        log_printf( &logger, "  Time      : %.2d:%.2d:%.2d\r\n", ( uint16_t ) time.hours, ( uint16_t ) time.min, ( uint16_t ) time.sec );
        log_printf( &logger, "- - - - - - - - - - - -\r\n" );
        new_sec = time.sec;
        Delay_ms( 1 );
     }
}

void main ( void ) {
    application_init( );

    for ( ; ; ) {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.