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...");
}
}
Thanks in advance