问题遇到的现象和发生背景
我想使用STM32开发板编程与OpenMV模块进行串口通信,代码编译没有问题OpenMV也能够正常发送数据出来,当时好像STM32开发板没有办法正常接收OpenMV接收到的数据
针脚设置:
遇到的现象和发生背景
STM32开发板没有正常接收到数据
代码
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2023 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "gpio.h"
#include "stdio.h"
/* USER CODE BEGIN PFP */
#ifdef __GNUC__ //串口重定向
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart1 , (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/* USER CODE END PFP */
void SystemClock_Config(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
while (1)
{
HAL_GPIO_WritePin ( GPIOA, GPIO_PIN_6, GPIO_PIN_SET ) ;
HAL_GPIO_WritePin ( GPIOA, GPIO_PIN_5, GPIO_PIN_SET ) ;
HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_3, GPIO_PIN_SET ) ;
HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_4, GPIO_PIN_SET ) ;
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
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_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
int theta_err,rho_err;
void Optical_Flow_Receive_Prepare(uint8_t data)
{
/* 局部静态变量:接收缓存 */
static uint8_t RxBuffer[10];
/* 数据长度 *//* 数据数组下标 */
static uint8_t _data_cnt = 0;
/* 接收状态 */
static uint8_t state = 0;
/* 帧头1 */
if(state==0&&data== 0x2C )
{
state=1;
}
/* 帧头2 */
else if(state==1&&data== 0x12 )
{
state=2;
_data_cnt = 0;
}
/* 接收数据租 */
else if(state==2)
{
RxBuffer[++_data_cnt]=data;
if(_data_cnt>=8)
{
state = 0;
Data_Processing(RxBuffer,_data_cnt);
}
}
/* 若有错误重新等待接收帧头 */
else
state = 0;
}
void Data_Processing(uint8_t *data_buf,uint8_t num)
{
int theta_org,rho_org;
/* 读取偏移角度原始数据 */
theta_org = (int)(*(data_buf+1)<<0) | (int)(*(data_buf+2)<<8) | (int)(*(data_buf+3)<<16) | (int)(*(data_buf+4)<<24) ;
theta_err = theta_org;
/* 读取偏移尺寸原始数据 */
rho_org = (int)(*(data_buf+5)<<0) | (int)(*(data_buf+6)<<8) | (int)(*(data_buf+7)<<16) | (int)(*(data_buf+8)<<24) ;
rho_err = rho_org;
}
运行结果及详细报错内容
对应的A56针脚没有电压反应
我的解答思路
是不是针脚设置有问题还是说是代码的编译有问题
怎么样才能够正常的接收数据呢