当前位置:网站首页>STM32 串口乱码
STM32 串口乱码
2022-07-29 05:23:00 【BobBobBao】
问题描述
用正点原子STM32F4探索者开发板调试野火骄阳电机驱动程序,发现串口输出一直是乱码。问题排查:
- 串口调试助手编码方式?同一个串口调试助手,用正点原子、STM32CubeMX生成的程序发送数据正常。排除串口调试助手问题。
- 串口配置函数问题?仔细检查过串口配置,GPIO配置,用STM32CubeMX与骄阳程序相互替换,问题仍然存在。
- HAL库其它文件干扰?删除多余HAL库文件,与STM32CubeMX用到的库文件保持一致。问题仍然存在。
- 参考STM32串口通信乱码详细处理方法,更改stm32f4xx_hal_conf.h文件中HSE_VALUE = 8000000,此处设置的是外部晶振时钟频率,而SystemClock_Config()函数中RCC_OscInitStruct.PLL.PLLM = 8;是PLLM分频系数。系统内部很多参数是直接调用HSE_VALUE 的值,所以一定要修改这个值。
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
/** * @brief System Clock Configuration * @retval None */
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {
0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {
0};
/** Configure the main internal regulator output voltage */
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** 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.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
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_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
Error_Handler();
}
}

边栏推荐
- D3.js vertical relationship diagram (with arrows and text description of connecting lines)
- Wechat built-in browser prohibits caching
- Discussion on the design of distributed full flash memory automatic test platform
- Hal library learning notes-10 overview of Hal library peripheral driver framework
- 智慧能源管理系统解决方案
- 智能温度控制系统
- 三、如何搞自定义数据集?
- Jianzhi core taocloud full flash SDS helps build high-performance cloud services
- 迁移学习—Geodesic Flow Kernel for Unsupervised Domain Adaptation
- 2、 Multi concurrent interface pressure test
猜你喜欢
随机推荐
HAL库学习笔记- 8 串口通信之概念
基于FPGA:运动目标检测(补充仿真结果,可用毕设)
Transfer learning
Transfer feature learning with joint distribution adaptation
AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘
Hal learning notes - Basic timer of 7 timer
Dust and noise monitoring system
Migration learning robot visual domain adaptation with low rank reconstruction
ML7自学笔记
Hal library learning notes-10 overview of Hal library peripheral driver framework
ML17-神经网络实战
Reading papers on false news detection (I): fake news detection using semi supervised graph revolutionary network
Hal library learning notes-14 ADC and DAC
HR面必问问题——如何与HR斗志斗勇(收集于FPGA探索者)
电力电子:单项逆变器设计(MATLAB程序+AD原理图)
华为云14天鸿蒙设备开发-Day5驱动子系统开发
125KHz唤醒功能2.4GHz单发射芯片-Si24R2H
ML4自学笔记
预训练语言模型的使用方法
NRF52832-QFAA 蓝牙无线芯片









