加入串口接收

This commit is contained in:
不吃油炸鸡
2025-10-19 12:00:28 +08:00
parent 548db44f01
commit 82f489bf5c
3 changed files with 13 additions and 3 deletions

View File

@@ -36,7 +36,8 @@ extern UART_HandleTypeDef huart6;
/* USER CODE BEGIN Private defines */
#define USART_RX_BUFFER_SIZE 25
extern uint8_t uart_receive_str[USART_RX_BUFFER_SIZE + 1];
extern uint8_t uart_receive_buf[USART_RX_BUFFER_SIZE + 1];
extern uint8_t uart_receive_flag;
/* USER CODE END Private defines */
void MX_USART6_UART_Init(void);

View File

@@ -250,9 +250,10 @@ void USART6_IRQHandler(void)
/* USER CODE BEGIN USART6_IRQn 0 */
if(__HAL_UART_GET_FLAG(&huart6, UART_FLAG_IDLE) != RESET)
{
uart_receive_flag = 1;
__HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_IDLE);
HAL_UART_DMAStop(&huart6);
HAL_UART_Receive_DMA(&huart6, uart_receive_str, USART_RX_BUFFER_SIZE);
HAL_UART_Receive_DMA(&huart6, uart_receive_buf, USART_RX_BUFFER_SIZE);
}
/* USER CODE END USART6_IRQn 0 */

View File

@@ -21,9 +21,11 @@
#include "usart.h"
/* USER CODE BEGIN 0 */
#include "stdio.h"
// memeory for receive string
uint8_t uart_receive_str[USART_RX_BUFFER_SIZE + 1];
uint8_t uart_receive_buf[USART_RX_BUFFER_SIZE + 1];
uint8_t uart_receive_flag = 0; // flag for receive complete
/* USER CODE END 0 */
@@ -162,6 +164,12 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
/* USER CODE BEGIN 1 */
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit(&huart6, (uint8_t *)&ch, 1, 0xffff);
return ch;
}
//串口6发送
void UART6_TX_Send(uint8_t *buffer, uint16_t length)
{