2019-04-03 04:46 AM
Can any body can give example for receive data on interrupt on uart??
I am using TRUE studio and CubeMx and STM32F103C8T6 device . I successfully tested UART-2 Transmit. It works perfectly.
But when I try to receive on interrupt I didn't get the data. i have tries many times as suggested in community but not get any success. Please somebody help me with this
2019-04-03 05:15 AM
Hi,
I'm assuming you've tested transmit function with polling receive.
Did you initialize interrupt for reception correctly?
You need to start Receive IT by HAL_UART_Receive_IT()
then if you like you can use
HAL_UART_RxCpltCallback() for reception or directly write down in to IRQ Handler.
2019-04-03 05:21 AM
Can you please give me any example code???
2019-04-03 05:22 AM
I have tried it many times but not get any success.....
I think I miss any step...I am trying from 4-5 days but not getting any success
2019-04-03 05:28 AM
Why don't you check the Cube examples? Install STM32F1 package in Cube, open Help->Updater Settings and press the Browse button to open you repository directory.
Then, for example, go to STM32Cube_FW_F1_V1.7.0/Projects/STM32F103RB-Nucleo/Examples/UART/UART_TwoBoards_ComIT to find UART example which uses interrupts.
2019-04-03 05:29 AM
MX_USART2_UART_Init();
__HAL_UART_ENABLE_IT(&huart2,UART_IT_RXNE);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
uint8_t i;
if (huart->Instance == USART2) //current UART
{
if (Rx_indx==0) {for (i=0;i<100;i++) Rx_Buffer[i]=0;} //clear Rx_Buffer before receiving new data
if (Rx_data[0]!=13) //if received data different from ascii 13 (enter)
{
Rx_Buffer[Rx_indx++]=Rx_data[0]; //add data to Rx_Buffer
}
else //if received data = 13
{
Rx_indx=0;
Transfer_cplt=1;//transfer complete, data is ready to read
}
HAL_UART_Receive_IT(&huart2, Rx_data, 1); //activate UART receive interrupt every time
}
}