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.
#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).
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 --
Wire.beginTransmission(25); // transmit to device #25
Also, that --
Wire.requestFrom(25, (uint8_t)2);
data = Wire.read();
data |= (Wire.read() << 8);
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.
Wire.beginTransmission(50); //checking if transmission was succesful
Wire.endTransmission(); // stop transmitting
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!
#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()
{
}
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.