cancel
Showing results for 
Search instead for 
Did you mean: 

STSW-ST25R-LIB using SPI while in IRQ context

afr_e2
Associate II

Hello everyone,

in a project we are using the ST25R3916 chip to read RFID cards. To do this we are using the sources of the STSW-ST25R-LIB library. If the ST25R3916 sets its IRQ output, the routine st25r3916isr() is called. In this ISR the interrupt registers are read via SPI.

void st25r3916Isr( void )
{
    st25r3916CheckForReceivedInterrupts();
    ...
}

void st25r3916CheckForReceivedInterrupts( void )
{
   ...
   /* In case the IRQ is Edge (not Level) triggered read IRQs until done */
   while( platformGpioIsHigh( ST25R_INT_PORT, ST25R_INT_PIN ) )
   {
       st25r3916ReadMultipleRegisters( ST25R3916_REG_IRQ_MAIN, iregs, ST25R3916_INT_REGS_LEN );
       ...
   }
   ...
}

As other components can be connected to this SPI bus, no SPI communication is alowed in the context of an interrupt, as otherwise 2 SPI operations can overlap and this can lead to undesirable effects.

How can I get around this problem? Is there some kind of polling mode or how can I move the SPI operation into the context of the main loop?

Thank you for your support!

Best regards,
Andy

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
10 REPLIES 10

Hi again,

thank you for your analysis. At first I just have modified the "WaitFor..." function. When modifying the GetInterrupt function also, everything works fine!

Here my mods:

uint32_t st25r3916GetInterrupt( uint32_t mask )
{
    if (platformGpioIsHigh( ST25R_INT_PORT, ST25R_INT_PIN ))
    {
        st25r3916Isr();
    }

    uint32_t irqs = (st25r3916interrupt.status & mask);
    if(irqs != ST25R3916_IRQ_MASK_NONE)
    {
        platformProtectST25RIrqStatus();
        st25r3916interrupt.status &= ~irqs;
        platformUnprotectST25RIrqStatus();
    }
    return irqs;
}​

It seems: that's it! Thank you for your assistance!

Best regards,

Andy