2023-02-21 12:57 PM
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++);
}
}
}
2023-02-21 01:59 PM
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.
2023-02-21 02:20 PM
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.