[MCU] 瑞萨RA4M2开发板评测-OLED显示RTC时间

[复制链接]
 楼主| lrj2024 发表于 2025-5-29 16:51 | 显示全部楼层 |阅读模式

本次参加瑞萨活动,非常荣幸获得瑞萨RA4M2开发板一块。
如下图所示:



本开发板资源丰富,如下介绍。
特性:
1个复位按键
2个用户按键
2个触摸按键
3个LED
2个PMOD接口
板载USB转TTL模块,可用于串口通信和烧录
板载SWD接口,方便用户调试与下载
支持 TrustZone 的 100MHz Arm Cortex-M33
安全芯片的功能
512kB 闪存、64kB SRAM(支持奇偶校验)以及 64kB ECC SRAM
8KB 数据闪存,提供与 EEPROM 类似的数据存储功能
1kB 休眠用 SRAM
100 引脚封装
电容式触摸传感单元 (CTSU)
全速 USB 2.0,支持主机模式和设备模式
CAN 2.0B
四线 SPI
SCI(UART、简单 SPI、简单 I2C)
独立SPI/I2C 多主接口
SDHI 和 MMC


对我而言,接触的不多,所以要好好学习一下。
本次实现OLED驱动,显示RTC时间。
效果如下所示:


开发环境:
采用e2stduio。管脚分配采用 FSP


主代码实现
  1. #include "hal_data.h"
  2. #include "oled.h"
  3. FSP_CPP_HEADER
  4. void R_BSP_WarmStart(bsp_warm_start_event_t event);
  5. FSP_CPP_FOOTER

  6. i2c_master_event_t i2c_event = I2C_MASTER_EVENT_ABORTED;
  7. void sci_i2c_master_callback(i2c_master_callback_args_t *p_args)
  8. {
  9.     i2c_event = I2C_MASTER_EVENT_ABORTED;
  10.     if (NULL != p_args)
  11.     {
  12.         /* capture callback event for validating the i2c transfer event*/
  13.         i2c_event = p_args->event;
  14.     }
  15. }

  16. fsp_err_t err = FSP_SUCCESS;
  17. int  timeout_ms = 100;

  18. /* rtc_time_t is an alias for the C Standard time.h struct 'tm' */
  19. rtc_time_t set_time =
  20. {
  21.     .tm_sec  = 8,      /* 秒,范围从 0 到 59 */
  22.     .tm_min  = 8,      /* 分,范围从 0 到 59 */
  23.     .tm_hour = 12,      /* 小时,范围从 0 到 23*/
  24.     .tm_mday = 30,       /* 一月中的第几天,范围从 1 到 31*/
  25.     .tm_mon  = 06,      /* 月份,范围从 0 到 11*/
  26.     .tm_year = 122,     /* 自 1900 起的年数,2021为121*/
  27. //    .tm_wday = 5,       /* 一周中的第几天,范围从 0 到 6*/
  28. //    .tm_yday=0,         /* 一年中的第几天,范围从 0 到 365*/
  29. //    .tm_isdst=0;        /* 夏令时*/
  30. };

  31. volatile bool rtc_flag = 0;//RTC延时1s标志位
  32. /* Callback function */
  33. void rtc_callback(rtc_callback_args_t *p_args)
  34. {
  35.     /* TODO: add your own code here */
  36.     if(p_args->event == RTC_EVENT_PERIODIC_IRQ)
  37.         rtc_flag=1;
  38. }

  39. void hal_entry(void)
  40. {
  41.     /* TODO: add your own code here */

  42.     /* Initialize the RTC module*/
  43.        err = R_RTC_Open(&g_rtc0_ctrl, &g_rtc0_cfg);
  44.        /* Handle any errors. This function should be defined by the user. */
  45.        assert(FSP_SUCCESS == err);
  46.        /* R_RTC_CalendarTimeSet must be called at least once to start the RTC */
  47.        R_RTC_CalendarTimeSet(&g_rtc0_ctrl, &set_time);
  48.        /* Set the periodic interrupt rate to 1 second */
  49.        R_RTC_PeriodicIrqRateSet(&g_rtc0_ctrl, RTC_PERIODIC_IRQ_SELECT_1_SECOND);

  50.        uint8_t rtc_second= 8;      //秒
  51.        uint8_t rtc_minute =8;      //分
  52.        uint8_t rtc_hour =12;         //时
  53.        uint8_t rtc_day =30;          //日
  54.        uint8_t rtc_month =06;      //月
  55.        uint16_t rtc_year =122;        //年
  56.        uint8_t rtc_week =0;        //周
  57.        rtc_time_t get_time;

  58.         /* IIC初始化*/
  59.         err = R_SCI_I2C_Open(&g_i2c0_ctrl, &g_i2c0_cfg);
  60.         assert(FSP_SUCCESS == err);
  61.         WriteCmd();//OLED初始化
  62.         OLED_Clear();//清屏

  63.         OLED_ShowString(16,1,"RA",16);
  64.         OLED_ShowCHinese(32,1,3);//生
  65.         OLED_ShowCHinese(48,1,4);//态
  66.         OLED_ShowCHinese(64,1,5);//工
  67.         OLED_ShowCHinese(80,1,6);//作
  68.         OLED_ShowCHinese(96,1,7);//室
  69.         OLED_ShowCHinese(40,5,0);//年
  70.         OLED_ShowCHinese(72,5,1);//月
  71.         OLED_ShowCHinese(104,5,2);//日
  72.         OLED_ShowString(32,3,"11:11:11",16);

  73.         while(1)
  74.             {
  75.                 if(rtc_flag)
  76.                 {
  77.                     R_RTC_CalendarTimeGet(&g_rtc0_ctrl, &get_time);//获取RTC计数时间
  78.                     rtc_flag=0;
  79.                     rtc_second=get_time.tm_sec;//秒
  80.                     rtc_minute=get_time.tm_min;//分
  81.                     rtc_hour=get_time.tm_hour;//时
  82.                     rtc_day=get_time.tm_mday;//日
  83.                     rtc_month=get_time.tm_mon;//月
  84.                     rtc_year=get_time.tm_year; //年
  85.                     rtc_week=get_time.tm_wday;//周
  86.                 }
  87.                     OLED_ShowNum(8,5,rtc_year+1900,4,16);//年
  88.                     OLED_ShowNum(56,5,rtc_month,2,16);//月
  89.                     OLED_ShowNum(88,5,rtc_day,2,16);//日
  90.                     OLED_ShowNum(32,3,rtc_hour,2,16);//时
  91.                     OLED_ShowNum(56,3,rtc_minute,2,16);//分
  92.                     OLED_ShowNum(80,3,rtc_second,2,16);//秒

  93.             }

  94. #if BSP_TZ_SECURE_BUILD
  95.     /* Enter non-secure code */
  96.     R_BSP_NonSecureEnter();
  97. #endif
  98. }
  99. /*******************************************************************************************************************//**
  100. * This function is called at various points during the startup process.  This implementation uses the event that is
  101. * called right before main() to set up the pins.
  102. *
  103. * @param[in]  event    Where at in the start up process the code is currently at
  104. **********************************************************************************************************************/
  105. void R_BSP_WarmStart(bsp_warm_start_event_t event)
  106. {
  107.     if (BSP_WARM_START_RESET == event)
  108.     {
  109. #if BSP_FEATURE_FLASH_LP_VERSION != 0

  110.         /* Enable reading from data flash. */
  111.         R_FACI_LP->DFLCTL = 1U;

  112.         /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
  113.          * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
  114. #endif
  115.     }

  116.     if (BSP_WARM_START_POST_C == event)
  117.     {
  118.         /* C runtime environment and system clocks are setup. */

  119.         /* Configure pins. */
  120.         R_IOPORT_Open (&g_ioport_ctrl, g_ioport.p_cfg);
  121.     }
  122. }

  123. #if BSP_TZ_SECURE_BUILD

  124. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();

  125. /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
  126. BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
  127. {

  128. }
  129. #endif


编译成功提示:


运行视频如附件所示。


特别注意:
VBAT需要接VCC哦。否则时间不动哦。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

22

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部