nanoFramework.Iot.Device.M24Sr 1.0.3

Prefix Reserved
dotnet add package nanoFramework.Iot.Device.M24Sr --version 1.0.3
                    
NuGet\Install-Package nanoFramework.Iot.Device.M24Sr -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.M24Sr" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.M24Sr" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.M24Sr" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nanoFramework.Iot.Device.M24Sr --version 1.0.3
                    
#r "nuget: nanoFramework.Iot.Device.M24Sr, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nanoFramework.Iot.Device.M24Sr@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nanoFramework.Iot.Device.M24Sr&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.M24Sr&version=1.0.3
                    
Install as a Cake Tool

M24SR - dynamic NFC tag

The M24SR is an NFC Forum Type 4 dynamic tag that exposes the same NDEF storage over NFC and I2C. It is included on boards such as the ST B-L475E-IOT01A Discovery kit. Unlike a register-based EEPROM, the I2C interface uses framed ISO 14443-4 APDU commands with CRC checking and session arbitration.

Documentation

Usage

Important: make sure you properly setup the I2C pins especially for ESP32 before creating the I2cDevice, make sure you install the nanoFramework.Hardware.ESP32 nuget:

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

The on-board M24SR64-Y uses the 7-bit I2C address 0x56. The sample uses I2C bus 2; adjust the bus number if the board firmware maps that peripheral differently.

An I2C session must be opened before accessing the tag and closed afterward. OpenSession retries normal session acquisition up to the configured polling limit and does not intentionally interrupt NFC activity. It throws InvalidOperationException if the session remains unavailable. Use KillSession only when taking ownership is more important than preserving an active RF session.

using Iot.Device.M24Sr;
using Iot.Device.Ndef;
using System.Device.I2c;
using System.Diagnostics;

I2cConnectionSettings settings = new(2, M24Sr.DefaultI2cAddress);
using M24Sr tag = new(I2cDevice.Create(settings));

tag.OpenSession();
try
{
    M24SrCapabilityContainer capabilityContainer = tag.ReadCapabilityContainer();
    NdefMessage message = tag.ReadNdefMessage();

    Debug.WriteLine($"NDEF capacity: {capabilityContainer.MaximumNdefFileSize - 2} bytes");
    Debug.WriteLine($"NDEF length: {message.Length} bytes, records: {message.Records.Count}");
}
finally
{
    tag.CloseSession();
}

ReadNdefMessage and WriteNdefMessage reuse the repository's Iot.Device.Ndef message model. Writes first set the two-byte NDEF length to zero, update the payload in capability-container-sized chunks, and commit the final length last so an NFC reader does not observe a partially updated message.

The default answer polling limit is 80 attempts with a one-millisecond delay. Increase it with the constructor's answerPollingAttempts parameter if the target's I2C implementation or tag write timing requires more margin.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 95 9/26/2026
1.0.1 90 9/26/2026