当前位置: 首页 > news >正文

STM32基于HAL工程读取DS1302时间数据

STM32基于HAL工程读取DS1302时间数据


  • ✨申明:本文章仅发表在CSDN网站,任何其他网站,未注明来源,见此内容均为盗链和爬取,请多多尊重和支持原创!
  • 🍁对于文中所提供的相关资源链接将作不定期更换。
  • 📌相关篇《STM32基于STM32CubeMX读取/设置DS1307》
  • 🎯本工程使用STM32F103VE+DS1302实物验证没有问题。

基于STM32CubeMX配置工程,当然不局限与STM32其他型号的芯片的使用,只要是stm32芯片都可以使用该源文件进行驱动,方便适配移植,减少不必要的重复开发工作。

  • 📜串口打印信息:
    在这里插入图片描述

📓STM32CubeMX配置

  • 🌿只需配置串口,用于读取DS1302数据输出。
    在这里插入图片描述
  • 当然你也可以在STM32CubeMX先指定DS1302引脚。
  • 🔰如果你不想使用系统嘀嗒定时器作为微秒延时函数来时基,可以启用一个定时器。
  • 🔖时钟源根据个人具体的STM32型号自己配置。

🛠KEIL工程配置

  • 🔧usart.c文件中添加printf重映射,并在Keil设置中勾选MicroLib选项。
#include "stdio.h"
/*可调用printf*/
int fputc(int ch,FILE *f)
{/*&huart1指的是串口1,如果用别的串口就修改数字*/HAL_UART_Transmit(&huart1 , (uint8_t *)&ch , 1 , 1000);return ch;
}

📖设置时间到DS1302中

  • 🔨创建一个数组存放当前时间,注意数组下标和时间参数对应关系。
uint8_t	buf[8]={1,23/*年*/,4/*月*/,3/*日*/,17/*时*/,34/*分*/,8/*秒*/,1};
DS1302_WriteTime(buf);

📋DS1302驱动代码

  • 🌿DS1302.h文件
/*
如何使用:
1.根据所使用的控制器替换头文件 "stm32f3xx_hal.h"。我使用的是STM32F103VC。
2.重新分配与芯片连接的端口和引脚(DS1302_GPIO、DS1302_SCLK、DS1302_SDA、DS1302_RST)。
3.在主函数中执行 DS1302_Init();。现在就可以使用了。*/#ifndef _DS1302_H
#define _DS1302_H#include "stm32f1xx_hal.h"
#include "dwt_delay.h"//----------------------------------------------------------------------------------
//将下面列出的端口和引脚根据自己的需求进行重新分配
//----------------------------------------------------------------------------------
#define DS1302_CLK_Pin 	GPIO_PIN_7
#define DS1302_IO_Pin		GPIO_PIN_6
#define DS1302_RST_Pin	GPIO_PIN_4#define DS1302_GPIO				GPIOA
#define DS1302_SCLK				DS1302_CLK_Pin
#define DS1302_SDA				DS1302_IO_Pin
#define DS1302_RST				DS1302_RST_Pin
//存放时间
typedef struct _time
{uint8_t second;uint8_t minute;uint8_t hour;uint8_t date;uint8_t month;uint8_t week;uint8_t year;} DS1302_Time_t;/* 初始化 */
/* 配置 STM32 端口,启动微秒定时器,并将时钟从省电模式唤醒 */
void DS1302_Init(void);/* Reads time byte by byte to 'buf' */
void DS1302_ReadTime(DS1302_Time_t* time);/* Writes time byte by byte from 'buf' */
void DS1302_WriteTime(uint8_t *buf); /* Writes 'val' to ram address 'addr' */
/* Ram addresses range from 0 to 30 */
void DS1302_WriteRam(uint8_t addr, uint8_t val);/* Чтение из RAM по адресу 'addr' */
uint8_t DS1302_ReadRam(uint8_t addr);/* Очистка RAM памяти */
void DS1302_ClearRam(void);/* Reads time in burst mode, includes control byte */
void DS1302_ReadTimeBurst(uint8_t * temp);/* Writes time in burst mode, includes control byte */
void DS1302_WriteTimeBurst(uint8_t * buf);/* Reads ram in burst mode 'len' bytes into 'buf' */
void DS1302_ReadRamBurst(uint8_t len, uint8_t * buf);/* Writes ram in burst mode 'len' bytes from 'buf' */
void DS1302_WriteRamBurst(uint8_t len, uint8_t * buf);//Запуск часов.
void DS1302_ClockStart(void);//Остановка часов.
void DS1302_ClockStop(void);//Сброс часов
void DS1302_ClockClear(void);#endif //_DS1302_H
  • 🌿DS1302.c文件
#include "DS1302.h"// Регистры DS1302
#define DS1302_SEC				0x80
#define DS1302_MIN				0x82
#define DS1302_HOUR				0x84
#define DS1302_DATE				0x86
#define DS1302_MONTH				0x88
#define DS1302_DAY				0x8A
#define DS1302_YEAR				0x8C
#define DS1302_CONTROL				0x8E
#define DS1302_CHARGER				0x90
#define DS1302_CLKBURST				0xBE
#define DS1302_RAMBURST 			0xFE#define RAMSIZE 				0x31	// Размер RAM в байтах
#define DS1302_RAMSTART				0xC0 	// Первый адрес RAM#define HEX2BCD(v)	((v) % 10 + (v) / 10 * 16)
#define BCD2HEX(v)	((v) % 16 + (v) / 16 * 10)// SDA Write(output) Mode
static void writeSDA(void) {GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.Pin = DS1302_SDA;GPIO_InitStructure.Mode =  GPIO_MODE_OUTPUT_PP;GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;HAL_GPIO_Init(DS1302_GPIO, &GPIO_InitStructure);}// SDA Read(input) Mode
static void readSDA(void) {GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.Pin = DS1302_SDA;GPIO_InitStructure.Mode =  GPIO_MODE_INPUT;GPIO_InitStructure.Pull = GPIO_PULLDOWN;GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;HAL_GPIO_Init(DS1302_GPIO, &GPIO_InitStructure);	
}/* Отправка адреса или команды */
static void DS1302_SendCmd(uint8_t cmd) {uint8_t i;for (i = 0; i < 8; i ++) {	//		DS1302_SDA = (bit)(addr & 1);HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA, (cmd & 1) ?  GPIO_PIN_SET :  GPIO_PIN_RESET);//		DS1302_SCK = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_SET);delayUS_DWT(1);//		DS1302_SCK = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_RESET);delayUS_DWT(1);cmd >>= 1;}
}/* Прочитать байт по адресу 'addr' */
static void DS1302_WriteByte(uint8_t addr, uint8_t d)
{uint8_t i;//	DS1302_RST = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_SET);	//addr = addr & 0xFE;DS1302_SendCmd(addr);	// Отправка адресаfor (i = 0; i < 8; i ++) {//		DS1302_SDA = (bit)(d & 1);HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA, (d & 1) ?  GPIO_PIN_SET :  GPIO_PIN_RESET);//		DS1302_SCK = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_SET);delayUS_DWT(1);//		DS1302_SCK = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_RESET);delayUS_DWT(1);d >>= 1;}//	DS1302_RST = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_RESET);//	DS1302_SDA = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA,  GPIO_PIN_RESET);
}/* Sends 'cmd' command and writes in burst mode 'len' bytes from 'temp' */
static void DS1302_WriteBurst(uint8_t cmd, uint8_t len, uint8_t * temp)
{uint8_t i, j;DS1302_WriteByte(DS1302_CONTROL, 0x00);			// Отключить защиту от записи//	DS1302_RST = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_SET);	DS1302_SendCmd(cmd);	// Sends burst write commandfor(j = 0; j < len; j++) {for (i = 0; i < 8; i ++) {//			DS1302_SDA = (bit)(d & 1);HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA, (temp[j] & 1) ?  GPIO_PIN_SET :  GPIO_PIN_RESET);//			DS1302_SCK = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_SET);delayUS_DWT(1);//			DS1302_SCK = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_RESET);delayUS_DWT(1);temp[j] >>= 1;}}//	DS1302_RST = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_RESET);//	DS1302_SDA = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA,  GPIO_PIN_RESET);DS1302_WriteByte(DS1302_CONTROL, 0x80);			// Включить защиту от записи
}/* Reads a byte from addr */
static uint8_t DS1302_ReadByte(uint8_t addr)
{uint8_t i;uint8_t temp = 0;//	DS1302_RST = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_SET);	addr = addr | 0x01; 	// Generate Read AddressDS1302_SendCmd(addr);	// Sends addressreadSDA();for (i = 0; i < 8; i ++) {temp >>= 1;//		if(DS1302_SDA)if(HAL_GPIO_ReadPin(DS1302_GPIO, DS1302_SDA))temp |= 0x80;//		DS1302_SCK = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_SET);delayUS_DWT(1);//		DS1302_SCK = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_RESET);delayUS_DWT(1);}writeSDA();//	DS1302_RST = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_RESET);//	DS1302_SDA = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA,  GPIO_PIN_RESET);return temp;
}/* Sends 'cmd' command and reads in burst mode 'len' bytes into 'temp' */
static void DS1302_ReadBurst(uint8_t cmd, uint8_t len, uint8_t * temp) 
{uint8_t i, j;//	DS1302_RST = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_SET);	cmd = cmd | 0x01; 		// Generate read commandDS1302_SendCmd(cmd);	// Sends burst read commandreadSDA();for (j = 0; j < len; j ++) {temp[j] = 0;for (i = 0; i < 8; i ++) {temp[j] >>= 1;//			if(DS1302_SDA)if(HAL_GPIO_ReadPin(DS1302_GPIO, DS1302_SDA))temp[j] |= 0x80;//			DS1302_SCK = 1;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_SET);delayUS_DWT(1);//			DS1302_SCK = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_RESET);delayUS_DWT(1);}}writeSDA();//	DS1302_RST = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_RESET);HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SDA,  GPIO_PIN_RESET);
}/* Writes time byte by byte from 'buf' */
void DS1302_WriteTime(uint8_t *buf) 
{	DS1302_WriteByte(DS1302_CONTROL, 0x00);			// 解除保护delayUS_DWT(1);DS1302_WriteByte(DS1302_SEC, 0x80);DS1302_WriteByte(DS1302_YEAR, HEX2BCD(buf[1]));DS1302_WriteByte(DS1302_MONTH, HEX2BCD(buf[2]));DS1302_WriteByte(DS1302_DATE, HEX2BCD(buf[3]));DS1302_WriteByte(DS1302_HOUR, HEX2BCD(buf[4]));DS1302_WriteByte(DS1302_MIN, HEX2BCD(buf[5]));DS1302_WriteByte(DS1302_SEC, HEX2BCD(buf[6]));DS1302_WriteByte(DS1302_DAY, HEX2BCD(buf[7]));DS1302_WriteByte(DS1302_CONTROL, 0x80);			// 写保护delayUS_DWT(1);
}/* Reads time byte by byte to 'buf' */
void DS1302_ReadTime(DS1302_Time_t* time)  
{ uint8_t tmp;tmp = DS1302_ReadByte(DS1302_YEAR); 	time->year= BCD2HEX(tmp);		 tmp = DS1302_ReadByte(DS1302_MONTH); 	time->month = BCD2HEX(tmp);	 tmp = DS1302_ReadByte(DS1302_DATE); 	time->date = BCD2HEX(tmp);tmp = DS1302_ReadByte(DS1302_HOUR);		time->hour = BCD2HEX(tmp);tmp = DS1302_ReadByte(DS1302_MIN);		time->minute = BCD2HEX(tmp); tmp = DS1302_ReadByte((DS1302_SEC)) & 0x7F;time->second = BCD2HEX(tmp);tmp = DS1302_ReadByte(DS1302_DAY);		time->week = BCD2HEX(tmp);
}/* DS1302初始化 */
void DS1302_Init(void)
{DWT_Delay_Init(); //初始化计时器以进行毫秒级定时。GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.Pin = DS1302_SCLK | DS1302_SDA | DS1302_RST;GPIO_InitStructure.Mode =  GPIO_MODE_OUTPUT_PP;GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;HAL_GPIO_Init(DS1302_GPIO, &GPIO_InitStructure);DS1302_WriteByte(DS1302_CHARGER, 0x00);			// Отключить Trickle Charger//	DS1302_RST = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_RST,  GPIO_PIN_RESET);//	DS1302_SCK = 0;HAL_GPIO_WritePin(DS1302_GPIO, DS1302_SCLK,  GPIO_PIN_RESET);delayUS_DWT(10); // 不小于10微秒的延时。.DS1302_ClockStart();
}/* Writes 'val' to ram address 'addr' */
/* Ram addresses range from 0 to 30 */
void DS1302_WriteRam(uint8_t addr, uint8_t val) {DS1302_WriteByte(DS1302_CONTROL, 0x00);			// 禁用写入保护delayUS_DWT(1);if (addr >= RAMSIZE) {return;}DS1302_WriteByte(DS1302_RAMSTART + (2 * addr), val);	DS1302_WriteByte(DS1302_CONTROL, 0x80);			// 启用写入保护。delayUS_DWT(1);
}/* Reads ram address 'addr' */
uint8_t DS1302_ReadRam(uint8_t addr) {if (addr >= RAMSIZE) {return 0;}return DS1302_ReadByte(DS1302_RAMSTART + (2 * addr));	
}/* Clears the entire ram writing 0 */
void DS1302_ClearRam(void) {uint8_t i;for(i=0; i< RAMSIZE; i++){DS1302_WriteRam(i, 0x00);}
}/* Reads time in burst mode, includes control byte */
void DS1302_ReadTimeBurst(uint8_t * buf) {uint8_t temp[8] = {0, 0, 0, 0, 0, 0, 0, 0};DS1302_ReadBurst(DS1302_CLKBURST, 8, temp); buf[1] = BCD2HEX(temp[6]);	// Yearbuf[2] = BCD2HEX(temp[4]);	// Monthbuf[3] = BCD2HEX(temp[3]);	// Datebuf[4] = BCD2HEX(temp[2]);	// Hourbuf[5] = BCD2HEX(temp[1]);	// Minbuf[6] = BCD2HEX(temp[0]);	// Secbuf[7] = BCD2HEX(temp[5]);	// Daybuf[0] = temp[7]; 			// Control
}/* Writes time in burst mode, includes control byte */
void DS1302_WriteTimeBurst(uint8_t * buf) {uint8_t temp[8];temp[0]=HEX2BCD(buf[6]);	// Sectemp[1]=HEX2BCD(buf[5]);	// Mintemp[2]=HEX2BCD(buf[4]);	// Hourtemp[3]=HEX2BCD(buf[3]);	// Datetemp[4]=HEX2BCD(buf[2]);	// Monthtemp[5]=HEX2BCD(buf[7]);	// Daytemp[6]=HEX2BCD(buf[1]);	// Yeartemp[7]=buf[0];				// ControlDS1302_WriteBurst(DS1302_CLKBURST, 8, temp); 
}/* Reads ram in burst mode 'len' bytes into 'buf' */
void DS1302_ReadRamBurst(uint8_t len, uint8_t * buf) {uint8_t i;if(len <= 0) {return;}if (len > RAMSIZE) {len = RAMSIZE;}for(i = 0; i < len; i++) {buf[i] = 0;}DS1302_ReadBurst(DS1302_RAMBURST, len, buf);	
}/* Writes ram in burst mode 'len' bytes from 'buf' */
void DS1302_WriteRamBurst(uint8_t len, uint8_t * buf) {if(len <= 0) {return;}if (len > RAMSIZE) {len = RAMSIZE;}DS1302_WriteBurst(DS1302_RAMBURST, len, buf);
}//启动时钟。
//DS1302 最初处于 Halt 模式(已停止,省电模式)。
//为了开始计时,需要执行此函数一次。
void DS1302_ClockStart(void)
{uint8_t buf = 0x00;DS1302_WriteByte(DS1302_CONTROL, 0x00);			// 禁用写入保护。delayUS_DWT(1);buf = DS1302_ReadByte(DS1302_SEC) & 0x7F;		// 写入 8 位中的零的同时,保留当前秒数的值DS1302_WriteByte(DS1302_SEC, buf);DS1302_WriteByte(DS1302_CONTROL, 0x80);			// 启用写入保护。delayUS_DWT(1);
}//停止时钟。
//为了进入 Halt 模式(省电模式),此功能可能并不实用 
void DS1302_ClockStop(void)
{uint8_t buf = 0x00;DS1302_WriteByte(DS1302_CONTROL, 0x00);			// 禁用写入保护delayUS_DWT(1);buf = DS1302_ReadByte(DS1302_SEC) | 0x80;		// 写入 8 位中的1的同时,保留当前秒数的值DS1302_WriteByte(DS1302_SEC, buf);DS1302_WriteByte(DS1302_CONTROL, 0x80);			// 启用写入保护delayUS_DWT(1);
}//重置时钟
//将0写入所有时钟寄存器(从0x80到0x8C)并将 DS1302 传输到 Halt 模式(省电模式)。
//要启动时钟,请使用 DS1302_ClockStart() 函数。
void DS1302_ClockClear(void)
{DS1302_WriteByte(DS1302_CONTROL, 0x00);			// 禁用写入保护delayUS_DWT(1);DS1302_WriteByte(DS1302_SEC, 0x80);				//重置秒并进入 Halt 模式。DS1302_WriteByte(DS1302_MIN, 0x00);DS1302_WriteByte(DS1302_HOUR, 0x00);DS1302_WriteByte(DS1302_DATE, 0x00);DS1302_WriteByte(DS1302_MONTH, 0x00);DS1302_WriteByte(DS1302_DAY, 0x00);DS1302_WriteByte(DS1302_YEAR, 0x00);DS1302_WriteByte(DS1302_CONTROL, 0x80);			// 启用写入保护。delayUS_DWT(1);
}
  • 🌿dwt_delay.c文件
uint32_t DWT_Delay_Init(void) {/* Disable TRC */CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; // ~0x01000000;/* Enable TRC */CoreDebug->DEMCR |=  CoreDebug_DEMCR_TRCENA_Msk; // 0x01000000;/* Disable clock cycle counter */DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; //~0x00000001;/* Enable  clock cycle counter */DWT->CTRL |=  DWT_CTRL_CYCCNTENA_Msk; //0x00000001;/* Reset the clock cycle counter value */DWT->CYCCNT = 0;/* 3 NO OPERATION instructions */__ASM volatile ("NOP");__ASM volatile ("NOP");__ASM volatile ("NOP");/* Check if clock cycle counter has started */if(DWT->CYCCNT){return 0; /*clock cycle counter started*/}else{return 1; /*clock cycle counter not started*/}
}
  • 🌿dwt_delay.h文件
#ifndef DWT_DELAY_H
#define DWT_DELAY_H#ifdef __cplusplus
extern "C" {
#endif#include "stm32f1xx_hal.h"/*** @brief  Initializes DWT_Cycle_Count for DWT_Delay_us function* @return Error DWT counter*         1: DWT counter Error*         0: DWT counter works*/
uint32_t DWT_Delay_Init(void);/*** @brief  This function provides a delay (in microseconds)* @param  microseconds: delay in microseconds*/
__STATIC_INLINE void delayUS_DWT(volatile uint32_t microseconds)
{uint32_t clk_cycle_start = DWT->CYCCNT;/* Go to number of cycles for system */microseconds *= (HAL_RCC_GetHCLKFreq() / 1000000);/* Delay till end */while ((DWT->CYCCNT - clk_cycle_start) < microseconds);
}#ifdef __cplusplus
}
#endif#endif //DWT_DELAY_H

📝main主程序代码

/* USER CODE BEGIN Header */
/********************************************************************************* @file           : main.c* @brief          : Main program body******************************************************************************* @attention** Copyright (c) 2023 STMicroelectronics.* All rights reserved.** This software is licensed under terms that can be found in the LICENSE file* in the root directory of this software component.* If no LICENSE file comes with this software, it is provided AS-IS.********************************************************************************/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "DS1302.h"
/* USER CODE END Includes *//* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD *//* USER CODE END PTD *//* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD *//* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM *//* USER CODE END PM *//* Private variables ---------------------------------------------------------*//* USER CODE BEGIN PV *//* USER CODE END PV *//* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP *//* USER CODE END PFP *//* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 *//* USER CODE END 0 *//*** @brief  The application entry point.* @retval int*/
int main(void)
{/* USER CODE BEGIN 1 */DS1302_Time_t time = {0};
//	uint8_t	buf[8]={23,4,3,14,34,8,1};const char *WEEK[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };/* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_USART1_UART_Init();MX_TIM6_Init();/* USER CODE BEGIN 2 */printf("Hello World \r\n");DWT_Delay_Init();DS1302_Init();
//		DS1302_WriteTime(buf);uint32_t TimerUART = HAL_GetTick();/* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */if ((HAL_GetTick() - TimerUART) > 1500){/* 定义时间结构体 *//* 获取并打印当前时间 */DS1302_ReadTime(&time);printf("Current Time: 20%02d-%02d-%02d %02d:%02d:%02d T=%s \r\n", time.year, time.month, time.date, time.hour, time.minute, time.second, WEEK[time.week]);TimerUART = HAL_GetTick();HAL_GPIO_TogglePin(GPIOE, LED_Pin);}}/* USER CODE END 3 */
}/*** @brief System Clock Configuration* @retval None*/
void SystemClock_Config(void)
{RCC_OscInitTypeDef RCC_OscInitStruct = {0};RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};/** Initializes the RCC Oscillators according to the specified parameters* in the RCC_OscInitTypeDef structure.*/RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;RCC_OscInitStruct.HSEState = RCC_HSE_ON;RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;RCC_OscInitStruct.HSIState = RCC_HSI_ON;RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK){Error_Handler();}/** Initializes the CPU, AHB and APB buses clocks*/RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK){Error_Handler();}
}/* USER CODE BEGIN 4 *//* USER CODE END 4 *//*** @brief  This function is executed in case of error occurrence.* @retval None*/
void Error_Handler(void)
{/* USER CODE BEGIN Error_Handler_Debug *//* User can add his own implementation to report the HAL error return state */__disable_irq();while (1){}/* USER CODE END Error_Handler_Debug */
}#ifdef  USE_FULL_ASSERT
/*** @brief  Reports the name of the source file and the source line number*         where the assert_param error has occurred.* @param  file: pointer to the source file name* @param  line: assert_param error line source number* @retval None*/
void assert_failed(uint8_t *file, uint32_t line)
{/* USER CODE BEGIN 6 *//* User can add his own implementation to report the file name and line number,ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) *//* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

📚工程源码

  • ✨申明:本文章仅发表在CSDN网站,任何其他网站,未注明来源,见此内容均为盗链和爬取,请多多尊重和支持原创!
  • 🍁对于文中所提供的相关资源链接将作不定期更换。
链接: https://pan.baidu.com/s/1VPiYExdvXEcQOXrpDiWnGg
提取码: m7jc

相关文章:

STM32基于HAL工程读取DS1302时间数据

STM32基于HAL工程读取DS1302时间数据✨申明&#xff1a;本文章仅发表在CSDN网站&#xff0c;任何其他网站&#xff0c;未注明来源&#xff0c;见此内容均为盗链和爬取&#xff0c;请多多尊重和支持原创!&#x1f341;对于文中所提供的相关资源链接将作不定期更换。&#x1f4cc…...

《Effective Objective-C 2.0 》 阅读笔记 item10

第10条&#xff1a;在既有类中使用关联对象存放自定义数据 1. 关联对象 可以给某对象关联许多其他对象&#xff0c;这些对象通过“键”来区分&#xff0c;这就是关联对象。存储对象值的时候&#xff0c;可以指明“存储策略”&#xff08;storage policy&#xff09;&#xff…...

gpt3官网中文版-人工智能软件chat gpt安装

GPT-3&#xff08;Generative Pre-trained Transformer 3&#xff09;是一种自然语言处理模型&#xff0c;由OpenAI研发而成。它是GPT系列模型的第三代&#xff0c;也是目前最大、最强大的自然语言处理模型之一&#xff0c;集成了1750亿个参数&#xff0c;具有广泛的使用场景&a…...

工作常用、面试必问:Hive 窗口函数汇总

在SQL中有一类函数叫做聚合函数&#xff0c;例如sum()、avg()、max()等等&#xff0c;这类函数可以将多行数据按照规则聚集为一行&#xff0c;一般来讲聚集后的行数是要少于聚集前的行数的。但是有时我们想要既显示聚集前的数据&#xff0c;又要显示聚集后的数据&#xff0c;这…...

spring5(五):AOP操作

spring5&#xff08;五&#xff09;&#xff1a;AOP操作前言一、代理模式1、场景模拟2、代理模式2.1 概念2.2 静态代理2.3 动态代理二、AOP概述1、什么是 AOP?2、相关术语3、作用三、AOP底层原理1、AOP 底层使用动态代理2、AOP&#xff08;JDK 动态代理&#xff09;2.1 编写 J…...

functional.partial

functional.partial__slots____new__中的cls, /是什么意思&#xff1f;functools.partial这个partial类有什么作用类中没有__init__函数Python 内置的 functools.partial 类的实现。这个类可以用来创建一个新的函数对象&#xff0c;该对象是对一个原有函数的参数进行了部分应用…...

C#缩放PDF文件

项目上有个功能需求&#xff1a;将原PDF进行缩放至原先的90%大小。 使用的是spire.pdf插件&#xff0c;但是官方文档上的缩放只是改变显示&#xff0c;最终文件其实没有缩放成功。遂找到了另外的方式进行重绘。 上代码&#xff1a; using Spire.Pdf; using Spire.Pdf.Graphi…...

【Java面试八股文宝典之MySQL篇】备战2023 查缺补漏 你越早准备 越早成功!!!——Day20

大家好&#xff0c;我是陶然同学&#xff0c;软件工程大三即将实习。认识我的朋友们知道&#xff0c;我是科班出身&#xff0c;学的还行&#xff0c;但是对面试掌握不够&#xff0c;所以我将用这100多天更新Java面试题&#x1f643;&#x1f643;。 不敢苟同&#xff0c;相信大…...

Nsight System的安装和使用

本地安装 官方网站&#xff0c;需要登录 选择Windows Host下载安装 服务器安装 选择Linux CLI .deb下载&#xff0c;上传到服务器之后&#xff0c;执行以下命令&#xff0c;默认会安装在/opt/nvidia/nsight-systems-cli/2023.2.1/target-linux-x64/&#xff0c;nsys在/usr/lo…...

Spring销毁的几种实现

有这3种方法&#xff0c;但是程序执行完成并没有打印出来。一定要手动close.手动执行后会调用如下逻辑&#xff1a;org.springframework.context.support.AbstractApplicationContext#doCloseorg.springframework.context.support.AbstractApplicationContext#destroyBeansorg.…...

【 Spring 核⼼与设计思想 】

文章目录一、Spring 是什么1.1 什么是容器1.2 什么是 IoC二、开发案例对比2.1 传统程序开发2.2 控制反转式程序开发2.3 对⽐总结规律三、理解 Spring IoC四、DI 概念说明五、总结一、Spring 是什么 我们通常所说的 Spring 指的是 Spring Framework&#xff08;Spring 框架&…...

Arrays.sort()——逆序

package utils;import java.util.*;class ComparatorInteger implements Comparator<Integer> {Override //使得逆序 o1比o2小&#xff0c;返回正数——需要调换位置public int compare(Integer o1, Integer o2) {return o1 < o2 ? 1 : -1;} }class Comparato…...

测试2年遇到瓶颈,如何跨过这个坎,实现涨薪5k?

最近和字节跳动的一个老朋友闲聊&#xff0c;感触颇深&#xff0c;据他说公司近期招聘的测试工程师&#xff0c;大多数候选人都有一个“通病”&#xff1a;在工作2-3年的时候遇到瓶颈&#xff0c;而且是一道很难跨越的坎。为什么会遇到这种情况&#xff1f;因为大部分测试工程师…...

骑行团队怎样才能健康运行?

随着生活水平的提高&#xff0c;自行车运动在国内逐渐被人们所接受&#xff0c;也有越来越多的人加入到骑行的行列中。特别是现在骑行团队的兴起&#xff0c;不仅带动了自行车运动的发展&#xff0c;也带动了整个自行车行业的发展。骑行队就是由一群志同道合的车友组成&#xf…...

动力节点王鹤SpringBoot3学习笔记——第四章 访问数据库

目录 第四章 访问数据库 4.1 DataSource 4.2 轻量的JdbcTemplate 4.2.1 准备环境 4.2.1.1 准备数据库和表脚本 4.2.1.2 创建Spring Boot工程 4.2.2 JdbcTemplate访问MySQL 4.2.3 NamedParameterJdbcTemplate 4.2.4 多表查询 4.3 MyBatis 4.3.1 单表CRUD 4.3…...

segno.helpers.make_mecard(Python)

制作名片二维码的&#xff0c;浅浅的mark一下参数的东西。 官方文档是这么写的&#xff1a; segno.helpers.make_mecard(name, readingNone, emailNone, phoneNone, videophoneNone, memoNone, nicknameNone, birthdayNone, urlNone, poboxNone, roomnoNone, housenoNone, ci…...

OBCP第八章 OB运维、监控与异常处理-日常运维操作

白屏&#xff1a; 集群、Zone、Observer 常用运维操作 常用运维操作 运维场景步骤时钟同步 OceanBase从Partition的多个副本中选出主对外提供服务。为避免Paxos的活锁问题&#xff0c;OceanBase 采用一种基于时钟的选举算法选主 检查 NTP 状态&#xff1a;运行 ntpstat 检查 N…...

springboot-gateway注册nacos失败,控制台没有报错

目录 前言现象描述前言 最近springboot的gateway注册到nacos上,没有注册成功 现象描述 我是在common里面引入了nacos的依赖,依赖如下: <dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-confi…...

CLIP:语言-图像表示之间的桥梁

最近GPT4的火爆覆盖了一个新闻&#xff1a;midjourney v5发布&#xff0c;DALLE2&#xff0c;midjourney都可以从文本中生成图像&#xff0c;这种模型要求人工智能同时理解语言和图像数据。 传统的基于人工智能的模型很难同时理解语言和图像。因为自然语言处理和计算机视觉一直…...

failed: open /etc/resolv.conf: no such file or directory“ cause k8s init failed

kubeadm init报错 kubeadm init --config /etc/kubernetes/kubeadm.conf -v 4 --skip-phasesaddon/kube-proxyThis can take up to 4m0s", “[kubelet-check] Initial timeout of 40s passed.”, “”, “\tUnfortunately, an error has occurred:”, “\t\ttimed out wa…...

「科普」如何评价供应商的MES系统

随着制造业的数字化转型&#xff0c;MES系统作为生产信息化的重要组成部分&#xff0c;正在被越来越多的企业采用。然而&#xff0c;在选择供应商时&#xff0c;如何评价供应商的MES系统&#xff0c;成为了制造企业需要面对的一个难题。 首先&#xff0c;评价供应商的MES系统需…...

海康3D轮廓仪调试详细步骤

激光三角测量法 3D激光轮廓仪是基于激光三角测量法(laser triangulation)来重建三维场景。向被测物表面投射激光平面(光片&#xff0c;sheet of light) &#xff0c;通过使用CMOS相机接收其反射光的变化&#xff0c;可以非接触方式测量高度、高度差、宽度等轮廓&#xff08;截面…...

【Linux】PCB(进程控制块)

进程控制块PBC-描述进程号进程状态内存指针PBC-描述 我们知道&#xff0c;进程就是运行起来的代码&#xff0c;而操作系统就是通过对进程进行描述&#xff0c;然后将所有的进程使用双向链表串联到一起&#xff0c;实现对计算机软硬件资源的管理的。 那么&#xff0c;PCB到底是…...

风电的Weibull分布及光电的Beta分布组合研究(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…...

《Effective Objective-C 2.0 》 阅读笔记 item11

第11条&#xff1a;理解objc_msgSend的作用 1. 动态语言特性 在Objective-C中&#xff0c;如果向某对象传递消息&#xff0c;那就会使用动态绑定机制来决定需要调用的方法。在底层&#xff0c;所有方法都是普通的C语言函数&#xff0c;然而对象收到消息之后&#xff0c;究竟该…...

Python常见装饰器使用(实用向)

目录1.staticmethod2.classmethod3、classmethod 与staticmethod比较4. property5.abstractmethod6.wraps7.lru_cache8.timeout9.retrystaticmethod&#xff1a;将一个方法转换为静态方法&#xff0c;可以在不创建类实例的情况下调用。classmethod&#xff1a;将一个方法转换为…...

集合详解之(三)单列集合接口Set及具体子类HashSet、TreeSet

文章目录&#x1f412;个人主页&#x1f3c5;JavaSE系列专栏&#x1f4d6;前言&#xff1a;&#x1f380;Set集合接口&#x1f380;HashSet实现类&#x1f380;TreeSet实现类&#x1fa85;HashSet类常用方法&#xff1a;&#x1fa85;TreeSet类常用方法&#xff1a;&#x1f41…...

力扣刷题笔记22—— 矩阵中的路径(回溯)/pair的学习

矩阵中的路径&#xff08;回溯&#xff09;/pair的学习问题分析示例代码pair学习问题 来自力扣&#xff1a; 给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 单词必须按…...

Spring学习1

一、Spring简介 Spring翻译过来就是春天的意思&#xff0c;其实也就是给软件行业带来了春天2002年&#xff0c;首次推出Spring框架的雏形&#xff0c;interface21框架Spring框架就是以interface21框架为基础&#xff0c;经过重新设计&#xff0c;并不断丰富&#xff0c;在2004年…...

Keep再闯IPO,三年亏损16亿,会员留存率跌破70%

“运动科技第一股”来了&#xff1f; 3月28日&#xff0c;线上健身平台的运营方、北京卡路里科技有限公司&#xff08;下称“Keep”&#xff09;更新招股书&#xff0c;再次闯关港股IPO。 Keep是一家在线健身平台&#xff0c;主要产品包括在线健身内容、智能健身设备和配套运…...