Skip to main content
Visitor II
September 12, 2022
Solved

ST25R3914/5 porting issue

  • September 12, 2022
  • 18 replies
  • 2828 views

We are trying to interface ST25R3914/5 NFC reader IC with another microcontroller through SPI communication. But while the ST NFC reader IC is not able to detect the card.

Can you please tell what all steps are to be considered before interfacing NFC I

    This topic has been closed for replies.
    Best answer by cGosa.1

    Hello,

    After checking it was interrupt priority issue also the stack code was disabling interrupt so after enabling interrupt from st25r3911_com.c file it is working properly and I am able to detect data.

    Thanks for your support!

    18 replies

    Technical Moderator
    September 13, 2022

    Hi,

    having ST25R_SELFTEST and ST25R_SELFTEST_TIMER in platform.h should be fine.

    Regarding the ISR r_intc2_interrupt, I see that  you set NFC_intflag to 1. Then my question is when is st25r3911Isr being called? Would it be possible to call st25r3911Isr from r_intc2_interrupt()?

    Rgds

    BT

    cGosa.1Author
    Visitor II
    September 14, 2022

    Hello,

    After setting NFC_intflag to 1 I am calling st25r3911Isr() from another application code

    void NfcCanInit(void)
    {
    	st_NfcBckup.byte = (U1)0;
    	u1_NfcInitEnCnt = (U1)0;
    	EDAL_time_milliseconds = (U4)0;
    	U2_mSecCount = (U2)0;
     	//R_CSI11_CsEnbl();	
     	//u1_NfcInitFd = demoIni();
    	R_INTC2_Start();
    	if(!demoIni())
    	{
    		while(1);
    	}
    while(1)
    {
    	if(NFC_intflag==1)
     	{ 	 
    		NFC_intflag=0;
     		st25r3911Isr();
    	
     	}
    		demoCycle();
    }

    Also I have tried to call st25r3911Isr(); function from r_intc2_interrupt(),it is observed that control come in condition while(IRQ_PIN==1) only once and then it gets stuck in st25r3911ReadMultipleRegisters() function on line,

     /* Since the result comes one byte later, let's first transmit the adddress with discarding the result */

        platformSpiTxRx(&cmd, NULL, ST25R3911_CMD_LEN);

    unsigned int IRQpinCheck;
    void st25r3911CheckForReceivedInterrupts( void )
    {
     uint8_t iregs[ST25R3911_INT_REGS_LEN];
     uint32_t irqStatus; 
    	//uint8_t IRQ_PIN=1;
     irqStatus = ST25R3911_IRQ_MASK_NONE;
     ST_MEMSET( iregs, (int32_t)(ST25R3911_IRQ_MASK_ALL & 0xFFU), ST25R3911_INT_REGS_LEN ); /* MISRA 10.3 */
     
     /* In case the IRQ is Edge (not Level) triggered read IRQs until done */
     //while( platformGpioIsHigh( ST25R391X_INT_PORT, ST25R391X_INT_PIN ) )
     //while((u1_Get_MCAL_Port_PinSts(ST25R391X_INT_PORT, ST25R391X_INT_PIN)))
     while(IRQ_PIN==1)
     
     {
    	 IRQ_PIN=0;
    	 IRQpinCheck++;
     st25r3911ReadMultipleRegisters(ST25R3911_REG_IRQ_MAIN, iregs, sizeof(iregs));

    Technical Moderator
    September 14, 2022

    Hi,

    the NfcCanInit code cannot properly work (deadlock):

    while(1)
    {
    	if(NFC_intflag==1)
     	{ 	 
    		NFC_intflag=0;
     		st25r3911Isr();
     	}
    	demoCycle();
    }

    because st25r3911interrupt.status is shared between st25r3911Isr and some functions being called in task mode such as st25r3911WaitForInterruptsTimed. This function waits in a blocking way that the value of st25r3911interrupt.status is being changed when st25r3911Isr reads the ST25R3911B Interrupt register.

    If you are running bare metal application, the st25r3911Isr has to be called inside the interrupt routine;

    if your application uses an RTOS, the st25r3911Isr has to be run in a higher priority task/thread that is unblocked by the interrupt routine.

    Rgds

    BT

    cGosa.1Author
    Visitor II
    September 15, 2022

    Hello,

    Yes now  I have tried to call st25r3911Isr(); function from interrupt service routine ,it is observed that control come in isr of interrupt only once and then it gets stuck in st25r3911ReadMultipleRegisters() function on line,

     /* Since the result comes one byte later, let's first transmit the adddress with discarding the result */

        platformSpiTxRx(&cmd, NULL, ST25R3911_CMD_LEN);

    Initial spi communication works fine and one time interrupt comes but after that spi communication is not completing and getting stuck here in st25r3911_com.c file.

    Why is it happening that after receiving int from nfc IC SPI communication is not working,

    void st25r3911ReadMultipleRegisters(uint8_t reg, uint8_t* values, uint8_t length)
    {
    #if !defined(ST25R391X_COM_SINGLETXRX)
     uint8_t cmd = (reg | ST25R3911_READ_MODE);
    #endif /* !ST25R391X_COM_SINGLETXRX */
     
     if (length > 0U)
     {
     platformProtectST25R391xComm();
     platformSpiSelect();
    		 NOP(); NOP();
    #ifdef ST25R391X_COM_SINGLETXRX
     
     ST_MEMSET( comBuf, 0x00, MIN( (ST25R3911_CMD_LEN + (uint32_t)length), ST25R3911_BUF_LEN ) );
     comBuf[0] = (reg | ST25R3911_READ_MODE);
     
     platformSpiTxRx(comBuf, comBuf, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); /* Transceive as a single SPI call */
     
    		while(SPI_TX_flag==0)
     	{
     	 		;
     		}
    	
    	ST_MEMCPY( values, &comBuf[ST25R3911_CMD_LEN], MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); /* Copy from local buf to output buffer and skip cmd byte */
     
    #else /* ST25R391X_COM_SINGLETXRX */
     
     /* Since the result comes one byte later, let's first transmit the adddress with discarding the result */
     platformSpiTxRx(&cmd, NULL, ST25R3911_CMD_LEN);
     
     		while(SPI_TX_flag==0) // SPI_TX_flag not setting to 1
     {
     	;
     }
    		
     platformSpiTxRx(NULL, values, length);
    	
    		while(SPI_TX_flag==0)
     {
     	;
     }
     
    #endif /* ST25R391X_COM_SINGLETXRX */
    		 NOP(); NOP();
     platformSpiDeselect();
     platformUnprotectST25R391xComm();
     }
     
     return;
    }

    ,

    cGosa.1Author
    Visitor II
    September 15, 2022

    These are our interrupt and spi settings please suggest if something it is configured correctly,0693W00000SvRHFQA3.png0693W00000SvRGgQAN.png0693W00000SvRFyQAN.png

    Technical Moderator
    September 15, 2022

    Hi,

    as I told before, the logic analyzer traces indicate correct configuration. As to your other configuration we cannot comment. Also I don't know what your SPI_TX_flag really is.

    Please check if your SPI driver can be called from a GPIOs interrupt service routine. It may happen that you need use nested interrupts and give the SPI IRQ a higher prio than the GPIO IRQ. Or move the SPI driver to not use IRQ, etc.

    Best Regards, Ulysses

    cGosa.1Author
    Visitor II
    September 16, 2022

    Hello,

    The SPI_TX_flag is used for spi transmission complete flag , So initially SPI is sending data to NFC IC and after IC initialization Interrupt is coming only once and SPI communication is stucking , we have tried to change priority of SPI INT as high and GPIO INT as low still facing same issue. Also we are using bare metal application so called str25r3911() from interrupt isr only.

    We are not able to find the cause behind this problem please suggest if something we are missing.

    cGosa.1AuthorAnswer
    Visitor II
    September 19, 2022

    Hello,

    After checking it was interrupt priority issue also the stack code was disabling interrupt so after enabling interrupt from st25r3911_com.c file it is working properly and I am able to detect data.

    Thanks for your support!

    Technical Moderator
    September 19, 2022

    well done!

    Rgds

    BT