Use RC522 with Lazarus and RPI lazarus / 32-Linux ---------------------------------------------------------------------- h0mra · 2022-01-06 11:48 Greetings! For some time now I was tinkering with the Raspberry Pi und now started a project with the RFID-Reader "RC522" but I can't wrap my mind about how to use it with Lazarus. The Python sample code works as intended but I don't understand how to read out the Reader with Pascal. I tried working with the pascalio library that was linked on the wiki. As I understand it so far I need to write a command to the device and in the data-sheet the command for 'Receive' is "1000" so i tried to write that to the device but I get no output. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ... var  spi: TSPILinuxDevice; rbuf, wbuf: word; begin spi:= TSPILinuxDevice.C reate(0,0); spi.Mode:=SPI_MODE_0; wbuf:=$1000; spi.ReadAndWrite(wbuf, sizeof(wbuf), rbuf, sizeof(rbuf)); writeln(inttostr(rbuf)); ...  Does somebody have experience with this and can guide me in the right direction? Thanks in advance! ---------------------------------------------------------------------- MarkMLl · 2022-01-24 11:08 A very belated response, so that you don't think that everybody's ignoring you. I don't have one of those but have looked at various other RFID stuff on various platforms. I've got a vague recollection of looking at SPI minimally, but that would have been a few years ago and I went directly to the kernel API. When you say "don't understand": what's actually happening? Is the problem that you don't know how to use the SPI API, that your attempt at coding won't compile, or that the device is not responding and in that case what hardware faultfinding have you attempted? I'm not even sure what SPI devices I've got to hand to play with at the moment... MarkMLl ---------------------------------------------------------------------- MarkMLl · 2022-01-29 18:59 I've been looking at this, and the Python library hides a great deal of low-level chip access via SPI, plus a bit of GPIO stuff for the reset line. I'll do a bit more work on it in a few days time as a way of checking out low-level bus drivers (SPI and I2C) on a PC, but to be honest I think that selecting a reader with USB or serial access would be a much better idea. [A week later] I've been looking at this in depth as a way of familiarising myself with SPI and I2C as provided on e.g. a Raspberry Pi or using a USB-connected CH341A on a PC. The Pascal components to support SPI or I2C on Linux are basically thin wrappers around the kernel facilities with very little added value. However the support libraries for the MFRC522 chip amount to around 10k lines of source on top of this. That's based mainly on the ones tailored for the Arduino, but I anticipate that the Python interface is of a similar size. This is emphatically not a trivial interface. MarkMLl ---------------------------------------------------------------------- avra · 2022-02-09 11:58 Quote from: h0mra on January 06, 2022, 12:48:49 pmAs I understand it so far I need to write a command to the device and in the data-sheet the command for 'Receive' is "1000" so i tried to write that to the device but I get no output.Datasheet https://www.nxp.com/docs/en/data- sheet/MFRC522.pdf indeed says that receive command is 1000, but it looks like a binary number to me - not a hexadecimal number as you've asumed. Anyway, you should look at Arduino code for reference https:// forum.lazarus.freepascal.org/index.php/topic,43438.msg304077.html#msg3 04077 and https://microcontrollerslab.com/wp- content/uploads/2020/01/rfidmifare-commands.pdf. Reading anything beyond serial number seams partially specific to the card type you have. Without a logic analyzer you are making blind shots which I really don't recommend. ---------------------------------------------------------------------- MarkMLl · 2022-02-09 13:01 Quote from: avra on February 09, 2022, 12:58:57 pmReading anything beyond serial number seams partially specific to the card type you have. Without a logic analyzer you are making blind shots which I really don't recommend. Even getting the basic UID is hard work: as I've said, a minimal port of the public domain interface library comes to several thousand lines (OK, so that's well-formatted and properly commented but even so). The best aid for this sort of thing is having byte-level debugging traces, at least until the library port is done. Anything more sophisticated will definitely need a logic analyser with proper decoding facilities. However I think the most important thing is sufficient experience to be able to read the manufacturer's datasheet, which describes subtleties that you won't appreciate from inspecting code. ----- If all that is needed is to get the UID of an HF card or the ID of an LF card I suggest using a 7941W module. It's a bit more expensive but is simple to interface via a serial converter (FTDI clone etc.), has the advantage of supporting both frequency bands, and the sensitivity appears a bit better than that of generic RC522 modules (which in common with a lot of other really cheap stuff are notorious for slipshod manufacturing). MarkMLl