Main Site Documentation

TinyCLR RC522

Hello,
has anyone experience in using the RC522-module for reading MyFaire-Cards?
We use this module with the Netduino and it works fine. Now we wanted to transform into TinyCLR with a FEZ.
It has a SPI-interface and we have adapted the software to TinyCLR. We sent the same bytes but get totally other bytes in reading.
We’ve testet all 4 SPI-modes without success.

Chip select is not set properly perhaps?

can you share rc522 code if possible :smile:

It seem to work. If I set it to an other Pin I get other values.
I also deactivated it and activate the pin per programm and get the same result as with CS per SPI-module.

I use this code: https://github.com/mlowijs/mfrc522-netmf/tree/master/Mfrc522.
With NETDUINO it works perfect. For TinyCLR I’ve made some adaptions, f.e. in TransferSpi and init:

var settings = new SpiConnectionSettings()
        {
            ChipSelectType = SpiChipSelectType.Gpio,
            ChipSelectLine = FEZ.GpioPin.D9,
            Mode = SpiMode.Mode1,
            ClockFrequency =  1000 * 1000,       //1Mhz
            DataBitLength = 8,
        };

        var controller = SpiController.FromName(FEZ.SpiBus.Spi1);
        _spi = controller.GetDevice(settings);

can you add

var _chipSelectLine = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D9);
_chipSelectLine.SetDriveMode(GpioPinDriveMode.Output);
_chipSelectLine.Write(GpioPinValue.Low);

var spiSettings = new SpiConnectionSettings(_chipSelectLine.PinNumber);
spiSettings.ClockFrequency = 1000*1000;
spiSettings.DataBitLength = 8;
spiSettings.Mode = SpiMode.Mode1;

_spi = SpiDevice.FromId(FEZ.SpiBus.Spi1, spiSettings);

Thank you, but it dosn’t work fpr me.
My compiler didn_t accept a parameter in “SpiConnectionSettings” and “FromId” is unknown.

try this (since i am not before my pc and have no device)

GpioPin _chipSelect = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D9);
_chipSelect.SetDriveMode(GpioPinDriveMode.Output);
_chipSelect.Write(GpioPinValue.Low);

        var settings = new SpiConnectionSettings()
        {
            ChipSelectType = SpiChipSelectType.Gpio,
            ChipSelectLine = _chipSelect.PinNumber,
            Mode = SpiMode.Mode1,
            ClockFrequency = 1000 * 1000,       //1Mhz
            DataBitLength = 8,
        };

 
        var controller = SpiController.FromName(FEZ.SpiBus.Spi1);
        _spi = controller.GetDevice(settings);

it dosn’t work because you can’t define the same pin extern and in SPI. I get an exception.

you should enable chip select with write(low) today i’ve got an spi mfrc522 from an friend and buyed online an uart mfrc522 so i will try to make it working driver from link you sent

Did you find anything?
It is possible that the SPI in tinyCLR has a problem? Because as user we have only the init with a few parameter and this I have tested. The chip select should also not be the problem because in the mfrc522 class I can handle CS externally.
I have no idea what I should do to make it run.

@User_8034

I converted sample from your link but device i have do not work even with arduino

please find sample
https://drive.google.com/drive/folders/184LjWKSj9SesGOav9Db30xtfDYeQfDmE?usp=sharing

i tried to convert

such is

GetDevice(…) initialize chipselect so you dan’t have to initialize before GetDevice.
From datasheet (fig. 25) I think this sould be Mode0 and not Mode1 for spi mode.

I have an mfrc522 module, so I would check code and try to communicate with module.

Conversion is nice, but (there is Always a but ! :wink:), in TransferSpi, change TransferSequential to TransferFullDuplex.
In constructor, ssPin initialization is not needed because you can put it in spi settings which is better for time execution.
In mode, my module is working wth mode0 not mode1.
Now I can detect when tag is present or not, and read uid.

WriteBlock doesn’t seem to work but I’m not an expert with RC522. I’ll give others tries tomorrow.

i have no working mfrc522 rfid for now until i get new ones ,so i have no ability to test :frowning:

and tried to convert as is with adapted changes but as you see it (still have something that missing)