S32DS for S32 Platform RTC输出时间

1、添加RTC组件

右键项目找到"S32 Configuration Tools"--》"Open Peripherals"进入外设组件界面

选择Drivers搜索"rtc",添加完后双击rtc_1,配置rtc参数,更新代码

2、RTC初始化

c 复制代码
  /* Initialize RTC instance
   *  - See RTC configuration component for options
   */
  RTC_DRV_Init(0, &rtc_1InitCfg0);
  /* Configure RTC Time Seconds Interrupt */
  RTC_DRV_ConfigureSecondsInt(0, &rtc_1SecIntCfg0);
  /* Set the time and date */
  RTC_DRV_SetTimeDate(0, &rtc_1InitCfg0_StartTime);
  /* Start the RTC counter */
  RTC_DRV_StartCounter(0);

3、中断函数

c 复制代码
//如果在配置RTC参数时启动了"Alarm"中断和"Seconds"中断

/* Alarm interrupt handler */
void alarmISR(void * callbackParam)
{	
	//到设定的时间则会进入此中断
	rtc_timedate_t Scurrent_time,tempTime;

	RTC_DRV_GetCurrentTimeDate(0, &tempTime);
	Scurrent_time=tempTime;
	Scurrent_time.day +=1;
	RTC_DRV_StopCounter(0);
	RTC_DRV_SetTimeDate(0, &Scurrent_time);
	RTC_DRV_StartCounter(0);
	RTC_DRV_GetCurrentTimeDate(0, &tempTime);

	x1=1;

}

/* Time Seconds interrupt handler */
void secondsISR(void * callbackParam)
{
	//每秒进入一次
	x++;
}

4、main函数

下面是我的main函数,程序里面开启uart,rtc功能;所有在main函数进行了对应的初始化;在循环中判断x1;如果x1等于1则获取当前时间并输出到uart,并将x1置0

c 复制代码
int main(void)
{
  status_t error;
  /* Configure clocks for PORT */
  error = CLOCK_DRV_Init(&clockMan1_InitConfig0);
  DEV_ASSERT(error == STATUS_SUCCESS);
  /* Set pins as GPIO */
  error = PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
  DEV_ASSERT(error == STATUS_SUCCESS);

  /* Initialize LPUART instance */
  LPUART_DRV_Init(1, &lpUartState0, &lpuart_0_InitConfig0);
  /* Install the callback for rx events */
  LPUART_DRV_InstallRxCallback(1, rxCallback, NULL);
  LPUART_DRV_ReceiveData(1, (uint8_t *)rx_data, 1U);

  /* Initialize RTC instance
   *  - See RTC configuration component for options
   */
  RTC_DRV_Init(0, &rtc_1InitCfg0);
  /* Configure RTC Time Seconds Interrupt */
  RTC_DRV_ConfigureSecondsInt(0, &rtc_1SecIntCfg0);
  /* Set the time and date */
  RTC_DRV_SetTimeDate(0, &rtc_1InitCfg0_StartTime);
  /* Start the RTC counter */
  RTC_DRV_StartCounter(0);

  for (;;)
  {
	  LPUART_DRV_ReceiveData(1, (uint8_t *)rx_data, 1U);

	  if(x1==1){
		  rtc_timedate_t tempTime;
		  RTC_DRV_GetCurrentTimeDate(0,&tempTime);
		  uint8_t* Ctime=currentTimetoString(&tempTime);//时间转字符串
		  LPUART_DRV_SendDataBlocking(1,(uint8_t *)Ctime,strlen(Ctime),500U);
		  x1=0;
	  }
  }
}

5、整个RTC程序

https://download.csdn.net/download/weixin_46516921/92578566

相关推荐
FreakStudio11 天前
W55MH32L-EVB 上手测评:硬件 TCP/IP 加持的以太网单片机,MicroPython 零门槛开发
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy·电子计算机
ifndef13 天前
GPIO同时复用(ADC与TIM)
mcu
✎ ﹏梦醒͜ღ҉繁华落℘16 天前
单片机基础知识---stm32单片机的优先级
stm32·单片机·mongodb
zd84510150016 天前
RS485 总线详解
单片机·嵌入式硬件
✎ ﹏梦醒͜ღ҉繁华落℘16 天前
编程基础 --高内聚,低耦合
c语言·单片机
科芯创展16 天前
1A,1MHz,30VIN,XZ4115,降压恒流LED驱动芯片
单片机·嵌入式硬件
集芯微电科技有限公司16 天前
四通道2A输出集成功率电感降压模块专为紧凑型方案设计
人工智能·单片机·嵌入式硬件·生成对抗网络·计算机外设
踏着七彩祥云的小丑16 天前
嵌入式测试学习第 37 天:异常场景测试:断电、拔插、干扰、非法指令
单片机·嵌入式硬件·学习
意法半导体STM3216 天前
【官方原创】如何为STM32CubeMX2配置Visual Studio Code配置方案
vscode·stm32·单片机·嵌入式硬件·策略模式·stm32cubemx·嵌入式开发
雾削木17 天前
B语言经典教程现代化重构
java·前端·stm32·单片机·嵌入式硬件