中级
30 分钟

使用RV-3032-C7和ATmega328获取您需要的完美计时

滴答,滴答!

RTC 18 Click with Arduino UNO Rev3

已发布 6月 24, 2024

点击板

RTC 18 Click

开发板

Arduino UNO Rev3

编译器

NECTO Studio

微控制器单元

ATmega328

与 RV-3032-C7 一起告别时间不准确性——这款实时时钟能让您保持准时。

A

A

硬件概览

它是如何工作的?

RTC 18 Click 基于 Micro Crystal AG 公司的 RV-3032-C7,这是一款专为低功耗操作而优化的高精度实时时钟/日历模块。RV-3032-C7 内置有 32.768kHz 的“音叉”晶振和 HF 振荡器,以及用于秒、分、时、日期、月、年和星期几的计数器。其温度补偿电路经过出厂校准,使其在整个温度范围内具有 ±2.5ppm 的最高时间精度,并具有额外的非易失性老化偏移校正。这个实时时钟还配备了一个集成的数字温度计,用于实际内部温度测量,精度为 ±1°C,分辨率为 0.0625°C/步,还具有可编程的上下温度限制报警功能。除了所有这些特性,它还支持自动闰年校正。当年份的最后两位数是 4 的倍数时,日历年将自动被识别为闰年。因

此,直到 2099 年的闰年可以自动被识别。这个 Click board™ 使用标准的 I2C 2 线接口与 MCU 进行通信,以读取数据和配置设置,支持最高 400kHz 的快速模式操作。它还包含一个配置为生成周期倒计时定时器和周期时间更新(秒、分钟)、日期/小时/分钟报警以及在 mikroBUS™ 插座上的 CS 引脚上注册的外部事件的中断信号的报警电路。一个报警(中断)信号通过路由到 mikroBUS™ 插座的 INT 引脚,允许在每天或特定日(由标记为 ALARM 的红色 LED 可视指示)进行可视化报警输出。RV-3032-C7 还包括一个自动备份切换电路,允许它与单个纽扣电池一起使用以延长使用时间。这个功能可以通过将标记为 BATT 

SEL 的 SMD 跳线放置在标记为 OFF 或 ON 的适当位置来激活。除了自动备份切换电路,它还具有一个带有充电泵的涓流充电器,提供完整的实时时钟功能,具有可编程的计数器、报警、可选择的中断和可编程时钟输出功能,频率范围从 1Hz 到 52MHz,可在标记为 CLKO 的板载头上获得。该 Click board™ 可以使用通过 VCC SEL 跳线选择的 3.3V 或 5V 逻辑电压电平进行操作。这样,既可以使 3.3V 又可以使 5V 的 MCU 正确使用通信线。然而,该 Click board™ 配备了一个包含易于使用的函数和示例代码的库,可用作进一步开发的参考。

RTC 18 Click top side image
RTC 18 Click bottom side image

功能概述

开发板

Arduino UNO 是围绕 ATmega328P 芯片构建的多功能微控制器板。它为各种项目提供了广泛的连接选项,具有 14 个数字输入/输出引脚,其中六个支持 PWM 输出,以及六个模拟输入。其核心组件包括一个 16MHz 的陶瓷谐振器、一个 USB 连接器、一个电

源插孔、一个 ICSP 头和一个复位按钮,提供了为板 子供电和编程所需的一切。UNO 可以通过 USB 连接到计算机,也可以通过 AC-to-DC 适配器或电池供电。作为第一个 USB Arduino 板,它成为 Arduino 平台的基准,"Uno" 符号化其作为系列首款产品的地

位。这个名称选择,意为意大利语中的 "一",是为了 纪念 Arduino Software(IDE)1.0 的推出。最初与 Arduino Software(IDE)版本1.0 同时推出,Uno 自此成为后续 Arduino 发布的基础模型,体现了该平台的演进。

Arduino UNO Rev3 double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

AVR

MCU 内存 (KB)

32

硅供应商

Microchip

引脚数

32

RAM (字节)

2048

你完善了我!

配件

Click Shield for Arduino UNO 具有两个专有的 mikroBUS™ 插座,使所有 Click board™ 设备能够轻松与 Arduino UNO 板进行接口连接。Arduino UNO 是一款基于 ATmega328P 的微控制器开发板,为用户提供了一种经济实惠且灵活的方式来测试新概念并构建基于 ATmega328P 微控制器的原型系统,结合了性能、功耗和功能的多种配置选择。Arduino UNO 具有 14 个数字输入/输出引脚(其中 6 个可用作 PWM 输出)、6 个模拟输入、16 MHz 陶瓷谐振器(CSTCE16M0V53-R0)、USB 接口、电源插座、ICSP 头和复位按钮。大多数 ATmega328P 微控制器的引脚都连接到开发板左右两侧的 IO 引脚,然后再连接到两个 mikroBUS™ 插座。这款 Click Shield 还配备了多个开关,可执行各种功能,例如选择 mikroBUS™ 插座上模拟信号的逻辑电平,以及选择 mikroBUS™ 插座本身的逻辑电压电平。此外,用户还可以通过现有的双向电平转换电压转换器使用任何 Click board™,无论 Click board™ 运行在 3.3V 还是 5V 逻辑电压电平。一旦将 Arduino UNO 板与 Click Shield for Arduino UNO 连接,用户即可访问数百种 Click board™,并兼容 3.3V 或 5V 逻辑电压电平的设备。

Click Shield for Arduino UNO accessories 1 image

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
External Event Interrupt
PB2
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

RTC 18 Click Schematic schematic

一步一步来

项目组装

Click Shield for Arduino UNO front image hardware assembly

从选择您的开发板和Click板™开始。以Arduino UNO Rev3作为您的开发板开始。

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product8 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
Arduino UNO 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

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

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

关键功能:

  • rtc18_read_time - 这个函数读取当前的时间值 - 秒、分钟和小时。

  • rtc18_read_date - 这个函数读取当前的日期值 - 星期几、日期、月份和年份。

  • rtc18_read_temperature - 这个函数读取摄氏度的温度测量值。

开源

代码示例

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

/*!
 * @file main.c
 * @brief RTC18 Click example
 *
 * # Description
 * This example demonstrates the use of RTC 18 click board by reading and displaying
 * the time and date values as well as the temperature measurements in Celsius.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and logger and performs the click default configuration
 * which enables the periodic interrupt on seconds count-up, and sets the starting time and date.
 *
 * ## Application Task
 * Waits for the second count-up interrupt and then reads and displays on the USB UART 
 * the current time and date values as well as the temperature measurements in Celsius.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "rtc18.h"

static rtc18_t rtc18;
static log_t logger;
static rtc18_time_t time;
static rtc18_date_t date;

/**
 * @brief RTC 18 get day of week name function.
 * @details This function returns the name of day of the week as a string.
 * @param[in] ctx : Click context object.
 * See #rtc18_t object definition for detailed explanation.
 * @param[in] day_of_week : Day of week decimal value.
 * @return Name of day as a string.
 * @note None.
 */
static char *rtc18_get_day_of_week_name ( uint8_t day_of_week );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    rtc18_cfg_t rtc18_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.
    rtc18_cfg_setup( &rtc18_cfg );
    RTC18_MAP_MIKROBUS( rtc18_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == rtc18_init( &rtc18, &rtc18_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( RTC18_ERROR == rtc18_default_cfg ( &rtc18 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    time.hour = 23;
    time.minute = 59;
    time.second = 50;
    if ( RTC18_OK == rtc18_set_time ( &rtc18, &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 = RTC18_SATURDAY;
    date.day = 31;
    date.month = 12;
    date.year = 22;
    if ( RTC18_OK == rtc18_set_date ( &rtc18, &date ) )
    {
        log_printf( &logger, " Set date: %s, %.2u.%.2u.20%.2u.\r\n", 
                    rtc18_get_day_of_week_name ( date.day_of_week ),
                    ( uint16_t ) date.day, ( uint16_t ) date.month, ( uint16_t ) date.year );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float temperature;
    
    // Wait for a second count-up interrupt
    while ( rtc18_get_int_pin ( &rtc18 ) );
    
    Delay_ms ( 10 );
    rtc18_clear_periodic_interrupt ( &rtc18 );
    
    if ( RTC18_OK == rtc18_read_time ( &rtc18, &time ) )
    {
        log_printf( &logger, " Time: %.2u:%.2u:%.2u\r\n", 
                    ( uint16_t ) time.hour, ( uint16_t ) time.minute, ( uint16_t ) time.second );
    }
    if ( RTC18_OK == rtc18_read_date ( &rtc18, &date ) )
    {
        log_printf( &logger, " Date: %s, %.2u.%.2u.20%.2u.\r\n", 
                    rtc18_get_day_of_week_name ( date.day_of_week ),
                    ( uint16_t ) date.day, ( uint16_t ) date.month, ( uint16_t ) date.year );
    }
    if ( RTC18_OK == rtc18_read_temperature ( &rtc18, &temperature ) )
    {
        log_printf( &logger, " Temperature: %.2f C\r\n\n", temperature );
    }
}

void main ( void ) 
{
    application_init( );

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

static char *rtc18_get_day_of_week_name ( uint8_t day_of_week )
{
    switch ( day_of_week )
    {
        case RTC18_MONDAY:
        {
            return "Monday";
        }
        case RTC18_TUESDAY:
        {
            return "Tuesday";
        }
        case RTC18_WEDNESDAY:
        {
            return "Wednesday";
        }
        case RTC18_THURSDAY:
        {
            return "Thursday";
        }
        case RTC18_FRIDAY:
        {
            return "Friday";
        }
        case RTC18_SATURDAY:
        {
            return "Saturday";
        }
        case RTC18_SUNDAY:
        {
            return "Sunday";
        }
        default:
        {
            return "Unknown";
        }
    }
}

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

额外支持

资源

喜欢这个项目吗?

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