初学者
10 分钟

使用DS1307和PIC32MZ2048EFM100掌握时间管理

在各种电子应用中跟踪时间

RTC 2 Click with Curiosity PIC32 MZ EF

已发布 6月 26, 2024

点击板

RTC 2 Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

紧凑的时间跟踪解决方案,能够保持准确的时间记录,适用于物联网、可穿戴设备、数据记录和工业设备等应用。

A

A

硬件概览

它是如何工作的?

RTC 2 Click 基于 Analog Devices 的 DS1307,这是一款 64x8 串行 I2C 实时时钟。它是一款低功耗的完整二进制编码的十进制(BCD)时钟/日历,带有 56 字节的非易失性静态随机存取存储器(NV SRAM)。月底会自动调整适应少于 31 天的月份,包括闰年的更正。该时钟可以以 24 小时或 12 小时格式运行,并

带有 AM/PM 指示器。RTC 内置电源感应电路,当检测到电源故障时会自动切换到备用电源。RTC 2 配备了一块 3V/230mA 的锂电池,确保在主电源断电时仍能继续保持时间。RTC 2 Click 通过 I2C 两线接口与主控 MCU 通信,时钟频率最高可达 400kHz。此 Click 板™的中断 INT 引脚可输出四种方波频率之一

(1Hz、4kHz、8kHz 和 32kHz)。启用时,它会根据配置位中设置的值输出频率。此 Click 板™ 只能在 5V 逻辑电压水平下运行。在使用具有不同逻辑水平的 MCU 之前,板必须进行适当的逻辑电压水平转换。此外,这个 Click 板™ 配备了一个库,其中包含易于使用的功能和示例代码,可以用作进一步开发的参考。

RTC 2 Click hardware overview image

功能概述

开发板

Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE 

mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口

来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。

Curiosity PIC32MZ EF double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RF13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RPA14
SCL
I2C Data
RPA15
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

RTC 2 Click Schematic schematic

一步一步来

项目组装

Curiosity PIC32MZ EF front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity PIC32 MZ EF作为您的开发板开始。

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image 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
Curiosity PIC32 MZ EF 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

软件支持

库描述

此库包含 RTC 2 Click 驱动程序的 API。

关键功能:

  • rtc2_read_byte - 通用读取字节数据的功能

  • rtc2_write_byte - 通用写入字节数据的功能

  • rtc2_enable_counting - 启用计数功能

开源

代码示例

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

/*!
 * \file 
 * \brief Rtc6 Click example
 * 
 * # Description
 * This application enables usage of Real-TIme clock and calendar with alarm on RTC 6 Click.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver init, sets time zone, sets UTC-GMT time and alarm time
 * 
 * ## Application Task  
 * Reads GMT time and Local time. Checks if the alarm is activated. 
 * If the alarm is active, it disable alarm and adjusts the new one within 20 seconds.
 * Logs this data on USBUART every 900ms.
 * 
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "rtc6.h"

// ------------------------------------------------------------------ VARIABLES

static rtc6_t rtc6;
static log_t logger;
static rtc6_time_t utc_time;
static rtc6_time_t alarm_time;
static rtc6_time_t local_time;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    rtc6_cfg_t cfg;
    int8_t time_zone = 2;

    /** 
     * 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.

    rtc6_cfg_setup( &cfg );
    RTC6_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    rtc6_init( &rtc6, &cfg );

    // Set UTC time

    utc_time.seconds  = 40;
    utc_time.minutes  = 59;
    utc_time.hours    = 23;
    utc_time.monthday = 14;
    utc_time.month    = 12;
    utc_time.year     = 18;
    
    // Set alarm time
    
    alarm_time.seconds  = 0;
    alarm_time.minutes  = 0;
    alarm_time.hours    = 0;
    alarm_time.weekdays  = 0;
    alarm_time.monthday = 15;
    alarm_time.month    = 12;
    alarm_time.year     = 18;

    rtc6_default_cfg( &rtc6, time_zone, &utc_time, &alarm_time );
    log_info( &logger, " ----- Init successfully ----- " );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

void application_task ( void )
{
    //  Task implementation.

    rtc6_get_gmt_time( &rtc6, &utc_time );
    rtc6_get_local_time( &rtc6, &local_time );
    
    log_printf( &logger, "--- UTC time ---\r\nTime : %u %u %u\r\n", ( uint16_t )utc_time.hours, ( uint16_t )utc_time.minutes, ( uint16_t )utc_time.seconds );
    
    log_printf( &logger, "Date : %u %u %u\r\n", ( uint16_t )utc_time.monthday, ( uint16_t )utc_time.month, utc_time.year );
    
    log_printf( &logger, "--- Local time ---\r\nTime : %u %u %u\r\n", ( uint16_t )local_time.hours, ( uint16_t )local_time.minutes, ( uint16_t )local_time.seconds );

    log_printf( &logger, "Date : %u %u %u\r\n \r\n", ( uint16_t )local_time.monthday, ( uint16_t )local_time.month, local_time.year );
    
    if ( rtc6_is_active_alarm( &rtc6 ) != 0 )
    {
        log_printf( &logger, " ----- Active alarm ----- \r\n" );
        rtc6_disable_alarm( &rtc6, RTC6_ALARM_0 );
        rtc6_repeat_alarm( &rtc6, RTC6_ALARM_0, 20 );
    }

    Delay_ms ( 900 );
}

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

额外支持

资源

喜欢这个项目吗?

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