Skip to main content
Graduate
April 15, 2024
Solved

STM32H7 HAL usart with and without interrupt

  • April 15, 2024
  • 2 replies
  • 3614 views

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.

    This topic has been closed for replies.
    Best answer by Karl Yamashita

    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.

    2 replies

    Graduate II
    April 15, 2024

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

    MDeac.1Author
    Graduate
    April 16, 2024

    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?

    Graduate II
    April 16, 2024

    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.

    Graduate II
    April 15, 2024

    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.

     

     

     

    MDeac.1Author
    Graduate
    April 16, 2024

    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.

     

    Graduate II
    April 16, 2024

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

    KarlYamashita_0-1713308554778.png