2021-05-21 12:25 AM
UART_HandleTypeDef huart2;
void MX_USART2_UART_Init(void){
huart2.Instance = USART2;
huart2.Init.BaudRate = 9600;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
}
int main(void){
HAL_Init();
MX_USART2_UART_Init();
while (1)
{ }
}
void USART2_IRQHandler(void){
static uint8_t temp;
HAL_UART_IRQHandler(&huart2);
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
}
2021-05-21 05:24 AM
If you want to use HAL, you'll have to use its way of doing things. In this case, that means using the HAL_UART_Receive_IT function to start the transfer.
See example here: