(二) uart-逐飞TC264库学习(对比STM32 HAL库)

/********看了一下感觉TC264的串口好复杂呀,平时还基本用不到,发数据直接上逐飞配置好的printf就行,看摄像头图像也有相应的函数一步到位,就先不研究了,权当一个stm32串口回忆篇就好了*****/

#include "isr_config.h"

这是一个设定优先级的头文件

stm32回顾:

要先在cube中选择心仪的串口开启异步模式并进行相关配置

并使能中断

发送函数

HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff);

参数说明: 句柄  发送内容储存地址 字节长度 最大时间限制

发送中断

HAL_UART_Transmit_IT(&huart1,txDataBuffer,sizeof(txDataBuffer));

中断回调函数

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)

接收中断

HAL_UART_Receive_IT(&huart1,rxDataBuffer,sizeof(rxDataBuffer));

回调函数

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

   if( huart ==  &huart1)

   {

       //do something

       HAL_UART_Receive_IT(&huart6,rxDataBuffer,sizeof(rxDataBuffer));

      //重新接收

   }  

}

重定向

#include “stdio.h”
extern UART_HandleTypeDef huart1;

//在user code begin 4 和 user code end 4 之间写 重定向函数
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff);
return ch;
}

并记得勾选MicroLIB

不过在TC264中逐飞已经帮我们重定向过了,所以直接无脑 printf(" ") 就行

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面给出基于STM32 HAL库UART中断形式的发送函数示例。 注意事项: - 使用前请确保已经初始化了UART。 - 建议在使用前先判断一次是否可发送,避免发送堵塞。 - 本例采用了DMA方式发送,需要提前配置好DMA。 示例代码如下: ```c void UART_DMA_Send_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) { uint32_t *tmp; uint16_t tmp1 = 0; uint32_t tmpisr = DISABLE; tmp = (uint32_t*)pData; /* Disable the UART DMA Tx request */ huart->Instance->CR3 &= (uint32_t)(~USART_CR3_DMAT); /* Configure the DMA Tx interrupt */ /* Configure the DMA Tx interrupt */ tmpisr = __HAL_UART_DMA_GET_IT_SOURCE(huart, UART_DMA_TX_IT); if(tmpisr == SET) { __HAL_DMA_DISABLE_IT(huart->hdmatx, DMA_IT_TC | DMA_IT_HT | DMA_IT_TE); /* Set the DMA Tx transfer complete callback */ huart->hdmatx->XferCpltCallback = NULL; /* Set the DMA Tx transfer half complete callback */ huart->hdmatx->XferHalfCpltCallback = NULL; /* Set the DMA error callback */ huart->hdmatx->XferErrorCallback = NULL; /* Set the DMA abort callback */ huart->hdmatx->XferAbortCallback = NULL; /* Clear the DMA transfer complete flag */ __HAL_DMA_CLEAR_FLAG(huart->hdmatx, __HAL_DMA_GET_TC_FLAG_INDEX(huart->hdmatx)); /* Clear the DMA transfer half complete flag */ __HAL_DMA_CLEAR_FLAG(huart->hdmatx, __HAL_DMA_GET_HT_FLAG_INDEX(huart->hdmatx)); /* Clear the DMA transfer error flag */ __HAL_DMA_CLEAR_FLAG(huart->hdmatx, __HAL_DMA_GET_TE_FLAG_INDEX(huart->hdmatx)); } /* Enable the UART DMA Tx request */ huart->Instance->CR3 |= USART_CR3_DMAT; /* Enable the DMA Tx Channel */ HAL_DMA_Start_IT(huart->hdmatx, (uint32_t)tmp, (uint32_t)&huart->Instance->TDR, Size); /* Enable the DMA channel IRQ Channel */ HAL_NVIC_EnableIRQ(huart->hdmatx->IRQn); tmp1 = huart->TxXferSize; /* Check if a non-blocking transfer is ongoing or not */ if (huart->gState == HAL_UART_STATE_BUSY_TX) { return; } /* If it is a put buffer */ if (huart->Init.WordLength == UART_WORDLENGTH_9B) { while (Size--) { huart->pTxBuffPtr[tmp1++] = (*tmp & (uint32_t)0x01FF); tmp++; } } else { while (Size--) { huart->pTxBuffPtr[tmp1++] = (*tmp & (uint8_t)0xFF); tmp++; } } huart->TxXferSize = tmp1; huart->TxXferCount = tmp1; /* Process Unlocked */ __HAL_UNLOCK(huart); /* Enable the UART Transmit data register empty interrupt */ __HAL_UART_ENABLE_IT(huart, UART_IT_TXE); } ``` 以上是基于HAL库UART中断形式的发送函数示例,由于不同版本的HAL库实现细节有所不同,因此具体实现可能会有所差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值