Problem interfacing SL3S4011 RFID using I2C

Hello there,

I’m working on a RFID project for a few week and now I’m stuck. I try to read a random adress with I2C interface on a SL3S4011 uing my Arduino micro but it doesn’t work. I try to read for exemple the memory adress EPC 2000(HEX) on my slave RFID device. The adress of the device is 50(HEX).

In the datasheet of the RFID chip I found this:

Here is my code:

#include <Wire.h>

void setup() {

  Wire.begin();
  Serial.begin(9600);

}

void loop() {
 
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.write((int)(0x2000 >> 8));   // MSB byte adress
  Wire.write((int)(0x2000 & 0xFF)); // LSB byte adress
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.endTransmission();           // Stop transmission


  int content = Wire.read();      // receive a byte 
  Serial.print(content);          // print the byte
  

}

If anyone can help me I would be very grateful.

Thank you

  Wire.beginTransmission(0x50);     // Start+device select
  Wire.write((int)(0x2000 >> 8));   // MSB byte adress
  Wire.write((int)(0x2000 & 0xFF)); // LSB byte adress
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.endTransmission();           // Stop transmission

The beginTransmission() methods sets up some buffers. You write data to the buffers, but don't send it. Then, you set up the buffers again, but don't write anything before sending the data to device.

I can't imagine how you think that will do anything useful.

Thanks for your answer PaulS. I know but in datasheet of the RFID chip they say to load the adress without sending a Stop condition so I can't use a Wire.endTransmission(). Thus I tried this:

void loop() {

  bool stop = false;
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.write((int)(0x2000 >> 8));   // MSB byte adress
  Wire.endTransmission(stop); 
  Wire.write((int)(0x2000 & 0xFF)); // LSB byte adress
  Wire.endTransmission(stop); 
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.endTransmission();           // Stop transmission


  int content = Wire.read();      // receive a byte 
  Serial.print(content);          // print the byte

}

But it doesn't work either. I don't know how to do the same opération as in the datasheet for "Random Adress Read". I'm a little lost..

Every beginTransmission() needs an endTransmission(), with some write()s in between.

Every endTransmission() must follow a beginTransmission(), with some write()s in between.

It's time you took a peak at the documentation. Arduino - WireEndTransmission

Ok so if i understand i must do Something like this:

void loop() {
  int MSB=0x2000 >> 8;
  int LSB=0x2000 & 0xFF;
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.write((int)MSB);   // MSB byte address
  Wire.endTransmission(false); 
  Wire.beginTransmission(0x50);
  Wire.write((int)LSB);   // LSB byte address
  Wire.endTransmission(false);
  Wire.requestFrom(0x50, 2); 
  if (2 <= Wire.available()) {
   MSB = Wire.read();  // MSB
   LSB = Wire.read();  // LSB
  }

  int content = Wire.read();      // receive a byte 
  Serial.print(content);          // print the byte

}

But it doesn’t work either… Can you help me ?

  Wire.write((int)MSB);   // MSB byte address

Every time you post code, you've added some other weirdness. The write() method takes a byte. Why are you casting the variable, whatever type it is, to an int?

You ask for two bytes. You then read three bytes, and ignore the first two. I just don't get it.

Ok but do you know what makes is not work in my code ? Because if it is, that will be verry helpfull for me. And I know my way of coding is not verry good.

Here my last version:

void loop() {
  byte MSB=0x2000 >> 8;
  byte LSB=0x2000 & 0xFF;
  Wire.beginTransmission(0x50);     // Start+device select
  Wire.write(MSB);   // MSB byte address
  Wire.endTransmission(false); 
  Wire.beginTransmission(0x50);
  Wire.write(LSB);   // LSB byte address
  Wire.endTransmission(false);
  Wire.requestFrom(0x50, 2); 
  if (Wire.available()) {
   MSB = Wire.read();  // MSB
   LSB = Wire.read();  // LSB
  }

  int content = Wire.read();      // receive a byte 
  Serial.print(content);          // print the byte

}

Thank you

  Wire.beginTransmission(0x50);     // Start+device select
  Wire.write(MSB);   // MSB byte address
  Wire.endTransmission(false);
  Wire.beginTransmission(0x50);
  Wire.write(LSB);   // LSB byte address
  Wire.endTransmission(false);

Why do you need to use two transactions to write two bytes? One of the transactions needs to use true as the argument to endTransmission().

  Wire.requestFrom(0x50, 2); 
  if (Wire.available()) {
   MSB = Wire.read();  // MSB
   LSB = Wire.read();  // LSB
  }

  int content = Wire.read();      // receive a byte
  Serial.print(content);          // print the byte

Ask for 2 bytes. Read 3 bytes. Pretend that the unsent byte is actually an int.

You just do NOT get it, do you? You need a new hobby. Basket weaving, maybe.