Go Down

Topic: Writing data on the EEPROM of NFC tag (MAX66242) using I2C bus (Read 196 times) previous topic - next topic

Nuramon

Hello everybody,
I'm trying to write data from Arduino to NFC tag (MAX66242) throw I2C bus. I'm receiving data from RGB sensor ISL29125 on Arduino without problem (I can see it on serial monitor). But then I want to send this data to EEPROM of NFC tag, so I can read it from it with smartphone.

Code: [Select]
#include <Wire.h>
#include "SparkFunISL29125.h"

// Declare sensor object
SFE_ISL29125 RGB_sensor;

void setup()
{
  // Initialize serial communication
  Serial.begin(9600);
  Wire.begin();

  // Initialize the ISL29125 with simple configuration so it starts sampling
  if (RGB_sensor.init())
  {
    Serial.println("Sensor Initialization Successful\n\r");
  }

}

// Read sensor values for each color and print them to serial monitor
void loop()
{
  // Read sensor values (16 bit integers)
  unsigned int red = RGB_sensor.readRed();
  unsigned int green = RGB_sensor.readGreen();
  unsigned int blue = RGB_sensor.readBlue();

  // Print out readings
  Serial.print("Red: "); Serial.println(red, HEX);
  Serial.print("Green: "); Serial.println(green, HEX);
  Serial.print("Blue: "); Serial.println(blue, HEX);
  Serial.println();
   
  Wire.beginTransmission(50); // transmit to device #50
  Wire.write(0);
  Wire.write(red);
  Wire.write(red>>8);
  Wire.endTransmission();     // stop transmitting

  uint16_t data = 0x0000;

  Wire.beginTransmission(50);         //checking if transmission was succesful
  Wire.requestFrom(50, (uint8_t)2);   
  data = Wire.read();
  data |= (Wire.read() << 8);
  Wire.endTransmission();

     
  Serial.println(data, HEX);   //number should be same as "Red"
  Serial.println();
 
  delay(5000);
}


The result is just "FFFF" on serial monitor.

In data sheet of NFC tag, they say, slave address of the tag is: 0011001R/W which should be "50" (address).

Wiring is in the picture:


Would somebody know, where did I make a mistake?

GolamMostafa

Quote
In data sheet of NFC tag, they say, slave address of the tag is: 0011001R/W which should be "50" (address).
In I2C Protocol, the device (Slave) address is usually 7-bit. The value as is seen is 8-bit (known as control byte) which includes the R/W bit. The 'slave address of the tag' is: 0011001 (0x19 = 25 decimal). So, we should be writing as --
Code: [Select]
Wire.beginTransmission(25); // transmit to device #25

Also, that --
Code: [Select]
Wire.requestFrom(25, (uint8_t)2);   
data = Wire.read();
data |= (Wire.read() << 8);


Thanks,



Nuramon

Ouu, thank you very much Golam. I haven't known that. Anyway, after correcting it, it still gives me "FFFF" respond.

GolamMostafa

Please, remove the following two instructions form the top and the end of Wire.requestFrom() command and then try. Connect 2x4.7k pull-up with the SDA and SCL lines of the I2C Bus.

Code: [Select]
Wire.beginTransmission(50);         //checking if transmission was succesful
Wire.endTransmission();     // stop transmitting

Nuramon

I removed instructions you mentoned and added pull-up resistors on the I2C bus as you can see in the picture. But problem remains.


I've also gotten idea if I don't need precise command which was set by manufacturer of the tag.


But I thought it is everything handled by Arduino. The same command for reading from it.

GolamMostafa

OK! Please execute the following program; it will indicate if your slave device is responding to I2C Bus commands or not. I assume that you have a UNO or a UNO compatible host controller. Please, tell if the Serial Monitor is reporting 0 or not; 0 means -- the sensor is responding to its address 25; non-zero/no-value means -- the sensor is not responding!

Code: [Select]
#include <Wire.h>
#include "SparkFunISL29125.h"
byte busStatus;
// Declare sensor object
SFE_ISL29125 RGB_sensor;

void setup()
{
  // Initialize serial communication
  Serial.begin(9600);
  Wire.begin();

  // Initialize the ISL29125 with simple configuration so it starts sampling
  if (RGB_sensor.init())
  {
    Serial.println("Sensor Initialization Successful\n\r");
  }

  do
  {
    Wire.beginTransmission(25); // transmit to device #25
    busStatus = Wire.endTransmission();
  }
  while (busStatus != 0x00);
  Serial.println(busStatus, HEX);
}

void loop()
{
  
}

Nuramon


GolamMostafa

This (busStatus = 0x00) indicates that the deviceAddress is correct. and the sensor is also healthy (at least the I2C Interface Logic). I don't have the hardware for the sensor; so, I cannot proceed to troubleshoot the system. You advance step-by-step with SSS (small start strategy) strategy; I hope that you will be able to come up with a working system.

Good luck!

Go Up