cancel
Showing results for 
Search instead for 
Did you mean: 

question about RF after writing in I2C

fab04
Associate II

Hi everybody,

I'm working on NFC tag. I'm using a ANT7-T-M24SR deb board. This one communicates in I2C with an ESP32.

First, I tried to read the dev board with a cellphone, and it worked well (URL : st.com)

Then I tried to write "Hello world" in the NDEF memory of M24SR and it was written into the memory, and I succeded to read it (only one time) with my cell phone.

So now, I have written another message, I think it's well writed into the memory (please see picture below) but I cannot read it with my cellphone.

I have one question :

  • After that I closed the I2C session, does I need to do something to reactivate the RF ? Because, by reading the System file, I see that the byte (offset = 0x0006) is sometimes at 0x09 (RF enabled) and sometimes at 0x00.

I hope my resquest is enough clear, please find below the different questions/answers between µc and M24SR.0693W00000QLcU5QAL.png 

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi Fabrice,

the NDEF is malformed. The text record has an incorrect payload length (0E):

0693W00000QLdLJQA1.jpgThe correct payload length for the Text record should be 1F:

0693W00000QLdLTQA1.jpg 

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

9 REPLIES 9
Brian TIDAL
ST Employee

Hi,

can you install the ST25 NFC Tap App on you smartphone and use this application to read/dump the raw content of the NDEF file after your last NDEF Write ?

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.
fab04
Associate II
#include <Wire.h>
 
#define GPO 17
#define DIS 16
 
#define NFC_ADDR_7BIT 0x56
 
void setup() 
{                
  pinMode(DIS,OUTPUT);
  digitalWrite(DIS,LOW);
  Wire.begin();
  Serial.begin(9600);
}
 
/* la lecture/écriture dans le mémoire du M24SR se fait selon une suite d'instructions */
 
/* kill RFC communication */
byte selectI2C[]      = {0x52};
/* Sélection de l'application NFC */
byte selectNFCApp[]   = {0x02,0x00,0xA4,0x04,0x00,0x07,0xD2,0x76,0x00,0x00,0x85,0x01,0x01,0x00,0x35,0xC0};
/* Selection Capability Container file */
byte selectCCFile[]   = {0x03,0x00,0xA4,0x00,0x0C,0x02,0xE1,0x03,0xD2,0xAF};
/* Read Capability Container file */
byte readCCLen[]      = {0x02,0x00,0xB0,0x00,0x00,0x02,0x6B,0x7D};
/* Read length Capability Container file */
byte readCCFile[]     = {0x03,0x00,0xB0,0x00,0x00,0x0F,0xA5,0xA2};
/* Selection System File */
byte selectSFFile[]  =  {0x03,0x00,0xA4,0x00,0x0C,0x02,0xE1,0x01,0xC0,0x8C};
/* Read System File */
byte readSFFile[]    =  {0x03,0x00,0xB0,0x00,0x00,0x11,0x5A,0x5B};
/* Sélection du NDEF file */
byte selectNDEFFile[] = {0x02,0x00,0xA4,0x00,0x0C,0x02,0x00,0x01,0x3E,0xFD};
/* Read length NDEF file */
byte readNDEFlen[]    = {0x03,0x00,0xB0,0x00,0x00,0x02,0x40,0x79};
/* Erase length NDEF file */
byte eraseNDEFLen[]   = {0x03,0x00,0xD6,0x00,0x00,0x02,0x00,0x00,0x6B,0x37};
                                                      /* 1    2   3    4     5   6    7     8    9   10    11   12  13   14   15   16   17  18    19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35*/
                        /*0     1    2   3     4    5    6    7   8    9    10   11   12   13   14   15    16   17  18   19   20   21   22  23    24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42
/* Write NDEF file */                                                                   /*  P    O    W    E    R         D    I    N              V    1    .    0              S    /    N    :    2    2    2    9    0    0    1 */
byte UpdateNDEFile[]  = {0x02,0x00,0xD6,0x00,0x02,0x23,0xD1,0x01,0x0E,0x54,0x02,0x65,0x6E,0x50,0x4F,0x57,0x45,0x52,0x20,0x44,0x49,0x4E,0x0D,0x0A,0x56,0x31,0x2E,0x30,0x0D,0x0A,0x53,0x2F,0x4E,0x3A,0x32,0x32,0x32,0x39,0x30,0x30,0x31,0x10,0x95};
/* FWTX */
byte FWTX[]           = {0xF2,0x03,0x83,0x63};
/* Write Length NDEF file */
byte UpdateNDEFLen[]  = {0x03,0x00,0xD6,0x00,0x00,0x02,0x00,0x23,0xF2,0x24};
/* Read NDEF file */
byte readNDEFMsg[]    = {0x02,0x00,0xB0,0x00,0x02,0x23,0x50,0x7E};
/* Deselect */
byte deselectI2C[]    = {0xC2,0xE0,0xB4};
 
// The delays are required, to allow the M24SR time to process commands.
 
void loop()
{
 
  /*ComputeCrc(UpdateNDEFLen, sizeof(UpdateNDEFLen)-2, &(UpdateNDEFLen[8]), &(UpdateNDEFLen[9]));
  Serial.println((UpdateNDEFLen[8]),HEX);
  Serial.println((UpdateNDEFLen[9]),HEX);*/
 
  delay(1000);
  Serial.println("\nstarting");
 
  // kill RF, select I2C
  Serial.println("selectI2C");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(selectI2C, sizeof(selectI2C));
  Wire.endTransmission();
  delay(1);
  
  //select NFC app
  Serial.println("selectNFCApp");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(selectNFCApp, sizeof(selectNFCApp));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(5);
  
  //select CC file
  Serial.println("selectCCFile");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(selectCCFile, sizeof(selectCCFile));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(5);
 
  //readCCLen
  Serial.println("readCCLen");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(readCCLen, sizeof(readCCLen));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(7);
 
  int len=20; //TODO get from above payload, not overly critical
 
  //readCCFile
  Serial.println("readCCFile");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(readCCFile, sizeof(readCCFile));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(len);
 
  //select SF file
  Serial.println("selectSFFile");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(selectSFFile, sizeof(selectSFFile));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(5);
 
 
  //read SF file
  Serial.println("readSFFile");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(readSFFile, sizeof(readSFFile));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(19);
 
  //selectNDEFFile
  Serial.println("selectNDEFFile");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(selectNDEFFile, sizeof(selectNDEFFile));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(5);
 
  // readNDEFlen
  Serial.println("readNDEFlen");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(readNDEFlen, sizeof(readNDEFlen));
  Wire.endTransmission();
  delay(1);
  readAndDisplay(5);
  
  //eraseNDEFLen
  Serial.println("eraseNDEFLen");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(eraseNDEFLen, sizeof(eraseNDEFLen));
  Wire.endTransmission();
  delay(10);
  readAndDisplay(5);
 
  //UpdateNDEFile
  Serial.println("UpdateNDEFile");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(UpdateNDEFile, sizeof(UpdateNDEFile));
  Wire.endTransmission();
  delay(100);
  readAndDisplay(4); 
 
  //FWTX
  Serial.println("FWTX");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(FWTX, sizeof(FWTX));
  Wire.endTransmission();
  delay(100);
  readAndDisplay(5); 
  
  //UpdateNDEFLen
  Serial.println("UpdateNDEFLen");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(UpdateNDEFLen, sizeof(UpdateNDEFLen));
  Wire.endTransmission();
  delay(10);
  readAndDisplay(5); 
  
  // readNDEFlen
  Serial.println("readNDEFlen");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(readNDEFlen, sizeof(readNDEFlen));
  Wire.endTransmission();
  delay(10);
  readAndDisplay(5);
  
 
int idx = 0;
  //readNDEFMsg
  //len = full NDEF length, (5 byte prefix+actual URI)
  Serial.println("readNDEFMsg");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  // Patch in the length and fix the broken CRC
  readNDEFMsg[5] = 35; // this is the len returned from ReadNDEFLen
  ComputeCrc(readNDEFMsg, sizeof(readNDEFMsg)-2, &(readNDEFMsg[6]), &(readNDEFMsg[7]));
  Wire.write(readNDEFMsg, sizeof(readNDEFMsg));
  Wire.endTransmission();
  delay(10);
  readAndDisplayASCII(36);
  
 
  //deselectI2C
  Serial.println("deselectI2C");
  Wire.beginTransmission(NFC_ADDR_7BIT);
  Wire.write(deselectI2C, sizeof(deselectI2C));
  Wire.endTransmission();
  delay(10);
  readAndDisplay(3);  
  
  delay(2000);
  digitalWrite(DIS,LOW);
  while(1);
 
}
 
void readAndDisplayASCII(int len)
{
  unsigned char idx = 0;
  unsigned char tab[] = {0};
  
  Wire.requestFrom(NFC_ADDR_7BIT, len);
  while (Wire.available())
  {
    tab[idx] = Wire.read();
    if(idx > 7)
    {
      Serial.print(char(tab[idx]));
      Serial.write(' ');
    }
    idx++;
  }
  Serial.println();
}
 
 
void readAndDisplay(int len)
{
  Wire.requestFrom(NFC_ADDR_7BIT, len);
  while (Wire.available())
  {
    Serial.print(Wire.read(), HEX);
    Serial.write(' ');
  }
  Serial.println();
}
 
 
word UpdateCrc(byte data, word *pwCrc)
{
  data = (data^(byte)((*pwCrc) & 0x00FF));
  data = (data^(data << 4));
  *pwCrc = (*pwCrc >> 8) 
         ^ ((word)data << 8) 
         ^ ((word)data << 3) 
         ^ ((word)data >> 4);
  return *pwCrc;
}
 
 
word ComputeCrc(byte *data, unsigned int len, byte *crc0, byte *crc1)
{
  byte bBlock;
  word wCrc;
 
  wCrc = 0x6363;
 
  do
  {
    bBlock = *data++;
    UpdateCrc(bBlock, &wCrc);
  }
  while (--len);
 
  *crc0 = (byte) (wCrc & 0xFF);
  *crc1 = (byte) ((wCrc >> 8) & 0xFF);
  return wCrc;
}
 
/* END OF FILE */

Hi,

Thank you for your quick answer.

I've tried with ST25 NFC tap App.

When the dev board is disconnected (without any supplies), the app can read the tag, but there is nothing in the NDEF tab (I cannot see my recorded text), but I've put in the memory the right bytes (0xD1,0x01...)0693W00000QLcqaQAD.pngWhen the dev board is connected to my ESP (VCC supply by it), nothing happens, the dev board is not detected.

If needed, please find above my code.

Brian TIDAL
ST Employee

Hi,

can you go to the MEMORY tab of the ST25 NFC Tap App and read the raw content of the NDEF file?

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.
fab04
Associate II

Hi,

So I went to the memory tab and then read memory. It seems to detect the tag but the app displays "command failed".

Brian TIDAL
ST Employee

Hi Fabrice,

the NDEF is malformed. The text record has an incorrect payload length (0E):

0693W00000QLdLJQA1.jpgThe correct payload length for the Text record should be 1F:

0693W00000QLdLTQA1.jpg 

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.
fab04
Associate II

Hi,

Thank you for your answer, it works. Effectively this byte correspond to the size of payload, and I forget to change it (I kept the size of my previous test).

Now, it works without any supplies (only the cellphone supplies the tag). So I need to check when the tag is supplied by VCC.

I'll let you inform.

Thank again.

JP Miller
Senior

Hi Fabrice

Indeed RF_enable has to be set to 1 in order to allow M24SR to answer to phone's requests. Otherwise the M24SR will stay mute with respect to RF NFC commands.

The bit in the system file is only writable from the I2C side so the MCU, and is never written by M24SR itself, unless instructed by the I2C master. You might want to check what in the MCU firmware execution might change this bit value.

Once fixed, other condition have to be fulfilled (RF Disable pin state, M24SR selected from the RF side, well formed NDEF message...)

Regards,

JP

fab04
Associate II

Hi everybody,

Thank you very much for all your answers, now it's working well. I can read the NDEF information even with my cell phone.

I just put RF disable pin at 0 with pull-down, then I do the different steps in I2C, and then I do a "while(1)" instruction.

I have just another question

@JP Miller​ 

what dou you mean with "M24SR selected from the RF side"

Thanks again

Fabrice

JP Miller
Senior

Hi Fabrice,

by 'M24SR selected from the RF side', it is meant that the M24SR has been activated - meaning the phone has performed the technology detection, collision resolution, device activation). As you have indicated the new NDEF message can read from the cell phone, that means that part is well taken care of and there's no issue there.

Regards

JP