arduino-c++platformiopn532

PN532 NFC module works on Arduino, but doesn't on VSCode with PlatformIO


I have a strange problem working with VSCode and PlatformIO. I'm using NFC module PN532 with Atmega328P. I program the Atmega by the USB-UART converter. I'm using this library with software serial high speed UART.

#include <PN532.h>
#include <PN532_SWHSU.h>
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(11, 10);
PN532_SWHSU pn532swhsu(SwSerial);
PN532 nfc(pn532swhsu);

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

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

  // Got ok data, print it out!
  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);
}

void loop() {
}

Using ArduinoIDE as a compiler everything works as intended - versiondata returns a non 0 number (in the not-shorted program I can read nfc cards).

But when I'm using VSCode with PlatformIO, program compiles and upload, but versiondata returns 0 - "Didn't find PN53x board".

Here is a configuration of my PlatformIO:

[env:uno]
platform = atmelavr
board = atmega328p
build_flags = -D 
SERIAL_PORT_HARDWARE=Serial
framework = arduino
upload_flags = -F
monitor_port = COM14
upload_port = COM14
targets = upload, monitor
monitor_speed = 115200

lib_deps = 
    Wire
    arduino-libraries/ArduinoRS485@^1.0.0
    fastled/FastLED@^3.4.0
    https://github.com/yoshitake-hamano/PN532
    featherfly/SoftwareSerial@^1.0
    SPI

I'm using the same library on both Arduino and PlatformIO (I've checked files both ways).


Solution

  • Try removing the Software Serial dependency, Minicore used by Platformio contains it already. The featherfly one seems to be an older implementation of software serial.