中级
30 分钟

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

滴答,滴答!

RTC 18 Click with Curiosity Nano with PIC18F57Q43

已发布 6月 24, 2024

点击板

RTC 18 Click

开发板

Curiosity Nano with PIC18F57Q43

编译器

NECTO Studio

微控制器单元

PIC18F57Q43

与 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

功能概述

开发板

PIC18F57Q43 Curiosity Nano 评估套件是一款尖端的硬件平台,旨在评估 PIC18-Q43 系列内的微控制器。其设计的核心是包含了功能强大的 PIC18F57Q43 微控制器(MCU),提供先进的功能和稳健的性能。这个评估套件的关键特点包括一个黄 色用户 LED 和一个响应灵敏的机械用户开关,提供无

缝的交互和测试。为一个 32.768kHz 水晶振荡器足迹提供支持,确保精准的定时能力。套件内置的调试器拥有一个绿色电源和状态 LED,使编程和调试变得直观高效。此外,增强其实用性的还有虚拟串行端口 (CDC)和一个调试 GPIO 通道(DGI GPIO),提供广泛的连接选项。该套件通过 USB 供电,拥有由

 MIC5353 LDO 调节器提供支持的可调目标电压功能,确保在 1.8V 至 5.1V 的输出电压范围内稳定运行,最大输出电流为 500mA,受环境温度和电压限制。

PIC18F57Q43 Curiosity Nano double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC

MCU 内存 (KB)

128

硅供应商

Microchip

引脚数

48

RAM (字节)

8196

你完善了我!

配件

Curiosity Nano Base for Click boards 是一款多功能硬件扩展平台,专为简化 Curiosity Nano 套件与扩展板之间的集成而设计,特别针对符合 mikroBUS™ 标准的 Click 板和 Xplained Pro 扩展板。这款创新的基板(屏蔽板)提供了无缝的连接和扩展可能性,简化了实验和开发过程。主要特点包括从 Curiosity Nano 套件提供 USB 电源兼容性,以及为增强灵活性而提供的另一种外部电源输入选项。板载锂离子/锂聚合物充电器和管理电路确保电池供电应用的平稳运行,简化了使用和管理。此外,基板内置了一个固定的 3.3V 电源供应单元,专用于目标和 mikroBUS™ 电源轨,以及一个固定的 5.0V 升压转换器,专供 mikroBUS™ 插座的 5V 电源轨,为各种连接设备提供稳定的电力供应。

Curiosity Nano Base for Click boards accessories 1 image

使用的MCU引脚

mikroBUS™映射器

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

“仔细看看!”

Click board™ 原理图

RTC 18 Click Schematic schematic

一步一步来

项目组装

Curiosity Nano Base for Click boards front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity Nano with PIC18F57Q43作为您的开发板开始。

Curiosity Nano Base for Click boards front image hardware assembly
Barometer 13 Click front image hardware assembly
PIC18F57Q43 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Curiosity Nano with PICXXX MB 1 - 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
PIC18F57Q43 Curiosity 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

额外支持

资源

喜欢这个项目吗?

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