RFID MfRc522 - method ListenToCardIso14443TypeA always returns false in .NET 5 project

160 Views Asked by At

Hi I have problem on my RaspberryPI with MfRC522 in Iot.Device.Bindings library. The method ListenToCardIso14443TypeA always returns false. I have a similar application in Node.js and it works perfectly fine.

    GpioController gpioController = new GpioController();
    int pinReset = 21;

    SpiConnectionSettings connection = new(0, 1);
    connection.ClockFrequency = 10_000_000;
    SpiDevice spi = SpiDevice.Create(connection);
    MfRc522 mfrc522 = new(spi, pinReset, gpioController, false);

    bool res;
    Data106kbpsTypeA card;
    do
    {
        res = mfrc522.ListenToCardIso14443TypeA(out card, TimeSpan.FromSeconds(2));

        if (res)
        {
            Console.WriteLine("card");
        }
        else
        {
            Console.WriteLine("No card.");
        }
        Thread.Sleep(res ? 0 : 1000);
    }
    while (!res);

Have anyone similar issue and were able to fix that?

1

There are 1 best solutions below

0
On

Resolved I changed:

SpiConnectionSettings connection = new(0, 1);

To the:

SpiConnectionSettings connection = new(0, 0);

And it has started working.