ST意法半导体
直播中

张勇

7年用户 1420经验值
私信 关注
[问答]

ST25R911B阅读器和ST25DV04K标签之间如何建立通信呢

大家好,
我需要你的帮助:
我想在 ST25R911B 阅读器和 ST25DV04K 标签之间建立通信
我能够将数据从阅读器写入转发器,并且还得到一个中断 (XYZ)。现在我想回答读者。我通过 I2C 将数据写入邮箱。当读者阅读邮箱时,我收到超时或无效请求错误。
标签代码:
初始化:
  • void MX_NFC_Init(void)
  • {
  •         const ST25DV_PASSWD st25dv_i2c_password = {.MsbPasswd = 0, .LsbPasswd=0};
  •         char txtbuf[] = "Initialize NFC-TagrnReset Mailbox and allow write to EEPROMrn Select NFC Type 5rn";
  •         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 Protocolrn"};
  •                  HAL_UART_Transmit(&huart2, (uint8_t*) txtbuf, sizeof(txtbuf), 100);
  •                  /* Init of the Type Tag 5 component (M24LR) */
  •                  while( NfcType5_TT5Init( ) != NFCTAG_OK );
  •          }
  • }
处理传入的 GPO(GPOActivated 在 GPO 回调中设置)
  • 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 getrn", 13, 50 );
  •                         HAL_Delay(10);
  •                 }
  •                 if( ITStatus == ST25DV_ITSTS_DYN_RFPUTMSG_MASK)
  •                 {
  •                         /* read mailbox */
  •                         HAL_UART_Transmit(&huart2, "message putrn", 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, "rnMessage is:rn", 16, 50);
  •                         HAL_Delay(10);
  •                         HAL_UART_Transmit(&huart2, data, 12, 50);
  •                         HAL_Delay(10);
  •                         HAL_UART_Transmit(&huart2, "rnrn", 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 Readerrn"};
  •                         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 detectedrn", 20, 50 );
  •                         HAL_Delay(10);
  •                 }
  •                 GPOActivated = 0;
  •         }
  • }
来自读者的代码:
  • 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: %srn", 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, ®content[0]);
  •                             /* check if tag is powered by vcc */
  •                             states[1] = rfalST25xVPollerReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
  •                                             nfcDevice->dev.nfcv.InvRes.UID, 0x02, ®content[1]);
  •                             /* check if MB (fast transfer mode) is enabled */
  •                             states[2] = rfalST25xVPollerReadConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
  •                                             nfcDevice->dev.nfcv.InvRes.UID, 0x0D, ®content[2]);
  •                                 states[3] = rfalST25xVPollerReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT,
  •                                                                                                                 nfcDevice->dev.nfcv.InvRes.UID, 0x0D, ®content[3]);
  •                             uint8_t txbuf[30] ={0};
  •                             uint8_t msgdata[] = "Hello Tag";
  •                             uint16_t len=0;
  •                             uint8_t rxbuf[300] ={0};
  •                             platformLog("rnrn written into Mailbox rnrn");
  •                             /* 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, ®content[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 completedrnTag can be removed from the fieldrn");
  •                             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;
  •             }



回帖(1)

田野

2022-12-20 11:09:42
ST25 嵌入式 NFC 库示例默认适用于  NUCLEO-L476RG,因此您必须在 STM32F401RE 上进行移植。
我建议使用 STM32CubeMX 通过正确初始化 SPI 和中断引脚为 STM32F401RE 生成项目,然后手动导入各种源文件和包含文件。还要确保从 FTM 示例(例如 ST25R3916 定义)导入各种定义,但与 NUCLEO-L476RG 相关的定义除外。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分