[solved] MFRC522 library and STM32

anistor
Thu Jun 11, 2015 5:10 pm
Hi,

I’m trying to use the MFRC522 library to read RFID Mifare cards. This library (https://github.com/miguelbalboa/rfid) was written for Arduino and although it was not specifically written for STM32 it seems to compile without errors for my STM32F103C8T6 ARM STM32 Minimum System Dev Board. Unfortunately I did not managed to make it work. There seems to be some SPI communication failure.

I was able to use this rfid reader (http://www.electrodragon.com/product/mifare-rc522-rfid-card-readerdetector-ic-card/) previously with a Pro Mini, so I’m confident it is not broken and I do understand how to make the wiring for both Pro Mini and STM32F103C8T6 boards, so the problem is definitely on the software side.

Does anyone have any positive experience making this particular RFID reader work with the MFRC522 lib on the STM32?

Thanks!
Adrian


victor_pv
Thu Jun 11, 2015 5:40 pm
Not sure if you have seen the other thread about the SPI SS pin, but if you are trying to use the hardware SPI NSS pin to manage CS, that may not work.
If that is the case, try to use some other GPIO pin for CS.

anistor
Thu Jun 11, 2015 6:37 pm
Hi Victor!

Excellent advice. It works after changing the SS pin. The lib also seems to need some tweaking to move some pinMode calls out of the MFRC522 constructor into an init function that is called in setup().
I still have some minor issues but it generally works and I think I’ll start to port this one.

Thanks!


victor_pv
Thu Jun 11, 2015 6:57 pm
anistor wrote:Hi Victor!

Excellent advice. It works after changing the SS pin. The lib also seems to need some tweaking to move some pinMode calls out of the MFRC522 constructor into an init function that is called in setup().
I still have some minor issues but it generally works and I think I’ll start to port this one.

Thanks!


anistor
Tue Jun 16, 2015 2:10 pm
Glad to let you know the mfrc522 library (https://github.com/miguelbalboa/rfid) was patched and the patch was integrated in master so now it works on stm32f103 boards out of the box.

Adrian


RogerClark
Tue Jul 07, 2015 1:23 am
Excellent

Thanks for letting us know


petronel
Thu Nov 10, 2016 9:49 am
trying to use MFRC522 with my STM32F103 (blue pill).
It compiles fine but the code seems to crash at SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus

RogerClark
Thu Nov 10, 2016 9:52 am
Must be crashing somewhere else

I just added that line to my blink code and it still runs OK

#include "SPI.h"
int counter=0;
void setup() {
// put your setup code here, to run once:
pinMode(PB12,OUTPUT);
Serial.begin(250000);
SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));

}

bool v=false;
void loop() {

Serial.println(counter++);
// put your main code here, to run repeatedly:
digitalWrite(PB12,v);
delay(50);
v=!v;
}


petronel
Thu Nov 10, 2016 10:27 am
Strange . Removed all my connections and it doesn’t crash. Will double check again all my RC522 connections

LE: my mistake, I had the “mfrc522.PCD_DumpVersionToSerial(); ” commented out…


RogerClark
Thu Nov 10, 2016 10:40 am
Sounds like the code is miss intrepreting the data and perhaps having a buffer overflow

remember the data types are different in ARM than AVR e.g. int is 32 bit, double really is double, “word” may be a different size to what the AVR code thinks it is.

Look carefully at the data types you are reading from the peripheral, you may need to change the variable declarations to explicitly set the size e.g. uint16_t etc


petronel
Thu Nov 10, 2016 11:06 am
No, It was crashing at that F() macro inside the void MFRC522::PCD_DumpVersionToSerial() {
Moved the #define F(x) x

petronel
Thu Nov 10, 2016 11:24 am
If i move the F() macro at th begining of my sketch i get compilation errors.

Can we find an workaround, other than replacing all th F() in that library ?


RogerClark
Thu Nov 10, 2016 8:39 pm
I’d just remove all the F() macros.

Or I guess you could modify WString where the existing F macro is defined


Leave a Reply

Your email address will not be published. Required fields are marked *