Reputation: 101
I am trying to do uart communication. However, HAL_UART_TxCpltCallback function does not work.
Also, USART1_IRQHandler is not executed. I think there is a setting that enables uart and interrupt, but
I don't know. The source code is as follows. If you have more information, please tell me. Thanks.
/// main source
HW_UART_Init( );
uint8_t init_ment[60] = "\n\rWelcome to RF Test program\n\r";
strcpy(uart1_txbuffer,init_ment);
HAL_UART_Transmit_IT(&huart1, uart1_txbuffer, 30);
HAL_Delay(50);
InitQueue(&queue);
HAL_UART_Receive_IT(&huart1, uart1_rxbuffer, 1);
HAL_Delay(1);
void HW_UART_Init( void )
{
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 19200;
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;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
}
Upvotes: 0
Views: 2890
Reputation: 11
If you are using cubeMX for initializing your MCU, there is a tab in USART section "NVIC Settings" which you can enable USART1 global interrupt over there.
It adds these two lines in your code, in stm32f4xx_hal_msp.c
file.
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
I suggest you to use cubeMX.
Upvotes: 1
Reputation: 77
If you do your own configuration without cube mx, first you should check if you add convenient uart files into your project. STM32 Cube defines IRQ Handlers inside the "xxxx_it.c" file, so possibly you dont have it. On the other hand necessary NVIC configurations are also done by Cube MX.
I suggest you to use Cube MX, then you you can find what is wrong here. In your code snippet there seem nothing wrong.
Upvotes: 0