一、HAI生成
芯片选STM32F103C8
RCC配置,这个要使能外部低速时钟,SYS配置可以不用变
RTC模块使能时钟源和使能日历,同时将RTC_OUT选择为no rtc output,以及把下面的中断加上
RTC_OUT是是否使能tamper(PC13)引脚上输出校正的秒脉冲时钟。
在parameter setting模块可以初始化时间,也可以选择在代码里初始化时间
要用串口发送信息,所以使能一个usart1
打开keil,直接使用hal库自带的函数输出当前时间,下面是main.c函数代码,记得在target里勾选use microlib
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "rtc.h"
#include "usart.h"
#include "gpio.h"
#include "stdio.h"
int fputc(int ch,FILE *f){
uint8_t temp[1]={
ch};
HAL_UART_Transmit(&huart1,temp,1,2);
return ch;
}
/* Private includes ------------------------------