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

相关推荐
宵时待雨1 天前
STM32笔记归纳8:时钟
笔记·stm32·单片机·嵌入式硬件
JJRainbow1 天前
SN75176 芯片设计RS-232 转 RS-485 通信模块设计原理图
stm32·单片机·嵌入式硬件·fpga开发·硬件工程
宁静致远20211 天前
STM32模拟IIC读取PCF8563
stm32·单片机·嵌入式硬件
三佛科技-134163842121 天前
宠物洗澡打泡机方案,宠物泡泡机MCU方案开发设计分享
单片机·嵌入式硬件·物联网·智能家居·pcb工艺·宠物
芯岭技术1 天前
低成本315/433M接收芯片 XL420 SOP8封装,支持 1527 等常见 OOK编码
单片机·嵌入式硬件
Wangshanjie_981 天前
【通讯协议】-01、Modbus协议
单片机·信息与通信
听风吹雨yu1 天前
STM32F407-MD5码计算/Digest认证计算
stm32·单片机·嵌入式硬件
yugi9878381 天前
RN8302B电表芯片驱动开发指南(基于SPI通信)
驱动开发·单片机·嵌入式硬件
youcans_1 天前
【STM32-MBD】(15)Simulink 模型开发之三相互补 PWM
stm32·单片机·嵌入式硬件·matlab·foc
我是一棵无人问荆的小草1 天前
STM32标准库与HAL库编程差异分析
stm32·单片机·嵌入式硬件