IRQ_DIRECT_CONNECT not calling the ISR function

Hello. I'm trying to call an interrupt service routine (ISR) using IRQ_DIRECT_CONNECT, but it is not working.


Here is the flow of my code:

ISR_DIRECT_DECLARE(TWIM_IRQHandler){
    printk("TWIM Interrupt Triggered\r\n");
    return 1; // Return 1 to indicate that a scheduling decision may be needed
}

void Init(
// Pins
NRF_TWIM0->PSEL.SDA = this->config.pin_sda;
NRF_TWIM0->PSEL.SCL = this->config.pin_scl;

// Freq.
NRF_TWIM0->FREQUENCY = this->config.frequency;

// RX/TX buffers
NRF_TWIM0->RXD.PTR = (uint32_t)rxBuffer;
NRF_TWIM0->RXD.MAXCNT = sizeof(rxBuffer);
NRF_TWIM0->RXD.LIST = 0;
NRF_TWIM0->TXD.PTR = (uint32_t)txBuffer;
NRF_TWIM0->TXD.LIST = 0;

// Enable
NRF_TWIM0->ENABLE = 0x06;
}

void enableIRQ(){
    NRF_TWIM0->INTENSET = irq_type;
    IRQ_DIRECT_CONNECT(SPIM0_SPIS0_TWIM0_TWIS0_UARTE0_IRQn, 0, TWIM_IRQHandler, 0);
    irq_enable(SPIM0_SPIS0_TWIM0_TWIS0_UARTE0_IRQn);
}

So, it is expected to print out 'TWIM Interrupt Triggered', but there are no events shown in my RTT viewer.

Here is prj.conf

# RTT Debugging
CONFIG_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_CBPRINTF_COMPLETE=y
CONFIG_CBPRINTF_FP_SUPPORT=y

# General
CONFIG_ZERO_LATENCY_IRQS=y
CONFIG_SHARED_INTERRUPTS=y
CONFIG_I2C=y

The purpose of this code is to get raw data from I²C devices through interrupts in order to prevent system blocking.

When I try to get it using blocking functions, it works fine.(Please see the code below)

void TWIM::Read(uint8_t addr, uint8_t *recv, uint8_t recv_length, uint8_t *write, uint8_t write_length){
    // Reading data from I2C devices
    uint8_t *output = recv;
    memset(txBuffer, 0x00, sizeof(txBuffer));
    memset(rxBuffer, 0x00, sizeof(rxBuffer));
    memcpy(txBuffer, write, write_length);
    switch(config.instance){
        case TWIM_INSTANCE_TWIM1:
            NRF_TWIM1->ADDRESS = addr;
            NRF_TWIM1->TXD.MAXCNT = write_length;
            NRF_TWIM1->TASKS_STARTTX = 1;
            while(!NRF_TWIM1->EVENTS_LASTTX){}
            NRF_TWIM1->EVENTS_LASTTX = 0;
		    NRF_TWIM1->TASKS_STARTRX = 1;
		    while(!NRF_TWIM1->EVENTS_LASTRX){}
		    NRF_TWIM1->EVENTS_LASTRX = 0;
		    NRF_TWIM1->TASKS_STOP = 1;
		    while(!NRF_TWIM1->EVENTS_STOPPED){}
		    NRF_TWIM1->EVENTS_STOPPED = 0;
		    for(uint8_t i=0;i<recv_length;i++){
			    output[i] = rxBuffer[i];
		    }
        break;
        case TWIM_INSTANCE_TWIM2:
            NRF_TWIM2->ADDRESS = addr;
            NRF_TWIM2->TXD.MAXCNT = write_length;
            NRF_TWIM2->TASKS_STARTTX = 1;
            while(!NRF_TWIM2->EVENTS_LASTTX){}
            NRF_TWIM2->EVENTS_LASTTX = 0;
		    NRF_TWIM2->TASKS_STARTRX = 1;
		    while(!NRF_TWIM2->EVENTS_LASTRX){}
		    NRF_TWIM2->EVENTS_LASTRX = 0;
		    NRF_TWIM2->TASKS_STOP = 1;
		    while(!NRF_TWIM2->EVENTS_STOPPED){}
		    NRF_TWIM2->EVENTS_STOPPED = 0;
		    for(uint8_t i=0;i<recv_length;i++){
			    output[i] = rxBuffer[i];
		    }
        break;
        case TWIM_INSTANCE_TWIM3:
            NRF_TWIM3->ADDRESS = addr;
            NRF_TWIM3->TXD.MAXCNT = write_length;
            NRF_TWIM3->TASKS_STARTTX = 1;
            while(!NRF_TWIM3->EVENTS_LASTTX){}
            NRF_TWIM3->EVENTS_LASTTX = 0;
		    NRF_TWIM3->TASKS_STARTRX = 1;
		    while(!NRF_TWIM3->EVENTS_LASTRX){}
		    NRF_TWIM3->EVENTS_LASTRX = 0;
		    NRF_TWIM3->TASKS_STOP = 1;
		    while(!NRF_TWIM3->EVENTS_STOPPED){}
		    NRF_TWIM3->EVENTS_STOPPED = 0;
		    for(uint8_t i=0;i<recv_length;i++){
			    output[i] = rxBuffer[i];
		    }
        break;
        default:
            NRF_TWIM0->ADDRESS = addr;
            NRF_TWIM0->TXD.MAXCNT = write_length;
            NRF_TWIM0->TASKS_STARTTX = 1;
            while(!NRF_TWIM0->EVENTS_LASTTX){}
            NRF_TWIM0->EVENTS_LASTTX = 0;
		    NRF_TWIM0->TASKS_STARTRX = 1;
		    while(!NRF_TWIM0->EVENTS_LASTRX){}
		    NRF_TWIM0->EVENTS_LASTRX = 0;
		    NRF_TWIM0->TASKS_STOP = 1;
		    while(!NRF_TWIM0->EVENTS_STOPPED){}
		    NRF_TWIM0->EVENTS_STOPPED = 0;
		    for(uint8_t i=0;i<recv_length;i++){
			    output[i] = rxBuffer[i];
		    }
        break;
    }
}

Related