我有一个定制设计的电路板,带有STM32L071和EnOcean TCM515。使用USART1我能够传输数据包(ESP3协议)以获取TCM515模块的版本号。 HAL_UART_Transmit(&huart1, (uint8_t*)enocean_ver, sizeof(enocean_ver), HAL_MAX_DELAY);
使用逻辑分析仪我可以看到来自TCM515模块的发送和响应数据包,还探测了通信信道的引脚,我可以看到发送和接收的数据包。
但是使用HAL_UART_Receive(&huart1, (uint8_t*)buf, sizeof(buf), HAL_MAX_DELAY);
数据并没有存储到缓冲区中,我相信它是一个软件问题,我错过了什么?
uint8_t enocean_ver[]={0x55, 0x00, 0x01, 0x00, 0x05, 0x70, 0x03, 0x09};
UART_HandleTypeDef huart1;
int main(void) {
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
HAL_UART_GetState(&huart1);
char buf[40];
memset(buf, 0, sizeof(buf));
HAL_UART_Transmit(&huart1, (uint8_t*)enocean_ver, sizeof(enocean_ver), HAL_MAX_DELAY);
HAL_UART_Receive(&huart1, (uint8_t*)buf, sizeof(buf), HAL_MAX_DELAY);
while(1);
}
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 57600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
HAL_UART_Init(&huart1);
}
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
if(huart->Instance==USART1){
/*USART1 GPIO Configuration
PB6 ------> USART1_TX
PB7 ------> USART1_RX*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_USART1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
}
void MX_GPIO_Init() {
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();
}