换晶振导致stm32串口数据飞码的解决办法(补充)
生活随笔
收集整理的這篇文章主要介紹了
换晶振导致stm32串口数据飞码的解决办法(补充)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
今天(2014.4.21)把stm32f107的程序下載到stm32f103的板子上,發(fā)現(xiàn)串口收不到數(shù)據(jù),突然想起晶振頻率沒(méi)有修改,#define HSE_VALUE ? ?((uint32_t)13560000) /*!< Value of the External oscillator in Hz */ 這個(gè)要改回去,因?yàn)橥饨泳д袷?M
之后試驗(yàn),發(fā)現(xiàn)有數(shù)據(jù),但是亂碼。百思不得其解,無(wú)意中發(fā)現(xiàn),PC的波特率設(shè)置為9600,板子的波特率設(shè)置為19200就不會(huì)亂碼。剛好是2倍的關(guān)系。順藤摸瓜問(wèn)度娘!一個(gè)帖子也是這種情況,一個(gè)回答是“問(wèn)題解決了,把target options里#define里的STM32F10X_HD_VL改成STM32F10X_MD就正常了(我用的是中密度器件)”,樓下有人說(shuō):
看庫(kù)里面的stm32f10x.h文件,里面很多內(nèi)容與系統(tǒng)時(shí)鐘的配置有關(guān)。該文件會(huì)根據(jù)選擇的芯片類型來(lái)進(jìn)行時(shí)鐘配置,要在此位置將選用的芯片類型去掉注釋符。當(dāng)然不想每次修改此文件,比較方便的方法就是你所說(shuō)是在編譯器的target options選項(xiàng)框中define。。。效果一樣。
我翻開(kāi)那個(gè)頭文件
#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,(好像上一位工程師寫錯(cuò)了),我修改為#define STM32F10X_MD,問(wèn)題解決。
之后試驗(yàn),發(fā)現(xiàn)有數(shù)據(jù),但是亂碼。百思不得其解,無(wú)意中發(fā)現(xiàn),PC的波特率設(shè)置為9600,板子的波特率設(shè)置為19200就不會(huì)亂碼。剛好是2倍的關(guān)系。順藤摸瓜問(wèn)度娘!一個(gè)帖子也是這種情況,一個(gè)回答是“問(wèn)題解決了,把target options里#define里的STM32F10X_HD_VL改成STM32F10X_MD就正常了(我用的是中密度器件)”,樓下有人說(shuō):
看庫(kù)里面的stm32f10x.h文件,里面很多內(nèi)容與系統(tǒng)時(shí)鐘的配置有關(guān)。該文件會(huì)根據(jù)選擇的芯片類型來(lái)進(jìn)行時(shí)鐘配置,要在此位置將選用的芯片類型去掉注釋符。當(dāng)然不想每次修改此文件,比較方便的方法就是你所說(shuō)是在編譯器的target options選項(xiàng)框中define。。。效果一樣。
我翻開(kāi)那個(gè)頭文件
#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,(好像上一位工程師寫錯(cuò)了),我修改為#define STM32F10X_MD,問(wèn)題解決。
總結(jié)
以上是生活随笔為你收集整理的换晶振导致stm32串口数据飞码的解决办法(补充)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mac os 和 ubuntu 上测试工
- 下一篇: 互联网日报 | 5月10日 星期一 |