PN532 problem

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
kzrysiej
Posts: 4
Joined: Sat Feb 22, 2020 10:25 pm

PN532 problem

Post 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 :)
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: PN532 problem

Post 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.
kzrysiej
Posts: 4
Joined: Sat Feb 22, 2020 10:25 pm

Re: PN532 problem

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: PN532 problem

Post 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?
kzrysiej
Posts: 4
Joined: Sat Feb 22, 2020 10:25 pm

Re: PN532 problem

Post 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!
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: PN532 problem

Post 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.
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: PN532 problem

Post 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
kzrysiej
Posts: 4
Joined: Sat Feb 22, 2020 10:25 pm

Re: PN532 problem

Post 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.
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: PN532 problem

Post 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
Post Reply

Return to “General discussion”