你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

基于STM32F103C8T6内部时钟作为系统时钟经验分享

[复制链接]
攻城狮Melo 发布时间:2023-5-1 17:15
首先说明一下芯片内部并没有时钟, 而是内部振荡。使用内部振荡的好处是外部无需设计晶振电路 ,再说的简单点 ,不用外部晶振依然可以让单片机正常运转。书归正传 直接开始配置打开任意keli工程 3abfd84a31744e26becb5fac0ecf553d.png 打开system_stm32f10x.c 15651841425044cfb9c3695a9017a21f.png 找到systeminit函数 全部注释掉 51791e66d6cb45ddabcd4982bac9425b.png 然后在下面粘贴以下代码(这段代码来自CSDN的一位大佬,我不是原作者)直接替换就可以用了
  1. #define  USE_HSI   1                        // 是否使用内部晶振  0 不使用  1使用
  2. void SystemInit ( void )
  3. {
  4. #if USE_HSI
  5.     {
  6. //设置使用内部晶振
  7.         /* 开启HSI 即内部晶振时钟 */
  8.         RCC->CR |= ( uint32_t ) 0x00000001;
  9.         /*选择HSI为PLL的时钟源HSI必须2分频给PLL*/
  10.         RCC->CFGR |= ( uint32_t ) RCC_CFGR_PLLSRC_HSI_Div2;
  11.         /*PLLCLK=8/2*9=36MHz  设置倍频得到时钟源PLL的频率*/
  12.         RCC->CFGR |= ( uint32_t ) RCC_CFGR_PLLMULL6;                         //设置倍频后的频率
  13.         /* PLL不分频输出 ?*/
  14.         RCC->CFGR |= ( uint32_t ) RCC_CFGR_HPRE_DIV1;
  15.         /* 使能 PLL时钟 */
  16.         RCC->CR |= RCC_CR_PLLON;
  17.         /* 等待PLL时钟就绪*/
  18.         while ( ( RCC->CR & RCC_CR_PLLRDY ) == 0 )
  19.         {
  20.         }
  21.         /* 选择PLL为系统时钟的时钟源 */
  22.         RCC->CFGR &= ( uint32_t ) ( ( uint32_t ) ~ ( RCC_CFGR_SW ) );
  23.         RCC->CFGR |= ( uint32_t ) RCC_CFGR_SW_PLL;
  24.         /* 等到PLL成为系统时钟的时钟源*/
  25.         while ( ( RCC->CFGR & ( uint32_t ) RCC_CFGR_SWS ) != ( uint32_t ) 0x08 )
  26.         { }
  27.     }
  28. #else
  29.     {
  30. //设置使用外部8M晶振
  31.         /* Reset the RCC clock configuration to the default reset state(for debug purpose) */
  32.         /* Set HSION bit */
  33.         RCC->CR |= ( uint32_t ) 0x00000001;
  34.         /* Reset SW, HPRE, PPRE1, PPRE2, ADCPRE and MCO bits */
  35. #ifndef STM32F10X_CL
  36.         RCC->CFGR &= ( uint32_t ) 0xF8FF0000;
  37. #else
  38.         RCC->CFGR &= ( uint32_t ) 0xF0FF0000;
  39. #endif /* STM32F10X_CL */
  40.         /* Reset HSEON, CSSON and PLLON bits */
  41.         RCC->CR &= ( uint32_t ) 0xFEF6FFFF;
  42.         /* Reset HSEBYP bit */
  43.         RCC->CR &= ( uint32_t ) 0xFFFBFFFF;
  44.         /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE/OTGFSPRE bits */
  45.         RCC->CFGR &= ( uint32_t ) 0xFF80FFFF;
  46. #ifdef STM32F10X_CL
  47.         /* Reset PLL2ON and PLL3ON bits */
  48.         RCC->CR &= ( uint32_t ) 0xEBFFFFFF;
  49.         /* Disable all interrupts and clear pending bits  */
  50.         RCC->CIR = 0x00FF0000;
  51.         /* Reset CFGR2 register */
  52.         RCC->CFGR2 = 0x00000000;
  53. #elif defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
  54.         /* Disable all interrupts and clear pending bits  */
  55.         RCC->CIR = 0x009F0000;
  56.         /* Reset CFGR2 register */
  57.         RCC->CFGR2 = 0x00000000;
  58. #else
  59.         /* Disable all interrupts and clear pending bits  */
  60.         RCC->CIR = 0x009F0000;
  61. #endif /* STM32F10X_CL */
  62. #if defined (STM32F10X_HD) || (defined STM32F10X_XL) || (defined STM32F10X_HD_VL)
  63. #ifdef DATA_IN_ExtSRAM
  64.         SystemInit_ExtMemCtl();
  65. #endif /* DATA_IN_ExtSRAM */
  66. #endif
  67.         /* Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers */
  68.         /* Configure the Flash Latency cycles and enable prefetch buffer */
  69.         SetSysClock();
  70. #ifdef VECT_TAB_SRAM
  71.         SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
  72. #else
  73.         SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
  74. #endif
  75.     }
  76. #endif
  77. }
复制代码
然后我简单拉高/低是试了一下引脚的电压 是正常的 大家可以去试试————————————————版权声明:文某9如有侵权请联系删除
收藏 评论0 发布时间:2023-5-1 17:15

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版