Arduino Mega+ PN532 0xFF Replacing parts of message?

Hi,
Im using an arduino mega with the adafruit PN532 NFC shield to send messages from my android phone to the arduino. Im using the pn532 in I2C mode.
However parts of the message are being replaced with 0xFF, for example the message sent by my android phone is : 0023D9011C0254E10473556549456F385762495652417053636D7533673173626838347A329000
However the arduino prints:
0023D9011C0254E10473556549456F3857624956524170FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
The messages are still the correct lenght, simply the ending is being replaced with 0xFF.
Arduino code

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532Interface.h>
#include <PN532.h>
#include <Adafruit_PN532.h>
#include <NfcAdapter.h>
#include <NdefMessage.h>
#include <NdefRecord.h>
#define PN532_IRQ   (2)
#define PN532_RESET (3)
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);



void setup();
void loop();
String printResponse(uint8_t *response, uint8_t responseLength);
void setupNFC();
void setup()
{
  Serial.begin(115200);
  Serial.println("-------Peer to Peer HCE--------");

  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);

  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  //nfc.setPassiveActivationRetries(0xFF);

  // configure board to read RFID tags
  nfc.SAMConfig();
}

void loop()
{
  bool success;

  uint8_t responseLength = 32;

  Serial.println("Waiting for an ISO14443A card");

  // set shield to inListPassiveTarget
  success = nfc.inListPassiveTarget();

  if (success) {

    Serial.println("Found something!");

    uint8_t selectApdu[] = { 0x00, /* CLA */
                             0xA4, /* INS */
                             0x04, /* P1  */
                             0x00, /* P2  */
                             0x07, /* Length of AID  */
                             0xA0, 0x00, 0x00, 0x02, 0x47, 0x10, 0x01, /* AID defined on Android App */
                             0x00  /* Le  */
                           };

    uint8_t response[32];
    bool recieved = true;
    success = nfc.inDataExchange(selectApdu, sizeof(selectApdu), response, &responseLength);

    if (success) {

      Serial.print("responseLength: ");
      Serial.println(responseLength);
     
      //nfc.PrintHexChar(response, responseLength);

      do {
        uint8_t apdu[] = {0x00, 0xB0, 0x00, 0x00, 0x0F};
        uint8_t back[64];
        uint8_t length = 64;
        
        success = nfc.inDataExchange(apdu, sizeof(apdu), back, &length);
        
        if (success) {
          nfc.PrintHexChar(back,length);
          Serial.print("responseLength: "); Serial.println(length);
          Serial.print("String: ");
         String accessCode = printResponse(back, &length);
          recieved = false;
          Serial.println(accessCode);
          Serial.println(accessCode.substring(14,accessCode.length()-2));
        }
        else {

          Serial.println("Broken connection?");
        }
      }
      while (success & recieved);
    }
    else {

      Serial.println("Failed sending SELECT AID");
    }
  }
  else {

    Serial.println("Didn't find anything!");
  }

  delay(1000);
}

String printResponse(uint8_t *response, uint8_t responseLength) {

  String respBuffer;

  for (int i = 0; i < responseLength; i++) {

    if (response[i] < 0x10)
      respBuffer = respBuffer + "0"; //Adds leading zeros if hex value is smaller than 0x10

    respBuffer = respBuffer + String((char)response[i]);
  }

 return respBuffer;
}

void setupNFC() {

  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);

  // configure board to read RFID tags
  nfc.SAMConfig();
}

Im struggling to figure out why the arduino is printing a different message.
I have tested the same communication between 2 android phones and had no issues recieving the correct message, which is why I'm thinking its something to do with the arduino.
Iv spent hours trying to figure this out so at this point any help will be greatly appreciated.

String accessCode = printResponse(back, &length);

&length ??

WattsThat:
String accessCode = printResponse(back, &length);

&length ??

I have tried without the & operator, actually i have tried even just deleting that line of code and still no difference.
Its only there as I was getting desperate for a solution and just trying anything.
uint8_t length = 64;
Its referring to this variable.

Well, you certainly don’t want the address of the variable, you want the contents of variable.

Jeez, talk about wasting peoples time.

I attempt using both the contents and the location in the code. They both return the same result. nfc.PrintHexChar(back,length);
Uses content first.
String accessCode = printResponse(back, &length);
Uses location.
It doesn't solve the problem what so ever.

Of course it doesnt doesn’t work! You’re looking in the forrest and not seeing a tree...

You call

String printResponse(uint8_t *response, uint8_t Length) {

with

String accessCode = printResponse(&back, length);

Seems to be an issue caused by I2C having a limit of 32 bytes, Im going to switch to using SPI instead as that should solve the problem.
I also wanted to stack a sparkfun ESP8266 wifi shield on top, does anyone know if that will work using SPI?

@WattsThat Its works just fine as long as the whole APDU response is 32 bytes or smaller. If it was an issue with how I pass variables would I not also run in to problems with smaller APDU's?
I have tried
String accessCode = printResponse(back, length);
and there is no difference. Still not getting the entire message.

You can always increase BUFFER_LENGTH in the wire library if you don’t want to bother with SPI.

Ill give that a go now, thanks for the help.

You really need to understand the difference between

&variable

and

variable

Only one will work when your subroutine variable is expecting a pointer.

From my understanding one passes the location in memory assigned to the variable, and the other passes a copy of all the data stored in that variable.
So I have changed the buffer size to 64, but nothing works now keep getting Preamble missing error.

From reading other forums it seems like its not possible to avoid using SPI. Will I be able to stack a wifi shield on top of a NFC shield using SPI? I had read somewhere that it might cause issues which is why I have avoided it.