[Solved] PN532 library from Adafruit not working

maman
Tue May 22, 2018 5:43 am
Hello,
Previously, I use esp8266 to connect to PN532 NFC module, using this library :
https://github.com/elechouse/PN532

Now, I want to change to STM32F1 core as the processor. However, it seem that the wire.h
library of STM32arduino is not compatible with the wire.h of the ESP8266 arduino library.

Is there any alternative of wire.h STM32F1 arduino library ?

Thanks,
Regards,


RogerClark
Tue May 22, 2018 6:07 am
This section is for people to post introduce themselves

After that you can post a question into the relevant section

Please read this post about where to find information

http://stm32duino.com/viewtopic.php?f=2&t=3111


maman
Tue May 22, 2018 10:22 am
Let me introduce, I am from Indonesia, working in a university.
Previously, I have developed parking system using NFC/RFID card.
I used ESP8266 as the main processor, however, I found it is not stable in the I2C interface.
Therefore, I want to try to use STM32F1 as the main processor.

For the NFC reader, I use PN532 with the following library https://github.com/elechouse/PN532.
However, it is failed to compile. It seem that the wire.h library of STM32 arduino core is not
compatible with the wire library of ESP8266.

Is there anyone have used PN532 module ? which PN532 library did you use ?

This is the error code when I compiled one of the example program,
In file included from C:\Users\LENOVO\AppData\Local\Temp\arduino_modified_sketch_142934\iso14443a_uid.pde:19:0:

C:\Users\LENOVO\Documents\Arduino\libraries\PN532_I2C/PN532_I2C.h: In member function 'uint8_t PN532_I2C::write(uint8_t)':

C:\Users\LENOVO\Documents\Arduino\libraries\PN532_I2C/PN532_I2C.h:29:37: error: void value not ignored as it ought to be

return _wire->write(data);


stevestrong
Tue May 22, 2018 1:03 pm
As the write() function of the Wire library from libmaple core does not return any value, you should change line 29 of the header file to:
_wire->write(data);
return 1;

RogerClark
Tue May 22, 2018 9:50 pm
Steve,

I just checked Ardunos SAMD core and and it’s write() functions return size_t, so I need to change the function signatures


maman
Wed May 23, 2018 3:16 am
Thanks, Steve and Rogerclark.
I have been check the PN532 library of Adafruit, too.
https://github.com/adafruit/Adafruit-PN532.
it can be compiled, but it does’nt worked.
It runs the setup part of the program, but halt at the loop part.
I used one of the examples of the library.

Regards,
Maman


RogerClark
Wed May 23, 2018 8:08 am
I’ve updated the Wire library to be compatible with the Arduino API

However that library still won’t compile because it defaults to defining WIRE to wire1 for the STM32 because of IMHO incorrect programming

#if defined(__AVR__) || defined(__i386__) || defined(ARDUINO_ARCH_SAMD) || defined(ESP8266) || defined(ARDUINO_ARCH_STM32)
#define WIRE Wire
#else // Arduino Due
#define WIRE Wire1
#endif


fpiSTM
Wed May 23, 2018 9:23 am
[RogerClark – Wed May 23, 2018 8:08 am] –
But I find it pointless to put PR’s into Adafruit as they usually have their own agenda and these libs are primarily written to support products they sell.

I’ve already submit a PR to Adafruit and it has been merged ;)
https://github.com/adafruit/Adafruit_MQ … ry/pull/95


RogerClark
Wed May 23, 2018 9:31 am
I think it depends if the PR is to fix a bug or to support another board.

If the @op wants to send a PR to Adafruit he can do that, but there are probably loads of other Adafruit libs that also don’t work with the STM32

An alternative is to define

ARDUINO_ARCH_STM32

As I see the STM core does this

I think thats probably the best option


RogerClark
Wed May 23, 2018 9:34 am
Yep.

I’m going to define ARDUINO_ARCH_STM32 in platform.txt

Edit.

Done.


fpiSTM
Wed May 23, 2018 9:57 am
All cores provide the -DARDUINO_ARCH_{build.arch}

RogerClark
Wed May 23, 2018 9:58 am
I agree it won’t make it compatible with everything

But just a bit more compatible with some libs


maman
Thu May 24, 2018 2:06 am
Today, I test the new STM32 arduino package.
It can be compiled and can read the MIFARE card.
But only at the beginning, after one or two time reading of the card,
the board will be hanged, need to reset.

Regards,


RogerClark
Thu May 24, 2018 4:25 am
[maman – Thu May 24, 2018 2:06 am] –
Today, I test the new STM32 arduino package.
It can be compiled and can read the MIFARE card.
But only at the beginning, after one or two time reading of the card,
the board will be hanged, need to reset.

Regards,

Unfortunately, some libraries only work when they are run on the hardware they were designed to run on.

A large percentage of libraries have to be “ported” to run on the STM32 as they are at least 5 times faster than the Arduino Uno and have a completely different architecture, this involves debugging both the software and possible using a logic analyser to understand why the software is not working

You also need to confirm that you application code would work even when running on an AVR (e.g Uno), as its not necessarily a fault in the library which is causing your problem


maman
Sat May 26, 2018 7:20 am
Thanks Roger, for your help.

I confirmed that the PN532 library is working for UNO and ESP8266.
https://github.com/elechouse/PN532
In the previous worked, I have been used this library many times.
It is no problem at all if we are using UNO, while on ESP8266, it is not stable,
because actually in ESP8266, I2C is not a hardware solution.

Probably, I have to try other PN532 board.

best regards,


Leave a Reply

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