"expected primary-expression before '{' token" MiFare NFC Card Writer


I’ve been using the adafruit NFC/RFID shield for a small project. I have successfully read the passive card data (0’s) multiple times, but when I try to use the WriteDataBlock command, I get this error:

expected primary-expression before ‘{’ token

The error highlights the line where I am choosing what “data” actually is (16 bits).
I used/slightly modified the simple example supplied with the NFC library. All I did to use the write command was uncomment the line of code that said something to the effect of “//uncomment the following line to write to the card”.

I’m definitely no expert, but I don’t know where this error is coming from. Anyone have any ideas?

#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {


  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
  Serial.println("Waiting for an ISO14443A Card ...");

void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);
    if (uidLength == 4)
      // We probably have a Mifare Classic card ... 
      Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
      // Now we need to try to authenticate it for read/write access
      // Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
      Serial.println("Trying to authenticate block 4 with default KEYA value");
      uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
	  // Start with block 4 (the first block of sector 1) since sector 0
	  // contains the manufacturer data and it's probably better just
	  // to leave it alone unless you know what you're doing
      success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
      if (success)
        Serial.println("Sector 1 (Blocks 4..7) has been authenticated");
        uint8_t data[16];
        data = {'H', 'i', 'M', 'y', 'N', 'a', 'm', 'e', 'I', 's', 0, 0, 0, 0, 0, 0};
        success = nfc.mifareclassic_WriteDataBlock (4, data);

        // Try to read the contents of block 4
        success = nfc.mifareclassic_ReadDataBlock(4, data);
        if (success)

          // Data seems to have been read ... spit it out
          Serial.println("Reading Block 4:");
          nfc.PrintHexChar(data, 16);
          // Wait a bit before reading the card again
          Serial.println("Ooops ... unable to read the requested block.  Try another key?");
        Serial.println("Ooops ... authentication failed: Try another key?");
        uint8_t data[16];
        data = {'H', 'i', 'M', 'y', 'N', 'a', 'm', 'e', 'I', 's', 0, 0, 0, 0, 0, 0};

You can't do that. The ONLY time when you can value an entire array at once is then the declaration and initialization happens in ONE statement:

        uint8_t data[16] = {'H', 'i', 'M', 'y', 'N', 'a', 'm', 'e', 'I', 's', 0, 0, 0, 0, 0, 0};

Beautiful! That fixed the error compiling. Could you provide a small explanation for why it works that way? Just curious. I knew it had to be something simple, thank you.

Could you provide a small explanation for why it works that way?

I did. Declaring a variable and initializing it can be done in one step, and the compiler understands the shortcut notation used.

When the declaration and initialization are performed separately, the shorthand notation is not supported.