元旦放假在家得到一块Nucleo-64 STM32G070RBT的开发板通过STM32CubeMX 生成的串口 无法接收数据,发送数据不会进入中断,发送数据正常 /* Includes ------------------------------------------------------------------*/ #include "usart.h" /* USER CODE BEGIN 0 */ #include "string.h" uint8_t pData[256] = {0}; /* USER CODE END 0 */ UART_HandleTypeDef huart2; /* USART2 init function */ void MX_USART2_UART_Init(void) { huart2.Instance = USART2; huart2.Init.BaudRate = 115200; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart2.Init.OverSampling = UART_OVERSAMPLING_16; huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart2) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK) { Error_Handler(); } } void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(uartHandle->Instance==USART2) { /* USER CODE BEGIN USART2_MspInit 0 */ /* USER CODE END USART2_MspInit 0 */ /* USART2 clock enable */ __HAL_RCC_USART2_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART2 GPIO Configuration PA2 ------> USART2_TX PA3 ------> USART2_RX */ GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF1_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USART2 interrupt Init */ HAL_NVIC_SetPriority(USART2_IRQn, 2, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ //HAL_UART_Transmit_IT(&huart2, pdata, sizeof(pdata)); /* USER CODE END USART2_MspInit 1 */ } } void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) { if(uartHandle->Instance==USART2) { /* USER CODE BEGIN USART2_MspDeInit 0 */ /* USER CODE END USART2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART2_CLK_DISABLE(); /**USART2 GPIO Configuration PA2 ------> USART2_TX PA3 ------> USART2_RX */ HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); /* USART2 interrupt Deinit */ HAL_NVIC_DisableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspDeInit 1 */ /* USER CODE END USART2_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ int fputc(int ch,FILE *f) { HAL_UART_Transmit(&huart2, (uint8_t*)&ch, 1, 1000); return ch; } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if(huart->Instance == USART2) // 判断是由哪个串口触发的中断 { //HAL_UART_Transmit(&huart3,aRxBuffer1,1,100); // 接收到数据马上使用串口1发送出去 HAL_UART_Receive_IT(&huart2,pData,1); // 重新使能串口1接收中断 HAL_UART_Transmit(&huart2, pData, 1, 1000); } } void HAL_UART_Enable(void) { memset(pData,0,sizeof(pData)); HAL_UART_Receive_IT(&huart2, pData, 1); //snprintf((char *)pData,sizeof(pData),"%s enable:%d\r\n",__func__,2); //HAL_UART_Transmit(&huart2, (char *)&pData[0], strlen(pData), 1000); } |
软件为keil5,头文件未找到
通过FATFS文件系统读写SD卡创建文件可以了,但加入MSC,一直显示一个没有格式化的U盘盘符,也不能格式化,这是什么问题导致的
STM32L431在去掉注释memcpy后会不断重启
STM32双核H7核间通信的方法
STM32F103C8T6使用CubeIDE烧录运行报硬件错误,相同代码MDK烧录却可以正常运行
MCSDK5.4.4 FOC电流闭环运行电机偶发停转问题
MCSDK6.3.1使用SIXSTEP如何才能使用电流模式呢?我在配置了电流传感器后仍然无法使用电流模式。
STM32G030F6 ADC+DMA多通道非连续采样无法正常工作?
STM32G0B1VE的CAN过滤器个数问题
STM32G473VET6同时使用6个片上放大器(OPAMP)的PGA加外部偏置模式,引脚位置让差分信号走线分离,信号有无较大影响?