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

UARTE Interrupt is not working at all

Hi.

I'm developing application that is needed to include  UARTE Interrupt.

I can drive UART interrupt well(not UARTE), but UARTE is not working.

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_uarte.h"
#include "SEGGER_RTT.h"


void UARTE0_UART0_IRQHandler(){
	SEGGER_RTT_printf(0, "test\n");
    if(NRF_UARTE0->EVENTS_ENDRX){
		SEGGER_RTT_printf(0, "test\n");
    }

}

int main(void)
{

	static uint8_t txBuffer[7] = "TEST\r\n";
	static uint8_t rxBuffer[20] = {0};

    NRF_UARTE0->BAUDRATE = NRF_UARTE_BAUDRATE_9600;
    NRF_UARTE0->PSEL.TXD = 19;
    NRF_UARTE0->PSEL.RXD = 18;
    NRF_UARTE0->CONFIG = NRF_UARTE_HWFC_DISABLED;
    NRF_UARTE0->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos);

    NRF_UARTE0->TXD.PTR = (uint32_t)((uint8_t *) txBuffer);
    NRF_UARTE0->TXD.MAXCNT = sizeof(txBuffer);
    NRF_UARTE0->TASKS_STARTTX = 0;

    NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
    NRF_UARTE0->RXD.MAXCNT = sizeof(rxBuffer);
    NRF_UARTE0->TASKS_STARTRX = 1;


    //NRF_UARTE0->INTENCLR = 0xFFFFFFFF;
    NRF_UARTE0->INTENSET = (1 << 2);

    NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
    NVIC_SetPriority(UARTE0_UART0_IRQn, 5);
    NVIC_EnableIRQ(UARTE0_UART0_IRQn);


    SEGGER_RTT_printf(0, "teTN\n");
    while (true)
    {
    	NRF_UARTE0->TASKS_STARTTX;
    }
}

Here is my code. Would guide me please?

Thank you.

Parents
  • Hi,

    there are some points to fix:

        if(NRF_UARTE0->EVENTS_ENDRX){
    		SEGGER_RTT_printf(0, "test\n");
        }
    

    you need to clear EVENTS_ENDRX here.

    NRF_UARTE0->INTENSET = (1 << 2);

    This will enable RXDRDY interrupt, not ENDRX. It's always better to use named constants.

    NRF_UARTE0->TASKS_STARTTX;

    this does nothing, should be NRF_UARTE0->TASKS_STARTTX = 1  (and wait for ENDTX event before next write)

  • #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "nrf_uarte.h"
    #include "SEGGER_RTT.h"
    
    
    void UARTE0_UART0_IRQHandler(){
    	SEGGER_RTT_printf(0, "test\n");
        if(NRF_UARTE0->EVENTS_ENDRX == 1){
    		SEGGER_RTT_printf(0, "test\n");
    		NRF_UARTE0->EVENTS_ENDRX = 0;
        }
        if(NRF_UARTE0->EVENTS_RXDRDY == 1){
        	SEGGER_RTT_printf(0, "RXDRDY\n");
        	NRF_UARTE0->EVENTS_RXDRDY = 0;
        }
    
    }
    
    int main(void)
    {
    
    	static uint8_t txBuffer[7] = "TEST\r\n";
    	static uint8_t rxBuffer[20] = {0};
    
        NRF_UARTE0->BAUDRATE = NRF_UARTE_BAUDRATE_9600;
        NRF_UARTE0->PSEL.TXD = 6;
        NRF_UARTE0->PSEL.RXD = 8;
        NRF_UARTE0->CONFIG = NRF_UARTE_HWFC_DISABLED;
        NRF_UARTE0->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos);
    
        NRF_UARTE0->TXD.PTR = (uint32_t)((uint8_t *) txBuffer);
        NRF_UARTE0->TXD.MAXCNT = sizeof(txBuffer);
        NRF_UARTE0->TASKS_STARTTX = 0;
    
        NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
        NRF_UARTE0->RXD.MAXCNT = sizeof(rxBuffer);
        NRF_UARTE0->TASKS_STARTRX = 1;
    
    
        //NRF_UARTE0->INTENCLR = 0xFFFFFFFF;
        NRF_UARTE0->INTENSET = (1 << 4);
    
        NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
        NVIC_SetPriority(UARTE0_UART0_IRQn, 5);
        NVIC_EnableIRQ(UARTE0_UART0_IRQn);
    
        NRF_UARTE0->TASKS_STARTTX = 0x01;
        while(!NRF_UARTE0->EVENTS_TXSTARTED){}
    
    
        SEGGER_RTT_printf(0, "Sequence check\n");
        while (true)
        {
    
    
        }
    }
    

    I've changed my code. But it is not works at all.

    Normal reading is fine. Only the problem is Interrupt.

    UARTE0_UART0_IRQHandler() <- This code is not called at all.

  • Hello,

    You must send RXD.MAXCNT(20) bytes for the ENDRX event to trigger the interrupt, did you try that?

  • Hi.

    NRF_UARTE0->INTENSET = (1 << 4) | (1 << 2);

    I modified this code.

    But there is no response. I've double checked TX, and RX pin number.

    What is the problems?

  • Are you testing with a nordic dev kit? Your code works when I try it here. The only change I made was to remove the RTT calls.

    Hitting breakpoint after receiving 1 byte:

Reply Children
  • Can you check Interrupt? UARTE0_UART0_IRQHandler isn't called.

  • As you can see from the screenshot I posted, the program enters the interrupt handler in my case.

  • #include <stdbool.h>
    #include <stdint.h>
    #include <string.h>
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "nrf_uarte.h"
    #include "SEGGER_RTT.h"
    
    
    void UARTE0_UART0_IRQHandler(){
    	SEGGER_RTT_printf(0, "test\n");
        if(NRF_UARTE0->EVENTS_ENDRX == 1){
    		SEGGER_RTT_printf(0, "test\n");
    		NRF_GPIO->OUTCLR = (1 << 23);
    		NRF_UARTE0->EVENTS_ENDRX = 0;
        }
        if(NRF_UARTE0->EVENTS_RXDRDY == 1){
        	SEGGER_RTT_printf(0, "RXDRDY\n");
        	NRF_GPIO->OUTCLR = (1 << 23);
        	NRF_UARTE0->EVENTS_RXDRDY = 0;
        }
    
    }
    
    int main(void)
    {
    	NRF_GPIO->DIRSET = (1 << 23);
    	NRF_GPIO->OUTSET = (1 << 23);
    	static uint8_t txBuffer[7] = "TEST\r\n";
    	static uint8_t rxBuffer[20] = {0};
    
        NRF_UARTE0->BAUDRATE = NRF_UARTE_BAUDRATE_9600;
        NRF_UARTE0->PSEL.TXD = 6;
        NRF_UARTE0->PSEL.RXD = 8;
        NRF_UARTE0->CONFIG = NRF_UARTE_HWFC_DISABLED;
        NRF_UARTE0->ENABLE = (UARTE_ENABLE_ENABLE_Enabled << UARTE_ENABLE_ENABLE_Pos);
    
        NRF_UARTE0->TXD.PTR = (uint32_t)((uint8_t *) txBuffer);
        NRF_UARTE0->TXD.MAXCNT = sizeof(txBuffer);
        NRF_UARTE0->TASKS_STARTTX = 0;
    
        NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
        NRF_UARTE0->RXD.MAXCNT = 5;
        NRF_UARTE0->TASKS_STARTRX = 1;
    
    
        //NRF_UARTE0->INTENCLR = 0xFFFFFFFF;
        NRF_UARTE0->INTENSET = (1 << 4) | (1 << 2);
    
        NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
        NVIC_SetPriority(UARTE0_UART0_IRQn, 6);
        NVIC_EnableIRQ(UARTE0_UART0_IRQn);
    
        NRF_UARTE0->TASKS_STARTTX = 0x01;
        while(!NRF_UARTE0->EVENTS_TXSTARTED){}
    
        uint8_t i=0;
        SEGGER_RTT_printf(0, "Sequence check\n");
        while (true)
        {
        	if(NRF_UARTE0->EVENTS_RXDRDY == 1){
        		SEGGER_RTT_printf(0, "Test %d : %d, %d\n", i++, rxBuffer[0], rxBuffer[1]);
        		NRF_UARTE0->EVENTS_RXDRDY = 0;
        	}
        	if(NRF_UARTE0->EVENTS_ENDRX == 1){
        		SEGGER_RTT_printf(0, "END RX Event!!!\n");
        		NRF_GPIO->OUTCLR = (1 << 23);
        		memset(rxBuffer, 0, sizeof(rxBuffer));
        		NRF_UARTE0->EVENTS_ENDRX = 0;
        	}
        	if(i >= 5){
        		i = 0;
        	}
    
        }
    }
    

    I can't get any data from RTT viewer.

    What did I do wrong?

    *Modiefied attatched code.

  • I think it could be HW related seeing that the same code worked on my side. Were you testing this on a nordic or custom board? Are you using the Segger IC as the USB - UART bridge?

  • It is custom board. I use cp2104 as uart bridge. I can use normal UART interrupt, but the problems only happens when I use UARTE.

Related