As I’ve mentioned in a previous post, I’ve looked through my collection of electronics and found some RFID readers. And I’ve decided to write yet another library to read those. There are plenty of Arduino libraries out there, but I’m not an Arduino guy. Most of the libraries out there are Arduino. Some others are kinda rough. I’m intending to writ a library which allows abstraction from the reader and the microcontroller. In that respect, it’s Arduino like, but then in C in stead of C++.
To begin with, I am looking at the MFRC522, as this is one of the popular boards being sold on eBay and AliExpress, and I’ve got a couple of them laying around. So… I’ve begun with the implementation of the communication protocol. The MFRC522 supports I²C, SPI and UART communication. The most popular board being sold on eBay and AliExpress is hard wired for SPI, and most libraries out there only consider SPI. My implementation however, is supposed to support all of them. At the moment I’ve only the SPI board available, but RobotDyn has a board with configurable protocol. I’ve placed an order, and waiting for the goods. — That said, I’ve been testing with the SPI. It seems I am able to communicate with the board. I’ve still to create a neat abstraction layer, but hey, I’m still in a testing phase.
Well.. the next step would be to read a card. But there I am yet unsuccessful. I’ve been trying to mimic a known good implementation. For this I’ve used an implementation I’ve used a few years ago. It was this library I’ve made my first experiments with RFID with. It lacks proper anti collision and cascading for UIDs and such. It ain’t great, but it works. But the thing has the SPI communication coded at low level, as in, accessing registers directly. As such, it’s hard coded to use SPI1. — Oh well — Thing is, this thing can read the UID of a card. I’ve writing the same values to registers (at least, I think I am) but to my code, a card remains unseen. Have I made a bug in writing multiple values? I am trying to do such a thing in a more efficient way then most (all?) of the implementations I’ve seen yet. However, I doubt the problem sits there, as it appears my implementation results in a timeout for the REQA command. Writing longer values comes in a later phase of the communication.
I’ve triple checked the values and register values, I can’t spot the place where I am doing something different. I guess… it’s time for the logic analyser.
Edit: turned out to be two silly bugs: The first bug, I configured the pin connected to the slave select as input in stead of output, second, I was passing a pointer in the and/or register to the set register, where the set register was expecting a value.