Page 1 of 1

PN532 problem

Posted: Sun Feb 23, 2020 8:39 am
by kzrysiej
Hi,
I'm playing with pn532 board nad bluepill. For some time, I've tried to make it work, but (almost) without success.
From time to time, bluepill is not able to discover pn532, when it happens, I need to unplug 5V from pn532, and then it starts working.
But not for long. After reading card(one on more, depends on luck, not always loop fails right away) it breaks - loop stops executing, green led starts blinking.
Maybe someone had the same problem? I thought it could by caused by writing out of array boundary, but after checking library, everything looks ok.
My configuration:
Pn532 conected to i2c on bluepill(ports b6&b7), powered with 5v from serial programmer. 1k resistor between 5v and SDA and one between 5V and SCL.

My code:

Code: Select all


#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);


void setup(void)
{
  Serial.begin(115200);
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (!versiondata)
  {
    Serial.print("Didn't find PN53x board");
    while (1);
  }

  Serial.print("Found chip PN5");
  Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. ");
  Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.');
  Serial.println((versiondata >> 8) & 0xFF, DEC);
  
  nfc.setPassiveActivationRetries(0xff);
  nfc.SAMConfig();
}

void loop(void)
{
  bool success;
  uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
  uint8_t uidLength;           
   
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success)
  {
    Serial.println("Found a card!");
    Serial.print("UID Length: ");
    Serial.print(uidLength, DEC);
    Serial.println(" bytes");
    Serial.print("UID Value: ");
 
    for (uint8_t i = 0; i < uidLength; i++)
    {
      Serial.print(" 0x");
      Serial.print(uid[i], HEX);
     }

    Serial.println("");
    delay(1000);
  }
  else
  {
    Serial.println("Waiting for a card...");
  }
}
I'm using this library: https://github.com/elechouse/PN532
Thanks in advance :)

Re: PN532 problem

Posted: Mon Feb 24, 2020 8:27 am
by stevestrong
The STM32F1 series MCUs are working with 3.3V supply voltage.
So the I2C pull-ups should be connected to 3.3V instead of 5V.

Re: PN532 problem

Posted: Mon Feb 24, 2020 11:34 am
by kzrysiej
I've also tried 3v3 configuration (pn532 power supply + pullups), but with the same effect. As PB6 & 7 are 5V tolerant, i thought that i'd give it a try.

Re: PN532 problem

Posted: Mon Feb 24, 2020 12:30 pm
by stevestrong
You should figure out in which function hangs or breaks the software.
I would not exclude the library, it may eventually have a memory overflow problem.

BTW, which core do you use?

Re: PN532 problem

Posted: Mon Feb 24, 2020 1:09 pm
by kzrysiej
It happens somewhere in ReadPassiveTargetId. The strange thing is, that if I don't provide card, it can work for long time without failing, but if I do, it fails in next 1 up to 4 loop execution.
I use
https://github.com/rogerclarkmelbourne/Arduino_STM32

Looks like I'll have to get ST-link to do some debugging.
Thanks guys!

Re: PN532 problem

Posted: Mon Feb 24, 2020 1:20 pm
by stevestrong
The Wire lib has been recently reworked, so it may cause some problems.
To exclude that, you could eventually use the SoftWire lib instead of the Wire (hardware) version.

Re: PN532 problem

Posted: Mon Feb 24, 2020 2:46 pm
by ag123
one way is to try to observe the signals on the i2c bus to see what may be happening
the adc on stm32 (even on stm32f103) is fast enough for it
or another way that isn't as good as if you use an adc as an oscilloscope is to use a logic analyzer e.g.
viewtopic.php?f=10&t=116
but this one is made for stm32f401 black pill
in addition, this one can only do 1 bit triggering, i.e. it can trigger on 8 parallel bits but if you need serial triggering, u'd need to use a single bit out of that 8 bits to trigger and capture the signals

Re: PN532 problem

Posted: Tue Feb 25, 2020 9:00 am
by kzrysiej
Thanks, I've tried SoftWire, with the same result. Looks like @ag123 said, I'll have to get oscilloscope or use another stm32 to see what's going on there.

Re: PN532 problem

Posted: Tue Feb 25, 2020 10:46 am
by ag123
there is another sump based logic analyzer, this one runs on a stm32f103, it probably runs on a blue pill
https://github.com/ddrown/stm32-sump