NTAG5 and Arduino UNO I2C writing not possible

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NTAG5 and Arduino UNO I2C writing not possible

135 Views
shubhamdasalmascience
Contributor I

Hi,

I am Shubham Das. I am new to the NTAG5 family. I have an NTAG5 link (OM2NTP5332) connected to the Arduino UNO. I have powered the UNO and connected it to the Arduino IDE. 

I am using this code: 

#include <Wire.h>

// NTAG5 I2C address
#define NTAG5_I2C_ADDRESS 0x54

void setup() {
  Serial.begin(9600); // Initialize serial communication for debugging
  Wire.begin(); // Initialize the I2C communication  
  Wire.beginTransmission(NTAG5_I2C_ADDRESS);
 
  int error = Wire.endTransmission();
  Serial.println(error);
  if(error == 0)
  {
    Serial.println( "The sensor is detected.");
  }
  else
  {
    Serial.println( "Error, no sensor found.");
  }
}

void loop() {
  // Reading from register 0x103D
  readRegister(0x103D);

  // Example of writing to register 0x103D
  writeRegister(0x103D, 0x7D); // 

  delay(5000); // Delay for 5 seconds before repeating the process
}

void readRegister(uint16_t registerAddress) {
  uint8_t regAddrHigh = (uint8_t)((registerAddress >> 8)& 0xFF);
  uint8_t regAddrLow = (uint8_t)(registerAddress & 0xFF);

  Wire.beginTransmission(NTAG5_I2C_ADDRESS);
  Wire.write(regAddrHigh); // MSB of the register address
  Wire.write(regAddrLow);  // LSB of the register address
  Wire.endTransmission(false); // End transmission but don't release the I2C bus

  Wire.requestFrom(NTAG5_I2C_ADDRESS, 1);
  while (Wire.available()) {
    int readValue = Wire.read(); // Read the register data
    uint8_t data = (uint8_t)readValue; // Cast to uint8_t to avoid sign extension issues
    Serial.print("Read data: 0x");
    Serial.println(data, HEX); // Print the read data in HEX format
  }
}

void writeRegister(uint16_t registerAddress, uint8_t data) {
  uint8_t regAddrHigh = (uint8_t)((registerAddress >> 8) & 0xFF);
  uint8_t regAddrLow = (uint8_t)(registerAddress & 0xFF);
  Wire.beginTransmission(NTAG5_I2C_ADDRESS);
  Wire.write(regAddrHigh); // MSB of the register address
  Wire.write(regAddrLow);  // LSB of the register address
  Wire.write(data);  // Data to write  
  int error = Wire.endTransmission();
  Serial.println(error);
 
  Serial.println("Write operation completed.");
}

So on running this code, I can read the register value as 4D which I had set using the NFC tools command. But when I am trying to Write on that register and change the value from 4D to 7D, I can do it using NFC tools but cannot do it using the Arduino UNO using I2C communication. I can only read using the UNO but not write. Can someone please help me out? It is urgent and important for me. 

Thanks 
0 Kudos
1 Reply

108 Views
KellyLi
NXP TechSupport
NXP TechSupport

Hello @shubhamdasalmascience 

There is an example C source code based on LPC MCU (SW6090), it's recommended that you make a reference.

BR

kelly

0 Kudos