The Texas Instruments Dynamic NFC Interface Transponder RF430CL330H is an NFC Tag Type 4 device that combines a wireless NFC interface and a wired SPI or I2C interface to connect the device to a host. The NDEF message in the SRAM can be written and read from the integrated SPI or I2C serial communication interface and can also be accessed and updated wirelessly.
Features:
- NFC Tag Type 4: The Type 4 tag offers the most flexibility and memory of all the tags. The most important reason to get this tag is security: It offers the functionality needed to perform true authentication.
- 3KB of SRAM for NDEF Messages: NDEF (NFC Data Exchange Format) is a light-weight binary format, used to encapsulate typed data. It is specified by the NFC Forum, for transmission and storage with NFC.
- 13.56-MHz RF Interface Supports up to 848 kbps
- Automatic Checking of NDEF Structure
- Interrupt Register and Output Pin to Indicate NDEF Read or Write Completion
- SPI or I 2C Interface to Write and Read NDEF Messages to Internal SRAM
Possible Applications:
- Diagnostic Interface: Data logging of certain parameters and sending to a phone/reader for monitoring purposes.
- Sensor Interface: Sending live sensor data to a phone/reader.
Absolute Maximum Ratings:
Typical values are specified at VCC = 3.3 V and TA = 25°C
Parameter |
MIN |
NOM |
MAX |
Unit |
|
Vcc |
Supply voltage during program execution no RF field present |
3.0 |
3.3 |
3.6 |
V |
Supply voltage during program execution with RF field present |
2.0 |
3.3 |
3.6 |
V |
|
Vss |
Supply voltage (GND reference) |
0 |
V |
||
Ta |
Operating free-air temperature |
-40 |
85 |
°C |
|
Fc |
Carrier Frequency |
13.56 |
Mhz |
||
Vant_peak |
Antenna peak input voltage |
3.6 |
V |
Wiring with ESP32 and reading data logs from a sensor using the RF430 breakout board:
In this example, we will be reading data logs of an inbuilt function called millis(), which returns the number of milliseconds passed since the ESP board began running the current program, to our phones using the RF430 board. The data from the function is stored in a Serial Peripheral Interface Flash File System until the user presses a button. As soon as the button is pressed, the NFC tag reads the contents of the file, prepares a message and transfers it to a nearby NFC reader (in this case our phone). When this transfer is complete, the existing file is erased and fresh data begins to be logged.
The connections for this example are given below:
RF430 Breakout |
NodeMCU ESP32S |
VCC |
3.3v |
GND |
GND |
SCL |
P22 |
SDA |
P21 |
RST |
Any Digital Pin (eg- P4) |
INT |
Any Digital Pin (eg - P5) |
The switch used in this example is connected to the P17 pin of the ESP board at one end and the GND pin at the other end.
The completed circuit will look like this:
Program:
/*In this example, we will be reading data logs of an inbuilt function called millis(), which returns the number of milliseconds passed since the ESP board began running the current program, to our phones using the RF430 board. The data from the function is stored in a Serial Peripheral Interface Flash File System until the user presses a button. As soon as the button is pressed, the NFC tag reads the contents of the file, prepares a message and transfers it to a nearby NFC reader(in this case our phone). On this transfer is complete, the existing file is erased and fresh data begins to be logged.*/#include "FS.h"#include "SPIFFS.h"#include <Wire.h>#include <RF430CL.h>#include <NDEF.h>#include <NDEF_TXT.h>#define FORMAT_SPIFFS_IF_FAILED true#define RF430CL330H_BOOSTERPACK_RESET_PIN 4 //Reset pin connected to ESP32#define RF430CL330H_BOOSTERPACK_IRQ_PIN 5 //Interrupt pin connected to ESP32#define UPDATE_DELAY 2000 //frequency at which SPIFFS needs to be updatedvolatile boolean update_trigger = false;RF430 nfc(RF430CL330H_BOOSTERPACK_RESET_PIN, RF430CL330H_BOOSTERPACK_IRQ_PIN);NDEF_TXT txt("en");char txtbuf[2048];uint32_t lastUpdate = millis();void listDir(fs::FS &fs, const char *dirname, uint8_t levels){Serial.printf("Listing directory: %s\r\n", dirname);File root = fs.open(dirname);if (!root){Serial.println("- failed to open directory");return;}if (!root.isDirectory()){Serial.println(" - not a directory");return;}File file = root.openNextFile();while (file){if (file.isDirectory()){Serial.print(" DIR : ");Serial.println(file.name());if (levels){listDir(fs, file.name(), levels - 1);}}else{Serial.print(" FILE: ");Serial.print(file.name());Serial.print("\tSIZE: ");Serial.println(file.size());}file = root.openNextFile();}}String readFile(fs::FS &fs, const char *path){Serial.printf("Reading file: %s\r\n", path);File file = fs.open(path);Serial.println("- read from file:");while (file.available()){String result;for (int j = 0; j < file.size(); j++){result += ((char)file.read());}Serial.println(result);return result;}}void writeFile(fs::FS &fs, const char *path, const char *message){Serial.printf("Writing file: %s\r\n", path);File file = fs.open(path, FILE_WRITE);if (!file){Serial.println("- failed to open file for writing");return;}if (file.print(message)){Serial.println("- file written");}else{Serial.println("- frite failed");}}void appendFile(fs::FS &fs, const char *path, const char *message){//Serial.printf("Appending to file: %s\r\n", path);File file = fs.open(path, FILE_APPEND);if (!file){Serial.println("- failed to open file for appending");return;}if (file.print(message)){Serial.println("- message appended");}else{Serial.println("- append failed");}}void deleteFile(fs::FS &fs, const char *path){Serial.printf("Deleting file: %s\r\n", path);if (fs.remove(path)){Serial.println("- file deleted");}else{Serial.println("- delete failed");}}void triggerTextUpdate(){update_trigger = true;}void setup(){Serial.begin(115200);if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){Serial.println("SPIFFS Mount Failed");return;}//Initializing I2CWire.begin();//Initializing NFC Tagnfc.begin();txt.setPayloadBuffer(txtbuf, 2048); /* <-- Payload buffer contents always get NUL-terminated, so be sure* your allocated buffer is 1 byte longer than the stated maximum size.*///Setting & appending values to bufferuint32_t tlen = txt.setText("Millis Data \n");//Writing Text object to NFC transceiverint ndef_size = txt.sendTo(nfc); // Export Text NDEF object to RF430's SRAMnfc.setDataLength(ndef_size);//Activating NFC transceivernfc.enable();//Configuring PUSH BUTTON to update NFC text record when pressedpinMode(17, INPUT_PULLUP);attachInterrupt(17, triggerTextUpdate, FALLING);listDir(SPIFFS, "/", 0);deleteFile(SPIFFS, "/readings.txt"); //It is important to delete any existing files by the same name before creating a new onewriteFile(SPIFFS, "/readings.txt", " Millis Readings: "); //Creating a new file readings.txt}void loop(){if ((millis() - lastUpdate) > UPDATE_DELAY){lastUpdate = millis();String data = String(millis());data += '\n';char buff[100];data.toCharArray(buff, 100);Serial.println(buff);appendFile(SPIFFS, "/readings.txt", buff);}if (update_trigger){//char *res = {};String res = readFile(SPIFFS, "/readings.txt");txtbuf[0] = '\0';txt.print(res);nfc.disable();nfc.setDataPointer(0);size_t ndef_size = txt.sendTo(nfc);Serial.println(ndef_size);nfc.setDataLength(ndef_size);nfc.enable();Serial.println("Tag updated.");update_trigger = false; // Detrigger}if (nfc.loop()){if (nfc.wasRead()){Serial.println("NDEF tag was read!");ESP.restart(); //restart the ESP so that existing file is removed and new data is logged fresh in a new file}if (nfc.available()){Serial.print("NFC master has written a new tag! ");uint16_t len = nfc.getDataLength();Serial.print(len);Serial.println(" bytes");nfc.flush(); // prevent nfc.available() from returning true again}nfc.enable();}} |
Once the code is uploaded, open the serial monitor at 115200 baud rate. Reset the ESP once to see if SPIFFS initialization takes place successfully. You can see that at the defined interval, you get a confirmation from the append file function saying Message appended.
On your Smartphone which supports NFC, install TagWriter Application made by NXP - Available on Android and iOS.
Once the app is open, go to the “Read tags” option, press the push button connected to ESP32’s P17 pin, you should be able to see the message it has prepared and is ready to transfer via NFC to your phone (as shown in the above image), take your phone close to the RF430 board and you would be able to see that the data has been transferred to your phone. This is also reflected on the serial monitor with a Tag updated message followed by the ESP resetting.
To view the received message, go to the “Edit Datasets” tab at the bottom.
If you have any queries or comments, please leave them below.