diff --git a/Lib/README.md b/Lib/README.md index 34c094b..c0c1e50 100644 --- a/Lib/README.md +++ b/Lib/README.md @@ -1,3 +1,4 @@ ### 本目录为各种外设驱动库,部分驱动库之间存在依赖关系,会在下面有所说明 -#### 1.QMI8658依赖I2C_Driver \ No newline at end of file +#### 1. QMI8658依赖I2C_Driver +#### 2. PCF85063依赖I2C_Driver \ No newline at end of file diff --git a/main/Bionic_sphere.c b/main/Bionic_sphere.c index bb6d25a..9f81be0 100644 --- a/main/Bionic_sphere.c +++ b/main/Bionic_sphere.c @@ -13,5 +13,6 @@ void app_main(void) // wireless_test(); - sd_card_module_test(); + // sd_card_module_test(); + pcf85063_test(); } diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index deaefd5..af97089 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -5,6 +5,7 @@ idf_component_register(SRCS "Bionic_sphere.c" "../Lib/BAT_Driver/BAT_Driver.c" # 电池adc驱动库 "../Lib/Wireless/Wireless.c" # 无线通信驱动库 "../Lib/SD_Card/SD_MMC.c" # SD卡驱动库 + "../Lib/PCF85063/PCF85063.c" # RTC驱动库 INCLUDE_DIRS "." "../test/driver_test" "../Lib/I2C_Driver" @@ -12,6 +13,7 @@ idf_component_register(SRCS "Bionic_sphere.c" "../Lib/BAT_Driver" "../Lib/Wireless" "../Lib/SD_Card" + "../Lib/PCF85063" PRIV_REQUIRES # 私有依赖 driver bt diff --git a/test/driver_test/drivers_test.c b/test/driver_test/drivers_test.c index 7151ae6..4d78b98 100644 --- a/test/driver_test/drivers_test.c +++ b/test/driver_test/drivers_test.c @@ -133,4 +133,63 @@ void sd_card_module_test(void) } printf("\n=== SD卡模块测试完成 ===\n"); +} + + +#include "PCF85063.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +static const char *TAG = "PCF85063_TEST"; +void pcf85063_test(void) +{ + /* 1. 初始化 I2C 与 PCF85063 */ + I2C_Init(); // 初始化 ESP32 I2C 外设 + PCF85063_Init(); // 配置 PCF85063 进入 24h 模式、RTC 启动 + ESP_LOGI(TAG, "PCF85063 初始化完成"); + + /* 2. 设置当前系统时间(示例:2025-08-24 周日 14:30:00)*/ + datetime_t set_time = { + .year = 2025, + .month = 8, + .day = 24, + .dotw = 0, // 0 表示星期日 + .hour = 14, + .minute = 30, + .second = 0 + }; + PCF85063_Set_All(set_time); + ESP_LOGI(TAG, "已设置时间:2025-08-24 14:30:00"); + + /* 3. 设置闹钟(示例:14:31:15 触发一次)*/ + datetime_t alarm_time = { + .hour = 14, + .minute = 31, + .second = 15, + /* 日/星期字段无需关心,已在 PCF85063_Set_Alarm 中屏蔽 */ + }; + PCF85063_Set_Alarm(alarm_time); + PCF85063_Enable_Alarm(); // 使能闹钟中断并清除 AF 标志 + ESP_LOGI(TAG, "已设置闹钟:14:31:15"); + + /* 4. 周期性读取时间与检查闹钟标志位 */ + char str_buf[64]; + while (true) + { + /* 4.1 读取当前时间 */ + datetime_t now; + PCF85063_Read_Time(&now); + datetime_to_str(str_buf, now); + ESP_LOGI(TAG, "当前时间:%s", str_buf); + + /* 4.2 检查闹钟标志位 */ + uint8_t flag = PCF85063_Get_Alarm_Flag(); + if (flag & RTC_CTRL_2_AF) + { + ESP_LOGI(TAG, "闹钟触发!AF=1"); + /* 如需重复闹钟,可在此重新设置新时间或清除 AF 后再次使能 */ + PCF85063_Enable_Alarm(); // 清除 AF 并重新使能 + } + + vTaskDelay(pdMS_TO_TICKS(1000)); // 每秒读一次 + } } \ No newline at end of file diff --git a/test/driver_test/drivers_test.h b/test/driver_test/drivers_test.h index 4a4de5b..c81f8c8 100644 --- a/test/driver_test/drivers_test.h +++ b/test/driver_test/drivers_test.h @@ -17,5 +17,8 @@ void wireless_test(void); // SD卡测试 void sd_card_module_test(void); +// RTC测试 +void pcf85063_test(void); + #endif //BIONIC_SPHERE_DRIVERS_TEST_H \ No newline at end of file diff --git a/项目开发日志.md b/项目开发日志.md index 536af9f..5e4f1cd 100644 --- a/项目开发日志.md +++ b/项目开发日志.md @@ -101,5 +101,9 @@ ) ``` +- [x] 6. 测试了外部高精度RTC(PCF85063)的驱动,时钟功能正常,测试通过 + ```text + 驱动位置位于:Lib/PCF85063 + ```