本帖最后由 3goodboy 于 2015-10-13 21:24 编辑
使用stm32f051串口发送数据给电脑,一直接收到DB,而不是我设定的值
麻烦各位帮我分析下是什么问题,库是HAL库
蓝色的是我写的关于串口的代码,褐色是用stm32cubemx生成的,绿色是无关的代码
找到问题了,答案在6楼。感谢大家的回复
代码如下:
#include "stm32f0xx_hal.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
#define TxBUFFERSIZE 1
uint8_t Pwm =12;
void SystemClock_Config(void);
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t TxBuffer=Pwm;
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM1_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
HAL_TIMEx_PWMN_Start(&htim1, TIM_CHANNEL_3);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
HAL_UART_Transmit(&huart1,(uint8_t *)Pwm,TxBUFFERSIZE,5000);
HAL_Delay(500);
}
/* USER CODE END 3 */
}
|