cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 HAL usart with and without interrupt

MDeac.1
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

If you find my answers useful, click the accept button so that way others can see the solution.

View solution in original post

8 REPLIES 8

>>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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Karl Yamashita
Lead II

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.

 

 

 

If you find my answers useful, click the accept button so that way others can see the solution.

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?

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.

 

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.

If you find my answers useful, click the accept button so that way others can see the solution.

ST has a lot of examples. For the H7 you can look at the repository it created

KarlYamashita_0-1713308554778.png

 

If you find my answers useful, click the accept button so that way others can see the solution.

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.

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

If you find my answers useful, click the accept button so that way others can see the solution.