nanoFramework.Iot.Device.Mfrc522 1.2.883

Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Mfrc522 --version 1.2.883
                    
NuGet\Install-Package nanoFramework.Iot.Device.Mfrc522 -Version 1.2.883
                    
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.Mfrc522" Version="1.2.883" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nanoFramework.Iot.Device.Mfrc522" Version="1.2.883" />
                    
Directory.Packages.props
<PackageReference Include="nanoFramework.Iot.Device.Mfrc522" />
                    
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.Mfrc522 --version 1.2.883
                    
#r "nuget: nanoFramework.Iot.Device.Mfrc522, 1.2.883"
                    
#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.
#addin nuget:?package=nanoFramework.Iot.Device.Mfrc522&version=1.2.883
                    
Install as a Cake Addin
#tool nuget:?package=nanoFramework.Iot.Device.Mfrc522&version=1.2.883
                    
Install as a Cake Tool

MFRC522 - RFID reader

MFRC522 is a very cheap RFID/NFC reader for Iso 14443 Type A cards. Part of those cars are the Mifare and Ultralight family. This reader implement the proprietary Mifare cryptography protocol and can be used transparently.

Documentation

Usage

MFRC522 supports SPI, I2C and UART (Serial Port). You can create the reader with any of those protocols.

Note: most of the popular boards you'll buy are SPI only. This documentation will focus on SPI. You have in the samples more information on how to setup I2C and UART.

GpioController gpioController = new GpioController();
// adjust the GPIO used for the hard reset
int pinReset = 21;

// Default on ESP32:
// GPIO23 = MOSI; GPIO25 = MISO; GPIO19 = Clock

// Uncomment for SPI
SpiConnectionSettings connection = new(1, 22);
// Here you can use as well MfRc522.MaximumSpiClockFrequency which is 10_000_000
// Anything lower will work as well
connection.ClockFrequency = 5_000_000;
SpiDevice spi = SpiDevice.Create(connection);
MfRc522 mfrc522 = new(spi, pinReset, gpioController, false);

The code will create an instance of MFRC522 and will use the pin GPIO21 as the hardware rest pin and will create an GpioController automatically from the default driver. Check the detailed [samples] for more elements. More detailed examples shows how to use other type or cards.

You can get the version using the Version property.

Debug.WriteLine($"Version: {mfrc522.Version}, version should be 1 or 2. Some clones may appear with version 0");

Keep in mind that having a version which is 0.0 doesn't necessary means that your reader is not working properly, if you bought a cheap copy of an original MFRC522, the internal version may not be recognized.

MFRC522 only supports ISO 14443 Type A. You can pull a card like this:

bool res;
Data106kbpsTypeA card;
do
{
    res = mfrc522.ListenToCardIso14443TypeA(out card, TimeSpan.FromSeconds(2));
    Thread.Sleep(res ? 0 : 200);
}
while (!res);

As soon as a card will be detected, it will get out a Data106kbpsTypeA class which is a card. You will have the Unique Identifier from the card as well as the rest of the elements to help identifying it.

You can then create a Mifare card and fo operation on it:

var mifare = new MifareCard(mfrc522, 0);
mifare.SerialNumber = card.NfcId;
mifare.Capacity = MifareCardCapacity.Mifare1K;
mifare.KeyA = MifareCard.DefaultKeyA;
mifare.KeyB = MifareCard.DefaultKeyB;

mifare.BlockNumber = 0;
mifare.Command = MifareCardCommand.AuthenticationB;
ret = mifare.RunMifareCardCommand();
if (ret < 0)
{
    mifare.ReselectCard();
    Debug.WriteLine($"Error reading bloc: {mifare.BlockNumber}");
}
else
{
    mifare.Command = MifareCardCommand.Read16Bytes;
    ret = mifare.RunMifareCardCommand();
    if (ret >= 0)
    {
        if (mifare.Data is object)
        {
            Debug.WriteLine($"Bloc: {mifare.BlockNumber}, Data: {BitConverter.ToString(mifare.Data)}");
        }
    }
    else
    {
        mifare.ReselectCard();
        Debug.WriteLine($"Error reading bloc: {mifare.BlockNumber}");
    }
}

Important: you have to do the ReselectCard() operation every time you have a failure in reading or authentication. By default the card will stop responding. This behavior is wanted by design to make is longer to brute force the authentication mechanism. The samples shows a way how to find a key from known keys for NDEF scenarios for example. Note that the sample is not fully optimize, it is to help understanding what as the mechanism behind.

Other notes

  • The SPI implementation has been deeply tested.
  • The I2C and UART has been barely tested due to lack of hardware support. So please open issues if you have any issue.
  • When using I2C, the address can be setup using the hardware pin, it's the reason why there is no default address.
  • If you are using UART, it is more than strongly recommended to use as high as possible serial baud transfer.
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.2.883 187 4/28/2025
1.2.880 174 4/24/2025
1.2.869 200 4/2/2025
1.2.864 180 4/2/2025
1.2.852 191 3/11/2025
1.2.842 238 3/5/2025
1.2.838 122 3/3/2025
1.2.835 127 2/27/2025
1.2.822 140 2/26/2025
1.2.790 134 2/5/2025
1.2.787 137 2/4/2025
1.2.785 136 2/4/2025
1.2.775 128 2/4/2025
1.2.772 134 2/4/2025
1.2.759 130 1/31/2025
1.2.755 123 1/31/2025
1.2.737 122 1/13/2025
1.2.729 119 1/8/2025
1.2.704 141 12/18/2024
1.2.696 120 12/16/2024
1.2.691 140 12/11/2024
1.2.673 142 10/23/2024
1.2.662 126 10/11/2024
1.2.656 163 10/3/2024
1.2.635 140 8/30/2024
1.2.631 133 8/28/2024
1.2.606 110 8/2/2024
1.2.595 115 7/24/2024
1.2.590 139 7/17/2024
1.2.570 145 6/14/2024
1.2.560 155 5/29/2024
1.2.552 154 5/17/2024
1.2.548 150 5/15/2024
1.2.536 173 4/15/2024
1.2.486 186 2/2/2024
1.2.483 144 1/31/2024
1.2.479 143 1/27/2024
1.2.446 289 11/17/2023
1.2.436 161 11/10/2023
1.2.416 161 11/8/2023
1.2.329 269 5/26/2023
1.2.313 217 5/12/2023
1.2.298 212 5/5/2023
1.2.297 218 5/3/2023
1.2.253 348 2/22/2023
1.2.243 311 2/20/2023
1.2.215 389 1/6/2023
1.2.212 367 1/5/2023
1.2.205 348 12/30/2022
1.2.203 362 12/28/2022
1.2.161 417 11/15/2022
1.2.159 409 11/14/2022
1.2.155 410 11/6/2022
1.2.153 443 11/5/2022
1.2.141 476 10/25/2022
1.2.128 463 10/22/2022
1.2.122 516 10/12/2022
1.2.118 484 10/11/2022
1.2.117 468 10/10/2022
1.2.114 454 10/8/2022
1.2.95 498 9/22/2022
1.2.89 482 9/16/2022
1.2.87 548 9/15/2022
1.2.73 480 9/8/2022
1.2.40 496 8/6/2022
1.2.35 474 8/4/2022
1.2.5 526 7/13/2022
1.2.0 413 11/2/2022
1.1.141.41205 508 7/6/2022
1.1.116.8772 529 6/24/2022
1.1.113.2032 520 6/23/2022
1.1.111.5739 516 6/17/2022
1.1.109.32999 509 6/16/2022
1.1.99.36719 519 6/14/2022
1.1.97.17326 522 6/13/2022
1.1.92.53000 518 6/8/2022
1.1.67.25390 526 5/27/2022
1.1.48.19401 514 5/19/2022
1.1.38 544 5/4/2022
1.1.27 532 4/26/2022
1.1.20 523 4/21/2022
1.1.3 534 4/15/2022
1.1.1 535 4/14/2022
1.0.300 534 3/31/2022
1.0.278-preview.125 197 3/25/2022
1.0.278-preview.124 184 3/25/2022
1.0.278-preview.115 172 3/22/2022
1.0.278-preview.111 180 3/19/2022
1.0.278-preview.109 179 3/18/2022
1.0.278-preview.105 191 3/15/2022
1.0.278-preview.104 182 3/15/2022
1.0.278-preview.101 176 3/11/2022
1.0.278-preview.98 178 3/10/2022
1.0.278-preview.97 183 3/8/2022
1.0.278-preview.84 195 2/25/2022
1.0.278-preview.76 192 2/18/2022
1.0.278-preview.70 184 2/11/2022
1.0.278-preview.64 182 2/9/2022
1.0.278-preview.62 185 2/8/2022
1.0.278-preview.61 192 2/5/2022
1.0.278-preview.59 197 2/4/2022
1.0.278-preview.52 204 1/31/2022
1.0.278-preview.40 198 1/28/2022
1.0.278-preview.31 196 1/27/2022
1.0.278-preview.29 196 1/27/2022
1.0.278-preview.16 203 1/24/2022
1.0.278-preview.14 197 1/21/2022
1.0.278-preview.12 197 1/21/2022
1.0.278-preview.1 197 1/14/2022
1.0.272 232 1/10/2022
1.0.259 402 12/9/2021
1.0.221 232 10/19/2021
1.0.219 235 10/19/2021
1.0.218 269 10/18/2021
1.0.217 268 10/16/2021
1.0.209 257 10/12/2021
1.0.194 273 10/1/2021
1.0.193 237 9/30/2021
1.0.191 241 9/29/2021
1.0.146 242 7/22/2021
1.0.140 246 7/20/2021
1.0.138 264 7/18/2021