标签:enable 长度 tin ble 发送数据 setting dma inter receive
HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
以下均以UART1为例
int fputc(int ch, FILE *f)
{
uint8_t temp[1] = {ch};
HAL_UART_Transmit(&huart1, temp, 1, 2);
return ch;
}
需要先在STM32CubeMX中打开串口中断(USART1 -> NVIC Settings -> USART1 global interrupt -> Enable)
在USER CODE BEGIN PV中设置缓冲区
uint8_t aRxBuffer[1]; // 用来接收串口发送的数据
在USER CODE BEGIN 2中打开串口中断
HAL_UART_Receive_IT(&huart1,aRxBuffer,1);//接收来自串口1的数据,将其存放在缓冲区中,接收长度为1
在USER CODE BEGIN 4中设置回调函数
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart -> Instance == USART1 )// 判断是由哪个串口触发的中断
{ //回调应用代码 }
}
标签:enable 长度 tin ble 发送数据 setting dma inter receive
原文地址:https://www.cnblogs.com/qu-yang/p/12676103.html