|
int32_t uartWrite(uint8_t *buf, uint32_t len)
{
uint8_t crc[1] = {0x55};
uint32_t i = 0;
uint8_t aa=0x55;
if(NULL == buf)
{
return -1;
}
for(i=0; i<len; i++)
{
// HAL_UART_Transmit_IT(&huart2, (uint8_t *)&buf, 1);
HAL_UART_Transmit(&huart2, (uint8_t *)&buf, 1,50);
// while (huart2.State != HAL_UART_STATE_READY);//Loop until the end of transmission
if(i >=2 && buf == 0xFF)
{
// HAL_UART_Transmit_IT(&huart2, (uint8_t *)&crc, 1);
HAL_UART_Transmit(&huart2, (uint8_t *)&buf, 1,50);
// while (huart2.State != HAL_UART_STATE_READY);//Loop until the end of transmission
}
}
#ifdef PROTOCOL_DEBUG
GIZWITS_LOG("MCU2WiFi[%4d:%4d]: ", gizGetTimerCount(), len);
for(i=0; i<len; i++)
{
GIZWITS_LOG("%02x ", buf);
if(i >=2 && buf == 0xFF)
{
GIZWITS_LOG("%02x ", 0x55);
}
}
GIZWITS_LOG("\n");
#endif
return len;
}
程序注掉的地方是中断发送的,这么写,程序运行有问题,按照你的换成轮询的就好了,而且咱们用CubeMx生成的hal_uart.h文件中的结构体UART_HandleTypeDef中是这样的
typedef struct
{
USART_TypeDef *Instance; /*!< UART registers base address */
UART_InitTypeDef Init; /*!< UART communication parameters */
uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
uint16_t TxXferSize; /*!< UART Tx Transfer size */
uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
uint16_t RxXferSize; /*!< UART Rx Transfer size */
uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
HAL_LockTypeDef Lock; /*!< Locking object */
__IO HAL_UART_StateTypeDef State; /*!< UART communication state */
__IO uint32_t ErrorCode; /*!< UART Error code */
}UART_HandleTypeDef;
而官网生成的代码是这样的,我忘了是官网生成的还是你的一个教程里面的,是这样的typedef struct
{
USART_TypeDef *Instance; /*!< UART registers base address */
UART_InitTypeDef Init; /*!< UART communication parameters */
uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
uint16_t TxXferSize; /*!< UART Tx Transfer size */
__IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
uint16_t RxXferSize; /*!< UART Rx Transfer size */
__IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
HAL_LockTypeDef Lock; /*!< Locking object */
__IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
and also related to Tx operations.
This parameter can be a value of @ref HAL_UART_StateTypeDef */
__IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations.
This parameter can be a value of @ref HAL_UART_StateTypeDef */
__IO uint32_t ErrorCode; /*!< UART Error code */
}UART_HandleTypeDef;
后面那部分不一样,不知道是不是这个原因导致的 |
|