找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6001|回复: 5
打印 上一主题 下一主题
收起左侧

BL5372-USB功能RTC时钟程序源码电路板原理图和PCB工程文件

[复制链接]
跳转到指定楼层
楼主
BL5372-USB功能RTC时钟电路板AD格式的电路原理图和PCB工程:

Demo演示用的固件(程序),出货前已经烧录好,给PCBA通电即可工作!

如果您需要再次烧录,请按此HEX文件进行烧录即可。

烧录工具一般用 ST-LINK/V2, 或者J-LINK都可以!

R8、R9两者只能焊接一个
焊接R8则选择IIC接口
焊接R9则选择SPI接口

stm32程序源码:
  1. /*

  2. 作者:紫电青霜


  3. */


  4. /*Includes ------------------------------------------------------------------*/
  5. #include "main.h"
  6. #include "stm32f0xx_hal.h"
  7. #include "usb_device.h"
  8. #include "BL5372_IIC.h"
  9. #include "usbd_cdc_if.h"


  10. uint8_t  RRTCiic_buf[16];
  11. uint8_t  RRTCiic_Buf_Out[26]={0x32,0x30,0x31,0x37,0xC4,0xEA,0x30,0x32,0xD4,0xC2,
  12.                              0x32,0x35,0xC8,0xD5,0x32,0x32,0x3A,0x35,0x36,0x3A,0x00,0x00,0x0D,0x0A,0x0D,0x0A};


  13.                                                                                                        
  14. extern unsigned char Set_Year ;       
  15. extern unsigned char Set_Month ;       
  16. extern unsigned char Set_Day ;       
  17. extern unsigned char Set_Hour ;       
  18. extern unsigned char Set_Minute ;       
  19. extern unsigned char Set_Second ;                                                                                                                         
  20.                                                                                                                  
  21. uint8_t   Rec_buff[18]={0};



  22. /* Private variables ---------------------------------------------------------*/
  23. SPI_HandleTypeDef hspi1;



  24. /* Private function prototypes -----------------------------------------------*/
  25. void SystemClock_Config(void);
  26. void Error_Handler(void);
  27. static void MX_GPIO_Init(void);
  28. static void MX_SPI1_Init(void);
  29. void My_GPIO_Init(void);


  30. unsigned char  DataStr[]=__DATE__;
  31. unsigned char  TimeStr[]=__TIME__;
  32. extern uint8_t UserRxBufferFS[];

  33. int main(void)
  34. {
  35.   unsigned char i=0;
  36.         unsigned char Miao_mark = 0;

  37.                


  38.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  39.   HAL_Init();

  40.   /* Configure the system clock */
  41.   SystemClock_Config();

  42.   /* Initialize all configured peripherals */
  43.   MX_GPIO_Init();
  44.   MX_SPI1_Init();
  45.   MX_USB_DEVICE_Init();
  46.         IIC_Init();
  47.        
  48.         My_GPIO_Init();
  49.         if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_7) == 0)//读取PB7管脚的电平,为低电平,则初始化BL5372时间
  50.         {
  51.                 BL5372_init();
  52.         }

  53.   while (1)
  54.   {
  55.                
  56.                
  57.                         HAL_Delay(50);


  58.                         if(UserRxBufferFS[0] == 'S'  && UserRxBufferFS[1] == 'T'  && UserRxBufferFS[10] == 'F' && UserRxBufferFS[11] == 'N' )
  59.                         {
  60.                                 CDC_Transmit_FS("设置年月日\r\n",12);
  61.                                 Set_Year = ((UserRxBufferFS[4]-0x30)<<4)+(UserRxBufferFS[5]-0x30);
  62.                                 Set_Month = ((UserRxBufferFS[6]-0x30)<<4)+(UserRxBufferFS[7]-0x30);
  63.                                 Set_Day = ((UserRxBufferFS[8]-0x30)<<4)+(UserRxBufferFS[9]-0x30);
  64.                                 BL5372_init();
  65.                         }
  66.                         else if(UserRxBufferFS[0] == 'S'  && UserRxBufferFS[1] == 'T'  && UserRxBufferFS[8] == 'F' && UserRxBufferFS[9] == 'I' )
  67.                         {
  68.                                 CDC_Transmit_FS("设置时分秒\r\n",12);
  69.                                 Set_Hour = ((UserRxBufferFS[2]-0x30)<<4)+(UserRxBufferFS[3]-0x30);
  70.                                 Set_Minute = ((UserRxBufferFS[4]-0x30)<<4)+(UserRxBufferFS[5]-0x30);
  71.                                 Set_Second = ((UserRxBufferFS[6]-0x30)<<4)+(UserRxBufferFS[7]-0x30);
  72.                                 BL5372_init();
  73.                         }
  74.                        

  75.                                 for(i=0;i<18;i++)
  76.                                 {
  77.                                         UserRxBufferFS[i] = 0;
  78.                                 }

  79. //                                        HAL_Delay(5);
  80.                                         BL5372_Read(0x00,RRTCiic_buf,7);
  81.                                         if(RRTCiic_buf[0] != Miao_mark)
  82.                                         {

  83.                                                                 //秒
  84.                                                                 RRTCiic_Buf_Out[20] = ((RRTCiic_buf[0]>>4)&0x0f) +0x30;
  85.                                                                 RRTCiic_Buf_Out[21] = (RRTCiic_buf[0]&0x0f) +0x30;
  86.                                                                
  87.                                                                 //分
  88.                                                                 RRTCiic_Buf_Out[17] = ((RRTCiic_buf[1]>>4)&0x0f) +0x30;
  89.                                                                 RRTCiic_Buf_Out[18] = (RRTCiic_buf[1]&0x0f) +0x30;
  90.                                                        
  91.                                                                 //时
  92.                                                                 RRTCiic_Buf_Out[14] = ((RRTCiic_buf[2]>>4)&0x0f) +0x30;
  93.                                                                 RRTCiic_Buf_Out[15] = (RRTCiic_buf[2]&0x0f) +0x30;       

  94.                                                                 //日
  95.                                                                 RRTCiic_Buf_Out[10] = ((RRTCiic_buf[4]>>4)&0x0f) +0x30;
  96.                                                                 RRTCiic_Buf_Out[11] = (RRTCiic_buf[4]&0x0f) +0x30;
  97.                                                                
  98.                                                                 //月
  99.                                                                 RRTCiic_Buf_Out[6] = ((RRTCiic_buf[5]>>4)&0x0f) +0x30;
  100.                                                                 RRTCiic_Buf_Out[7] = (RRTCiic_buf[5]&0x0f) +0x30;
  101.                                                        
  102.                                                                 //年
  103.                                                                 RRTCiic_Buf_Out[2] = ((RRTCiic_buf[6]>>4)&0x0f) +0x30;
  104.                                                                 RRTCiic_Buf_Out[3] = (RRTCiic_buf[6]&0x0f) +0x30;       



  105.                                                         CDC_Transmit_FS((uint8_t *)RRTCiic_Buf_Out,26);
  106.                                        
  107.                                         }
  108.                                         Miao_mark = RRTCiic_buf[0] ;
  109.                                         for(i=0;i<16;i++)
  110.                                         {
  111.                                                 RRTCiic_buf[i] = 0;
  112.                                         }
  113.   }
  114.   /* USER CODE END 3 */

  115. }

  116. /** System Clock Configuration
  117. */
  118. void SystemClock_Config(void)
  119. {

  120.   RCC_OscInitTypeDef RCC_OscInitStruct;
  121.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  122.   RCC_PeriphCLKInitTypeDef PeriphClkInit;

  123.     /**Initializes the CPU, AHB and APB busses clocks
  124.     */
  125.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
  126.   RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  127.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  128.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  129.   {
  130.     Error_Handler();
  131.   }

  132.     /**Initializes the CPU, AHB and APB busses clocks
  133.     */
  134.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  135.                               |RCC_CLOCKTYPE_PCLK1;
  136.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
  137.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  138.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

  139.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  140.   {
  141.     Error_Handler();
  142.   }

  143.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
  144.   PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;

  145.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  146.   {
  147.     Error_Handler();
  148.   }

  149.     /**Configure the Systick interrupt time
  150.     */
  151.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  152.     /**Configure the Systick
  153.     */
  154.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  155.   /* SysTick_IRQn interrupt configuration */
  156.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  157. }

  158. /* SPI1 init function */
  159. static void MX_SPI1_Init(void)
  160. {

  161.   hspi1.Instance = SPI1;
  162.   hspi1.Init.Mode = SPI_MODE_MASTER;
  163.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  164.   hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
  165.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  166.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  167.   hspi1.Init.NSS = SPI_NSS_SOFT;
  168.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  169.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  170.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  171.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  172.   hspi1.Init.CRCPolynomial = 7;
  173.   hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  174.   hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  175.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  176.   {
  177.     Error_Handler();
  178.   }

  179. }

  180. /** Pinout Configuration
  181. */
  182. static void MX_GPIO_Init(void)
  183. {

  184.   /* GPIO Ports Clock Enable */
  185.   __HAL_RCC_GPIOA_CLK_ENABLE();

  186. }





  187. void My_GPIO_Init(void)
  188. {                                             
  189.                 GPIO_InitTypeDef GPIO_InitStruct;
  190.          __HAL_RCC_GPIOB_CLK_ENABLE();
  191.           
  192.           /*Configure GPIO pin : PB7 */
  193.   GPIO_InitStruct.Pin = GPIO_PIN_7 ;
  194.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;//输入
  195.   GPIO_InitStruct.Pull = GPIO_PULLUP;//上拉输入
  196.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  197.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  198.        
  199.        

  200. }

  201. /* USER CODE BEGIN 4 */

  202. /* USER CODE END 4 */

  203. /**
  204.   * @brief  This function is executed in case of error occurrence.
  205.   * @param  None
  206.   * @retval None
  207.   */
  208. void Error_Handler(void)
  209. {
  210.   /* USER CODE BEGIN Error_Handler */
  211.   /* User can add his own implementation to report the HAL error return state */
  212.   while(1)
  213.   {
  214.   }
  215.   /* USER CODE END Error_Handler */
  216. }

  217. #ifdef USE_FULL_ASSERT

  218. /**
  219.    * @brief Reports the name of the source file and the source line number
  220.    * where the assert_param error has occurred.
  221.    * @param file: pointer to the source file name
  222.    * @param line: assert_param error line source number
  223.    * @retval None
  224.    */
  225. void assert_failed(uint8_t* file, uint32_t line)
  226. {
  227.   /* USER CODE BEGIN 6 */
  228.   /* User can add his own implementation to report the file name and line number,
  229.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  230.   /* USER CODE END 6 */

  231. }


  232. #endif

  233. /**
  234.   * @}
  235.   */

  236. /**
  237.   * @}
  238. */

  239. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

下载:
BL5372-USB功能RTC时钟电路板原理图和PCB.zip (17.33 MB, 下载次数: 58)
BL5372.pdf (144.14 KB, 下载次数: 37)
RTC时钟电路板程序源码.zip (3.63 MB, 下载次数: 88)



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:326234 发表于 2018-5-9 20:05 | 只看该作者
这个资源很好啊,准备弄BL5372
回复

使用道具 举报

板凳
ID:464148 发表于 2019-1-7 21:28 | 只看该作者
看下BL5372源码
回复

使用道具 举报

地板
ID:714984 发表于 2020-3-24 18:34 | 只看该作者
很不错的帖子,正好用到BL5372,这个帖子里的源码可以参考一下。
回复

使用道具 举报

5#
ID:545576 发表于 2021-8-7 12:33 | 只看该作者
感谢分享,测试一下,替代缺货的3231
回复

使用道具 举报

6#
ID:834913 发表于 2022-4-18 15:21 | 只看该作者
在使用BL5372的时候有遇到时钟不准的问题(大约四个小时走快一秒) 楼主有什么解决方法吗
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表