我遇到的一个问题似乎发生在其他董事会的其他人身上。我已经在STM32L4R上初始化了UART5以进行发送和接收。当我使用“ HAL_UART_Receive()”时,发送功能可以按预期工作,但是接收功能根本无法工作。该功能在UART1-3上没有问题,但在UART5上没有问题。有人可以告诉我设置UART5是否缺少某些细节吗? CubeMx已将UART5配置为:
static void MX_UART5_Init(void)
{
huart5.Instance = UART5;
huart5.Init.BaudRate = 38400;
huart5.Init.WordLength = UART_WORDLENGTH_8B;
huart5.Init.StopBits = UART_STOPBITS_1;
huart5.Init.Parity = UART_PARITY_NONE;
huart5.Init.Mode = UART_MODE_TX_RX;
huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart5.Init.OverSampling = UART_OVERSAMPLING_16;
huart5.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart5.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart5) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
我尝试从中收到的代码如下:
if(HAL_UART_Receive(&UART5, ch_receive, 2, 10000) == 3){ //if a HAL_TIMEOUT is received
HAL_UART_Transmit(&huart1, Communication_Fail, sizeof(Communication_Fail), 0xFFFF);
}