M24SR NFC Tag Driver. The main purpose of this library is to make memory reading and writing in applications agnostic to NFC and NDEF protocol headers.

Homepage

Driver class for the ST M24SR.

ST 8 KiB NFC Tag

The main purpose of this library is to make NFC Tag memory reading and writing in applications agnostic to the NFC and NDEF protocol headers.
This means that reading or writing large buffers from any starting address is easier for the program as it's not required to know the payload maximum size and NDEF header infomation.

It is possible to read and write the full size of the NFC Tag in one call as the library handles the counting internally.

// Example: write "test" to address 0 and read back
#include "M24SR.h"

M24SR _nfctag(I2C_SDA, I2C_SCL);

int main() {
	M24SR::status_t ret;
	char data[32] = {'t','e','s','t'};

	// Begin NFC session - Don't parse header
	ret = _nfctag.session_start(false);
	if ( ret != M24SR::M24SR_SUCCESS )
	{
		printf("Error write session start! %2.2X\n", ret );
	}

	// write 4 bytes to the NDEF payload
	ret = _nfctag.write(0, (char*)data, 4);
	if ( ret != M24SR::M24SR_SUCCESS )
	{
		printf("Error writing ! %2.2X\n", ret );
	}

	// Write header or Cancel and don't write header if we failed!
	ret = _nfctag.session_end( ret != M24SR::M24SR_SUCCESS );
	if ( ret != M24SR::M24SR_SUCCESS )
	{
		printf("Error write session end! %2.2X\n", ret );
	}


	// read back what we wrote

    // begin NFC session - Parsing header
	ret = _nfctag.session_start();
	if ( ret != M24SR::M24SR_SUCCESS )
	{
		printf("Error read session start! %2.2X\n", ret );
	}

	uint16_t sz = _nfctag.get_total_memory_used();
	if ( sz > sizeof(data) )
		sz = sizeof(data) ;

	memset( data, 0, sizeof(data) );
	ret = _nfctag.read(0, (uint8_t*)&data, sz);
	if ( ret !=  M24SR::M24SR_SUCCESS )
	{
		printf("Error reading %2.2X!\n", ret );
	}else{
		printf("Read: %s\n", data );
	}

	_nfctag.session_end();
	if ( ret != M24SR::M24SR_SUCCESS )
	{
		printf("Error read session end! %2.2X\n", ret );
	}
 return 0;
}

All wikipages