2024-04-15 12:13 PM
Using an STM32H723 I started with a non interrupt USART connection onto a wifi module.
I set up the connection on UART3 implementing nothing more than that and using these instructions
int len = sprintf(tx_buff,"AT+GMR\r\n");
HAL_UART_Transmit(&huart3,tx_buff,len,100);
Followed up with polling instructions to capture the data.
if( USART3->ISR & UART_IT_RXNE ){
rec1_buff[reccount] = USART3->RDR;
reccount++;
}
Now the above works so now I wanted to do this using interrupts.
I then set the interrupt and used the above transmit instruction but no receive packets are ever returned.
I have a workaround I put the same receive instructions in a standard timer interrupt and capture the data so I have a
solution that works for me. Systick is too slow but I can set a really fast timer interrupt instead for capture.
I am puzzled why no packets are returned and the interrupt handler (I just put a breakpoint in the handler) never fires at all.
Any advice on this would be appreciated.
Solved! Go to Solution.
2024-04-16 03:56 PM
You call HAL_UART_Receive_IT which tells HAL driver how many bytes you want to receive. Without telling the HAL driver what to do, it won't interrupt. Then the HAL driver will interrupt on each byte and do the work of saving each byte into the buffer array you're pointing to. When it's done it'll jump to the HAL_UART_RxCpltCallback
NVIC is more a of global interrupt for both Rx and Tx.
2024-04-15 12:32 PM - edited 2024-04-15 12:33 PM
>>I am puzzled why no packets are returned and the interrupt handler
Interrupt source needs to be enabled on the UART
NVIC needs to have the peripheral source enabled.
Vector Table needs to be set correctly, and the IRQ Handler suitably binds to the table.
For SysTick, you'd likely want a sufficiently deep circular DMA buffer which you can sweep at the 1 ms / 1 KHz rate
2024-04-15 01:25 PM
You talk about interrupt but don't say what type of interrupt it is? Is it HAL_UART_Receive_IT or HAL_UART_Receive_DMA?
As @Tesla DeLorean mentions, NVIC needs to be enabled. That is usually the #1 thing most people don't configure when they can't get the callback to work.
2024-04-16 03:29 PM
I got confused at one point as there are 3 different types of UART/USART communication in the HAL.
These are my steps ... So instruction used.
HAL_UART_Transmit(&huart3,tx_buff,len,100);
The reply is received polling. So I opened up the IOC and set the NVIC expecting the interrupt to fire when the data was received. I put a breakpoint in the interrupt handler just to catch it.
Then using that same instruction above just to get the data sent to the WIFI device and wait for the device to respond. I never get any reply on the interrupt but I can use a timer interrupt and grab the reply by polling in the dummy timer..
So for some reason it is not being received into the usart interrupt.
I have a feeling but can find no conformation on this.
To use HAL USART interrupt communications I have to use HAL_USART_Receive_IT()?
This instruction prepares the USART state for an expected future communication and without it any USART received data is ignored?
Would this be correct?
2024-04-16 03:32 PM
As I explained above it might be how I view the USART module and trying to interact with it is not as expected.
I never use those instructions so I never prepared the device USART state to receive the data.
I did set the NVIC for the device in the IOC file and it appears in the interrupt it.c file.
2024-04-16 03:56 PM
You call HAL_UART_Receive_IT which tells HAL driver how many bytes you want to receive. Without telling the HAL driver what to do, it won't interrupt. Then the HAL driver will interrupt on each byte and do the work of saving each byte into the buffer array you're pointing to. When it's done it'll jump to the HAL_UART_RxCpltCallback
NVIC is more a of global interrupt for both Rx and Tx.
2024-04-16 04:03 PM
ST has a lot of examples. For the H7 you can look at the repository it created
2024-04-16 06:02 PM
Thank you ... confirms I have to call the receive function to make the interrupt occur.
I will experiment with that as the length is not fixed it varies.
2024-04-16 06:30 PM
If the data varies in length then you'll want to use HAL_UARTEx_ReceiveToIdle_DMA and HAL_UARTEx_RxEventCallback
See this project which explains more about using interrupt with idle https://github.com/karlyamashita/Nucleo-G431RB_Three_UART/wiki