Skip to main content
JPanc.1
Associate III
Apr 3, 2019 11:46 AM UTC
Question

UART2 receive on interrupt examples required for STM32F103C8T6...

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

This topic has been closed for replies.

5 replies

e-zeki
Associate III
Apr 3, 2019 12:15 PM UTC

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.

JPanc.1
JPanc.1Author
Associate III
Apr 3, 2019 12:21 PM UTC

Can you please give me any example code???

JPanc.1
JPanc.1Author
Associate III
Apr 3, 2019 12:22 PM UTC

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

After Forever
Senior III
Apr 3, 2019 12:28 PM UTC

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.

JPanc.1
JPanc.1Author
Associate III
Apr 3, 2019 12:29 PM UTC
 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
 }
 
}