This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How can I clear TXDRDY interrupt in uart?

Hi, I'm using nrf51822. After sending a data from TXD, I enable the TXDRDY interrupt by setting INTENSET register. Then I can get into TXDRDY interrupt handler function. But I don't know how to clear the pending interrupt, then the interrupt handler function will be triggered again and again. I know setting INTENCLR register can disable the interrupt. But I don't want to disable the interrupt and enable it after sending another data, I just want to clear current interrupt and can get another interrupt after I sent another data. How can I deal with it?

Thanks, BinLei

  • You don't need to clear the pending interrupt - the entry to the interrupt handler does that for you, you need to clear the task

    NRF_UART0->EVENTS_TDXRDY = 0
    

    You can see this in the sample code too. Generally if an event is set up to generate an interrupt, the event needs to be cleared before you leave the interrupt handler or else it will trigger again.

  • Hi RK, Thanks for your quick reply! I use mbed library for development. In the serial_write() API it checks if NRF_UART0->EVENTS_TDXRDY == 1 firstly, if true then it's writeable, else then will check it again and again until NRF_UART0->EVENTS_TDXRDY becomes true. I think this checking it's reasonable to avoid writing data into TXD before the previous data is sent out. If I add code NRF_UART0->EVENTS_TDXRDY = 0 as you suggested, then the next serial_write() calling will get into stuck on checking whether NRF_UART0->EVENTS_TDXRDY is true.

    Thanks, BinLei

  • Well I assume the code which checks TXDREADY in the mbed library also clears the event and writes the next byte of data. You can't both control it, either you're handling the interrupt, writing the next load of data to transmit and clearing the event, or the mbed library is.

    If that event isn't cleared by some piece of code, the interrupt will continue to fire until it is. Perhaps on interrupt you just need to call the mbed library which will then check the event, find it's '1', send out the next data and clear the event.

Related