当前位置:网站首页>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();
}
}

边栏推荐
猜你喜欢

How to perform POC in depth with full flash distribution?

迁移学习笔记——Adapting Component Analysis

2022春招——禾赛科技FPGA技术岗(一、二面,收集于:数字IC打工人及FPGA探索者)

ML16 neural network (2)

基于51单片机的直流电机调速系统(L298的使用)

预训练语言模型的使用方法

1、 Usage of common loss function

Hal library learning notes-14 ADC and DAC

充电桩充电技术新能源充电桩开发

华为云14天鸿蒙设备开发-Day5驱动子系统开发
随机推荐
华为云14天鸿蒙设备开发-Day5驱动子系统开发
低成本2.4GHz 无线收发芯片--Ci24R1
CS4344国产替代DP4344 192K 双通道 24 位 DA 转换器
AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘
入门到入魂:单片机如何利用TB6600高精度控制步进电机(42/57)
1、 Transmission of file stream on Web page
Hal library learning notes-12 SPI
Hal learning notes - Basic timer of 7 timer
Continue the new journey and control smart storage together
Hal library learning notes - 9 DMA
How to use the pre training language model
Reading papers on false news detection (I): fake news detection using semi supervised graph revolutionary network
Design and implementation of QT learning notes data management system
4、 Application of one hot and loss function
智慧充电桩系统由什么组成?
避坑:关于两个HC-05主从一体蓝牙模块互连,连不上问题
基于STC51:四轴飞控开源项目原理图与源码(入门级DIY)
一、multiprocessing.pool.RemoteTraceback
Torch. NN. Parameter() function understanding
ML8自学笔记