cancel
Showing results for 
Search instead for 
Did you mean: 

Communication between St25DV04K and ST25R911B

RWalt.2
Associate

Hello guys,

i need your Help:

I would like to establish communication between the ST25R911B reader and the ST25DV04K tag.

I am able to write data from the reader to the transponder and I also get an interrupt (XYZ). Now I would like to answer the reader. I get the data written into the mailbox via I2C. When the reader reads the mailbox, I either get a timeout or an Invalid Request Error.

Code of the Tag:

Initialization:

void MX_NFC_Init(void)
{
	const ST25DV_PASSWD st25dv_i2c_password = {.MsbPasswd = 0, .LsbPasswd=0};
 
	char txtbuf[] = "Initialize NFC-Tag\r\nReset Mailbox and allow write to EEPROM\r\n Select NFC Type 5\r\n";
	HAL_UART_Transmit(&huart2, (uint8_t*) txtbuf, sizeof(txtbuf), 100);
 
	/* Init ST25DV driver */
	while( NFC04A1_NFCTAG_Init(NFC04A1_NFCTAG_INSTANCE) != NFCTAG_OK );
 
	/* Init GPO */
	MX_NFC04A1_GPO_Init();
 
	ST25DV_EN_STATUS MB_mode;
 
	/* If not activated, activate Mailbox, as long as MB is ON EEPROM is not available */
	NFC04A1_NFCTAG_ReadMBMode(NFC04A1_NFCTAG_INSTANCE, &MB_mode);
	if( MB_mode == ST25DV_DISABLE )
	{
		ST25DV_I2CSSO_STATUS i2csso;
		ST25DV_PASSWD passwd;
 
		/* You need to present password before changing static configuration */
		NFC04A1_NFCTAG_ReadI2CSecuritySession_Dyn(NFC04A1_NFCTAG_INSTANCE, &i2csso );
		if( i2csso == ST25DV_SESSION_CLOSED )
		{
			  /* if I2C session is closed, present password to open session */
			  passwd.MsbPasswd = 0; /* Default value for password */
			  passwd.LsbPasswd = 0; /* change it if password has been modified */
			  NFC04A1_NFCTAG_PresentI2CPassword(NFC04A1_NFCTAG_INSTANCE, passwd );
		}
		NFC04A1_NFCTAG_WriteMBMode(NFC04A1_NFCTAG_INSTANCE,ST25DV_ENABLE);
 
		/*enable interrupts (I2C Protection) */
		NFC04A1_NFCTAG_ConfigIT(NFC04A1_NFCTAG_INSTANCE,
		  ( ST25DV_GPO_FIELDCHANGE_MASK |
			ST25DV_GPO_RFPUTMSG_MASK |
			ST25DV_GPO_RFGETMSG_MASK |
			ST25DV_GPO_ENABLE_MASK ) );
 
		/* Close session as dynamic register doesn't need open session for modification */
		passwd.MsbPasswd = 123;
		passwd.LsbPasswd = 123;
		NFC04A1_NFCTAG_PresentI2CPassword(NFC04A1_NFCTAG_INSTANCE, passwd );
	}
 
	/* Enable Mailbox in dynamique register */
	NFC04A1_NFCTAG_SetMBEN_Dyn(NFC04A1_NFCTAG_INSTANCE);
 
	/* Check if Mailbox is available */
	NFC04A1_NFCTAG_ReadMBCtrl_Dyn( NFC04A1_NFCTAG_INSTANCE,&mbctrldynstatus );
 
	 NfcTag_SelectProtocol(NFCTAG_TYPE5);
 
	 /* Check if no NDEF detected, init mem in Tag Type 5 */
	 if( NfcType5_NDEFDetection( ) != NDEF_OK )
	 {
		 CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;
		 CCFileStruct.Version = NFCT5_VERSION_V1_0;
		 CCFileStruct.MemorySize = ( ST25DV_MAX_SIZE / 8 ) & 0xFF;
		 CCFileStruct.TT5Tag = 0x05;
 
		 char txtbuf1[] = {"Initialization NFC Type5 Protocol\r\n"};
		 HAL_UART_Transmit(&huart2, (uint8_t*) txtbuf, sizeof(txtbuf), 100);
 
		 /* Init of the Type Tag 5 component (M24LR) */
		 while( NfcType5_TT5Init( ) != NFCTAG_OK );
	 }
}

Handling incomming GPO (GPOActivated is set in the GPO Callback)

void MX_NFC4_NDEF_Process(void)
{
	ST25DV_FIELD_STATUS FieldStatus;
	uint8_t ITStatus;
 
	/* recognized interrupt */
	if( GPOActivated == 1 )
	{
		/* check if RF-Field changed */ //check return if always on or only at beginning
		NFC04A1_NFCTAG_GetRFField_Dyn(NFC04A1_NFCTAG_INSTANCE, &FieldStatus );
 
		/* get all other interrput sources */
		NFC04A1_NFCTAG_ReadITSTStatus_Dyn(NFC04A1_NFCTAG_INSTANCE, &ITStatus);
 
		if( ITStatus == ST25DV_ITSTS_DYN_RFGETMSG_MASK)
		{
			/* read mailbox */
			HAL_UART_Transmit(&huart2, "message get\r\n", 13, 50 );
			HAL_Delay(10);
		}
		if( ITStatus == ST25DV_ITSTS_DYN_RFPUTMSG_MASK)
		{
			/* read mailbox */
			HAL_UART_Transmit(&huart2, "message put\r\n", 13, 50 );
 
			uint8_t data[50] = {0};
 
			NFC04A1_NFCTAG_ReadMailboxData(NFC04A1_NFCTAG_INSTANCE, &data, 0, 49);
			//uint16_t NDEF_ReadText( sRecordInfo_t *pRecordStruct, NDEF_Text_info_t *pText )
			HAL_Delay(10);
 
			HAL_UART_Transmit(&huart2, "\r\nMessage is:\r\n", 16, 50);
			HAL_Delay(10);
 
			HAL_UART_Transmit(&huart2, data, 12, 50);
			HAL_Delay(10);
 
			HAL_UART_Transmit(&huart2, "\r\n\r\n", 14, 50);
			HAL_Delay(10);
 
			ST25DV_MB_CTRL_DYN_STATUS mbctrldynstatus;
 
			/* Check if Mailbox is available */
			NFC04A1_NFCTAG_ReadMBCtrl_Dyn( NFC04A1_NFCTAG_INSTANCE,&mbctrldynstatus );
 
			/* Write Data into Mailbox*/
			const uint8_t buf[]={"Hello Reader\r\n"};
			int32_t ret = 0;
 
			/* If MB is available, write data */
			if( (mbctrldynstatus.HostPutMsg == 0) && (mbctrldynstatus.RfPutMsg == 0) )
			{
				ret = NFC04A1_NFCTAG_WriteMailboxData( NFC04A1_NFCTAG_INSTANCE, buf, 14 );
 
				__NOP();
			}
 
			__NOP();
 
		}
		else if( FieldStatus == ST25DV_FIELD_ON )
		{
			/* power up device */
			HAL_UART_Transmit(&huart2, "RF field detected\r\n", 20, 50 );
			HAL_Delay(10);
		}
 
		GPOActivated = 0;
	}
 
}

Code from Reader:

if( rfalNfcIsDevActivated( rfalNfcGetState() ) )
            {
                rfalNfcGetActiveDevice( &nfcDevice );
                
                ledsOff();
                platformDelay(50);
                ndefDemoPrevFeature = 0xFF; /* Force the display of the prompt */
 
                            uint8_t devUID[RFAL_NFCV_UID_LEN];
                            
                            ST_MEMCPY( devUID, nfcDevice->nfcid, nfcDevice->nfcidLen );   /* Copy the UID into local var */
                            REVERSE_BYTES( devUID, RFAL_NFCV_UID_LEN );                 /* Reverse the UID for display purposes */
                            platformLog("ISO15693/NFC-V card found. UID: %s\r\n", hex2Str(devUID, RFAL_NFCV_UID_LEN));
                        
                            platformLedOn(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN);
                            
                            /* Try to read a register */
                            uint8_t addr = 0x00;
                            uint8_t regcontent[30] = {0x0};
                            ReturnCode states[10] = {0};
 
                            /* read enabled irq*/
                            states[0] = rfalST25xVPollerReadConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
                            		nfcDevice->dev.nfcv.InvRes.UID, addr, &regcontent[0]);
 
                            /* check if tag is powered by vcc */
                            states[1] = rfalST25xVPollerReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
                            		nfcDevice->dev.nfcv.InvRes.UID, 0x02, &regcontent[1]);
 
                            /* check if MB (fast transfer mode) is enabled */
                            states[2] = rfalST25xVPollerReadConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
                            		nfcDevice->dev.nfcv.InvRes.UID, 0x0D, &regcontent[2]);
 
                        	states[3] = rfalST25xVPollerReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
														nfcDevice->dev.nfcv.InvRes.UID, 0x0D, &regcontent[3]);
 
 
                            uint8_t txbuf[30] ={0};
                            uint8_t msgdata[] = "Hello Tag";
                            uint16_t len=0;
                            uint8_t rxbuf[300] ={0};
 
                            platformLog("\r\n\r\n written into Mailbox \r\n\r\n");
                            
                            /* write into Mailbox */
                            states[4] = rfalST25xVPollerFastWriteMessage( RFAL_NFCV_REQ_FLAG_DEFAULT,
                            		nfcDevice->dev.nfcv.InvRes.UID, 11, msgdata, txbuf, 25);
 
                            /* read dynamic configuration */
                            states[3] = rfalST25xVPollerReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
									nfcDevice->dev.nfcv.InvRes.UID, 0x0D, &regcontent[3]);
                            
                            /* Read from Mailbox */
							states[5] = rfalST25xVPollerFastReadMessage(RFAL_NFCV_REQ_FLAG_DEFAULT,
									nfcDevice->dev.nfcv.InvRes.UID, 0, 30, rxbuf, sizeof(rxbuf), &len);
 
 
                            /* Loop until tag is removed from the field */
                            platformLog("Operation completed\r\nTag can be removed from the field\r\n");
                            rfalNfcvPollerInitialize();
                            while (rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, RFAL_NFCV_UID_LEN * 8U, nfcDevice->dev.nfcv.InvRes.UID, &invRes, &rcvdLen) == ERR_NONE)
                            {
                                platformDelay(130);
                            }
                
                rfalNfcDeactivate( false );
                platformDelay( 500 );
                state = DEMO_ST_START_DISCOVERY;
            }

Thank you guys!

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi Rebecca,

the  ST25 Embedded NFC library examples are by default for NUCLEO-L476RG so you will have to port on your STM32F401RE.

I would suggest to use STM32CubeMX to generate the project for the STM32F401RE with the proper initialisation of the SPI and interrupt pin and then to import the various source and include files manually. Also make sur to import the various defines from the FTM example (e.g. ST25R3916 define) except the ones related to NUCLEO-L476RG

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3
Brian TIDAL
ST Employee

Hi Rebecca,

the ST25 Embedded NFC library provides an easy to use middleware for communication over the ST25DV mailbox. This middleware manages retries and provides a reliable data transfer. A ready to use example is available in the FTM (Fast Transfer Mode) project of the ST25 Embedded NFC library for ST25R3911B.

I would suggest to use this middleware for your application

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
RWalt.2
Associate

Hi Brain,

thx a lot for your help. But there is one problem left. My ST25R911b is mounted on a STM32F401RE uC. Is there a easy way to change the target in CubeIDE? Or do i have to copy/paste manually?

Regards

Rebecca

Brian TIDAL
ST Employee

Hi Rebecca,

the  ST25 Embedded NFC library examples are by default for NUCLEO-L476RG so you will have to port on your STM32F401RE.

I would suggest to use STM32CubeMX to generate the project for the STM32F401RE with the proper initialisation of the SPI and interrupt pin and then to import the various source and include files manually. Also make sur to import the various defines from the FTM example (e.g. ST25R3916 define) except the ones related to NUCLEO-L476RG

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.