换晶振导致stm32串口数据飞码的解决办法(补充)

今天(2014.4.21)把stm32f107的程序下载到stm32f103的板子上,发现串口收不到数据,突然想起晶振频率没有修改,#define HSE_VALUE    ((uint32_t)13560000) /*!< Value of the External oscillator in Hz */ 这个要改回去,因为外接晶振是8M
之后试验,发现有数据,但是乱码。百思不得其解,无意中发现,PC的波特率设置为9600,板子的波特率设置为19200就不会乱码。刚好是2倍的关系。顺藤摸瓜问度娘!一个帖子也是这种情况,一个回答是“问题解决了,把target options里#define里的STM32F10X_HD_VL改成STM32F10X_MD就正常了(我用的是中密度器件)”,楼下有人说:
看库里面的stm32f10x.h文件,里面很多内容与系统时钟的配置有关。该文件会根据选择的芯片类型来进行时钟配置,要在此位置将选用的芯片类型去掉注释符。当然不想每次修改此文件,比较方便的方法就是你所说是在编译器的target options选项框中define。。。效果一样。


我翻开那个头文件
#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL) 
  /* #define STM32F10X_LD */     /*!< STM32F10X_LD: STM32 Low density devices */
  /* #define STM32F10X_LD_VL */  /*!< STM32F10X_LD_VL: STM32 Low density Value Line devices */  
   /*#define STM32F10X_MD */    /*!< STM32F10X_MD: STM32 Medium density devices */
  /* #define STM32F10X_MD_VL */  /*!< STM32F10X_MD_VL: STM32 Medium density Value Line devices */  
  /* #define STM32F10X_HD */     /*!< STM32F10X_HD: STM32 High density devices */
  /* #define STM32F10X_HD_VL */  /*!< STM32F10X_HD_VL: STM32 High density value line devices */  
  /* #define STM32F10X_XL */     /*!< STM32F10X_XL: STM32 XL-density devices */
  /* #define STM32F10X_CL */     /*!< STM32F10X_CL: STM32 Connectivity line devices */
#endif
/*  Tip: To avoid modifying this file each time you need to switch between these
        devices, you can define the device in your toolchain compiler preprocessor.
 - Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
   where the Flash memory density ranges between 16 and 32 Kbytes.
 - Low-density value line devices are STM32F100xx microcontrollers where the Flash
   memory density ranges between 16 and 32 Kbytes.
 - Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers
   where the Flash memory density ranges between 64 and 128 Kbytes.
 - Medium-density value line devices are STM32F100xx microcontrollers where the 
   Flash memory density ranges between 64 and 128 Kbytes.   
 - High-density devices are STM32F101xx and STM32F103xx microcontrollers where
   the Flash memory density ranges between 256 and 512 Kbytes.
 - High-density value line devices are STM32F100xx microcontrollers where the 
   Flash memory density ranges between 256 and 512 Kbytes.   - XL-density devices are STM32F101xx and STM32F103xx microcontrollers where
   the Flash memory density ranges between 512 and 1024 Kbytes.
 - Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
  */


似乎有了思路。查找工程代码,定义了#define STM32F10X_MD_VL,(好像上一位工程师写错了),我修改为#define STM32F10X_MD,问题解决。

转载于:https://www.cnblogs.com/longintchar/p/5224446.html

你可能感兴趣的:(换晶振导致stm32串口数据飞码的解决办法(补充))