cancel
Showing results for 
Search instead for 
Did you mean: 

I have a button connected to STM32F405. I am using external interrupt with the button. Inside the callback of the external interrupt I am sending a command to retrieve some data from another microcontroller as a loop. But I am receving only data once.

cjaya.1
Associate II
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
        if(GPIO_Pin == GPIO_PIN_10)
           {
           for(volatile int j = 0; j<3000; j++)
              {
              char Txbuffer = "Read\n";
              HAL_UART_Transmit_IT(&huart2, (uint8_t*)Txbuffer, strlen(Txbuffer));
              for(volatile int i = 0; i < 1000; i++);
             
              HAL_UART_Receive_IT(&huart2, Rxbuffer, 30); 
               for(volatile int i =0; i<1000; i++);
 
               }
 
           } 
 
 
    
}

2 REPLIES 2
Karl Yamashita
Lead III

You should set a flag indicating a button was pressed and poll it in a main while loop. From there you can transmit your tx buffer. Is your intention to transmit "Read\n" and receive 30 bytes 3000 times?

You didn't show your code for the HAL_UART_RxCpltCallback so it may be that you didn't call HAL_UART_Receive_IT to re-enable the interrupt again.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.
Bob S
Principal

Since you call the HAL_UART_Transmit_IT() and receive_IT() from inside an interrupt, they will only work if the UART interrupt is higher priority than the EXTI interrupt. But as @Community member​ said - get that code OUT of the interrupt handler.

You do realize that HAL_UART_Transmit_IT() will return immediately, before any data has been sent. Your dummy delay loops will finish long before that string will be sent. Likewise, HAL_UART_Receive_IT() returns immediately, before any data has been received. And THAT dummy delay loop will also complete long before any data has been received (and likely before the "Read\n" string has finished being sent.

And finally - you don't check the return values from the HAL calls.