中级
30 分钟

通过将DS1343与STM32L496AG结合,解锁时间的秘密

RTC:数字时代中时间的可靠守护者

RTC 12 Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

RTC 12 Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

优化您的工程项目,通过高效的实时时钟,为关键操作提供可靠和准确的时间记录。

A

A

硬件概览

它是如何工作的?

RTC 12 Click 基于 DS1343,这是一款低电流实时时钟(RTC),消耗极低的时间记录电流,从而延长来自模拟设备的备用电源的寿命。该设备通过简单的串行接口提供全二进制编码的十进制时钟日历。时钟/日历提供秒、分、小时、天、日期、月份和年份的信息。月份结束日期会自动调整,以适应少于31天的月份,包括对2099年前的闰年的修正。时钟可以在24小时或12小时格式下工作,并带有AM/PM指示。在此Click板™上,最常见的配置是电池备份RTC,保持时间并可在提供的数据存储的96字节非易失

性RAM中保存数据。除了DS1343,RTC 12 Click还配备了一个与3000TR电池座兼容的纽扣电池座,适用于12毫米纽扣电池。此外,它具有内置的温度补偿电源感应电路,能够检测电源故障并自动切换到备用电源,从而允许不间断运行。DS1343通过支持模式1和3的标准SPI串行接口与MCU通信,最大频率为4 MHz。它还提供两个可编程的每日报警。每个报警都可以在INT pin上根据秒、分、小时和天的可编程组合生成中断。通过将标记为INT SEL的SMD跳线设置到适当位置,可以选择中断。两个中断输

出在设备由mikroBUS™电源轨或备用电源电压供电时都能工作。除了上述功能外,用户还可以使用另一个指示器,该指示器通过mikroBUS™插座上的AN引脚标记为PF,以指示来自mikroBUS™电源轨的主电源VCC的丧失。该Click板™可以通过VCC SEL跳线选择以3.3V或5V逻辑电压等级工作。这样,3.3V和5V的MCU都可以正确使用通信线路。此外,该Click板™配备了包含易于使用的功能库和示例代码,可作为进一步开发的参考。

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

功能概述

开发板

32L496GDISCOVERY Discovery 套件是一款功能全面的演示和开发平台,专为搭载 Arm® Cortex®-M4 内核的 STM32L496AG 微控制器设计。该套件适用于需要在高性能、先进图形处理和超低功耗之间取得平衡的应用,支持无缝原型开发,适用于各种嵌入式解决方案。STM32L496AG 采用创新的节能架构,集成

了扩展 RAM 和 Chrom-ART 图形加速器,在提升图形性能的同时保持低功耗,使其特别适用于音频处理、图形用户界面和实时数据采集等对能效要求较高的应用。为了简化开发流程,该开发板配备了板载 ST-LINK/V2-1 调试器/编程器,提供即插即用的调试和编程体验,使用户无需额外硬件即可轻松加载、调

试和测试应用程序。凭借低功耗特性、增强的内存能力以及内置调试工具,32L496GDISCOVERY 套件是开发先进嵌入式系统、实现高效能解决方案的理想选择。

Discovery kit with STM32L496AG MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32L496AG Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

STMicroelectronics

引脚数

169

RAM (字节)

327680

使用的MCU引脚

mikroBUS™映射器

Power-Fail Indicator
PA4
AN
NC
NC
RST
SPI Chip Select
PG11
CS
SPI Clock
PI1
SCK
SPI Data OUT
PD3
MISO
SPI Data IN
PI3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PH2
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

RTC 12 Click Schematic schematic

一步一步来

项目组装

Discovery kit with STM32H750XB MCU front image hardware assembly

从选择您的开发板和Click板™开始。以Discovery kit with STM32L496AG MCU作为您的开发板开始。

Discovery kit with STM32H750XB MCU front image hardware assembly
Thermo 21 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product7 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
Discovery kit with STM32H750XB MCU NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

软件支持

库描述

该库包含 RTC 12 Click 驱动程序的 API。

关键功能:

  • rtc12_set_time - RTC 12 设置时间功能

  • rtc12_get_time - RTC 12 获取时间功能

  • rtc12_get_date - RTC 12 获取日期功能

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @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 );
     }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

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

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。