2022-09-12 12:08 AM
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
Solved! Go to Solution.
2022-09-13 01:53 AM
Hi,
would you please provide a logic analyzer trace of the initialization sequence (i.e. from power up) with ST25R_SELFTEST and ST25R_SELFTEST_TIMER being enabled?
Can you print/log the value of u1_Get_MCAL_Port_PinSts(port, pin) for the interrupt pin just after power up and also when entering the interrupt routine?
Can you describe your implementation of platformProtectST25RIrqStatus and platformUnprotectST25RIrqStatus?
Rgds
BT
2022-09-13 03:47 AM
For implementation of platformProtectST25RIrqStatus and platformUnprotectST25RIrqStatus
#define platformProtectST25R391xComm() do{ globalCommProtectCnt++; R_INTC2_Stop();}while(0) /*!< Protect unique access to ST25R391x communication channel - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
#define platformUnprotectST25R391xComm() do{ if (--globalCommProtectCnt==0U) {R_INTC2_Start();} }while(0)
Also this ST25R_SELFTEST and ST25R_SELFTEST_TIMER I have added as #define in platform.h only Is it correct?
For interrupt we have configured like this:
//isr for INT
static void __near r_intc2_interrupt(void)
{
/* Start user code. Do not edit comment generated here */
PIF2 = 0U; /* clear INTP2 interrupt flag */
NFC_intflag=1;
/* End user code. Do not edit comment generated here */
}
void R_INTC2_Start(void)
{
PIF2 = 0U; /* clear INTP2 interrupt flag */
PMK2 = 0U; /* enable INTP2 interrupt */
}
2022-09-13 04:35 AM
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
2022-09-13 10:47 PM
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));
2022-09-14 09:36 AM
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
2022-09-15 12:02 AM
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;
}
,
2022-09-15 12:16 AM
These are our interrupt and spi settings please suggest if something it is configured correctly,
2022-09-15 02:16 AM
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
2022-09-15 11:17 PM
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.
2022-09-19 12:11 AM
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!