PN7150 as a tag to send NDEF_MESSAGE

Hi
thank you for reading my post, and for your help. I would need advice in the following:
I useing PN7150 as a tag. And use the lib of Electroniccats_PN7150 ,and the demo of “DetectingReaders”。Fortunately, when Reader approached, the log showed ""Reader detected!" ", but actually I want to send a custom "NDEF_MESSAGE" via PN7150。

void setup(){
  Serial.begin(115200);
  while(!Serial);
  Serial.println("Detect P2P devices with PN7150");
  
  Serial.println("Initializing...");   

  if(T4T_NDEF_EMU_SetMessage((unsigned char *) NDEF_MESSAGE, sizeof(NDEF_MESSAGE), (void*)*NdefPush_Cb))
  {
    Serial.printf("Set message ok\r\n");  
  }
  else
  {
    Serial.printf("Set message error\r\n");  
  

  if (nfc.connectNCI()) { //Wake up the board
    Serial.println("Error while setting up the mode, check connections!");
    while (1);
  }
  
  if (nfc.ConfigureSettings()) {
    Serial.println("The Configure Settings failed!");
    while (1);
  }
  
  if(nfc.ConfigMode(mode)){ //Set up the configuration mode
    Serial.println("The Configure Mode failed!!");
    while (1);
  }
  nfc.StartDiscovery(mode); //NCI Discovery mode
  Serial.println("Waiting for a P2P device...");
}

unsigned char STATUSOK[] = {0x90, 0x00}, Cmd[256], CmdSize;

void loop(){

  if(nfc.CardModeReceive(Cmd, &CmdSize) == 0) { //Data in buffer?
      if ((CmdSize >= 2) && (Cmd[0] == 0x00)) { //Expect at least two bytes
          switch (Cmd[1]) {
              case 0xA4: //Something tries to select a file, meaning that it is a reader
                  Serial.println("Reader detected!");
                  break;
  
              case 0xB0: //SFI
              Serial.println("0xB0 detected!");
                  break;
  
              case 0xD0: //...
              Serial.println("0xD0 detected!");
                  break;
  
              default:
                  break;
          }
          nfc.CardModeSend(STATUSOK, sizeof(STATUSOK));
      }
  }

}

What should I do

I fix it!
Method of ProcessCardMode need some changed, As follows:

void Electroniccats_PN7150::ProcessCardMode(RfIntf_t RfIntf)
{
    uint8_t Answer[MAX_NCI_FRAME_SIZE];

    uint8_t NCIStopDiscovery[] = {0x21, 0x06, 0x01, 0x00};
    bool FirstCmd = true;

    /* Reset Card emulation state */
    T4T_NDEF_EMU_Reset();

   // (void)writeData(NCIStartDiscovery, NCIStartDiscovery_length);
    getMessage(2000);
    //NxpNci_WaitForReception(Answer, sizeof(Answer), &AnswerSize, TIMEOUT_2S) == NXPNCI_SUCCESS

    while (rxMessageLength > 0)
    {
      getMessage(2000);
        /* is RF_DEACTIVATE_NTF ? */
        if ((rxBuffer[0] == 0x61) && (rxBuffer[1] == 0x06))
        {
            if (FirstCmd)
            {
                /* Restart the discovery loop */
                //NxpNci_HostTransceive(NCIStopDiscovery, sizeof(NCIStopDiscovery), Answer, sizeof(Answer), &AnswerSize);
                (void)writeData(NCIStopDiscovery, sizeof(NCIStopDiscovery));
                getMessage();
                do
                {
                    if ((rxBuffer[0] == 0x41) && (rxBuffer[1] == 0x06))
                        break;
                    //NxpNci_WaitForReception(Answer, sizeof(Answer), &AnswerSize, TIMEOUT_100MS);
                    //(void)writeData(rxBuffer, rxMessageLength);
                    getMessage(100);
                } while (rxMessageLength != 0);
                //NxpNci_HostTransceive(NCIStartDiscovery, NCIStartDiscovery_length, Answer, sizeof(Answer), &AnswerSize);
                (void)writeData(NCIStartDiscovery, NCIStartDiscovery_length);
                getMessage();
            }
            /* Come back to discovery state */
           // break;
        }
        /* is DATA_PACKET ? */
        else if ((rxBuffer[0] == 0x00) && (rxBuffer[1] == 0x00))
        {
            /* DATA_PACKET */
            uint8_t Cmd[MAX_NCI_FRAME_SIZE];
            uint16_t CmdSize;

            T4T_NDEF_EMU_Next(&rxBuffer[3], rxBuffer[2], &Cmd[3], (unsigned short *)&CmdSize);

            Cmd[0] = 0x00;
            Cmd[1] = (CmdSize & 0xFF00) >> 8;
            Cmd[2] = CmdSize & 0x00FF;

            //NxpNci_HostTransceive(Cmd, CmdSize+3, Answer, sizeof(Answer), &AnswerSize);
            (void)writeData(Cmd, CmdSize + 3);
            getMessage();
        }
        FirstCmd = false;
    }
}
``
`

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.