0

I am trying to read data from a pair of TLE493-W2B6 magnetic position sensors [1, 2] with Arduino over I2C. I can read from each sensor individually, using the Arduino library from the manufacturer [3, with corrections from 4], but when I try to read both sensors, I can only read the first sensor I initialize. The first sensor then issues empty write commands, and the second sensor NACKs when I try to address it. The sensors have different factory-programmed addresses, and they are connected to the same I2C bus on a PCB with pullup resistors. When I scan the bus for I2C devices, both sensors show up (ie they both ACK their own address).

How do I read both sensors over I2C with Arduino?

Code for reading both sensors:

#include <Tle493d_w2b6.h>

Tle493d_w2b6 sensor_A0 = Tle493d_w2b6(Tle493d_w2b6::MASTERCONTROLLEDMODE, Tle493d_w2b6::TLE493D_W2B6_A0);
Tle493d_w2b6 sensor_A1 = Tle493d_w2b6(Tle493d_w2b6::MASTERCONTROLLEDMODE, Tle493d_w2b6::TLE493D_W2B6_A1);

void setup() {
  Serial.begin(9600);
  while (!Serial);

  sensor_A1.begin();
  sensor_A0.begin();
}

void loop() {
  sensor_A1.updateData();
  Serial.print(sensor_A1.getX());
  Serial.print(", ");
  Serial.print(sensor_A1.getY());
  Serial.print(", ");
  Serial.println(sensor_A1.getZ());

  sensor_A0.updateData();
  Serial.print(sensor_A0.getX());
  Serial.print(", ");
  Serial.print(sensor_A0.getY());
  Serial.print(", ");
  Serial.println(sensor_A0.getZ());

  delay(500);

}

Here is what the average cycle looks like:

Oscilloscope capture of sensors 1 and 2

  1. (0.005ms) Read the first six registers of sensor A1.
    • Address frame = 0x22
    • R/W = R
    • Data frames = FF 00 FF 80 F1 1F 6A~ (this is as expected)
  2. (0.828ms) Library sends empty write command to sensor A1?
    • Address frame = 0x22
    • R/W = W
    • Data frames = empty
  3. (2.281ms) Attempt to read the first six registers of sensor A0, address is NACK'd, no data is returned.
    • Address frame = 0x35~
    • R/W = R
    • Data frames = empty
  4. (2.353ms) Library sends another empty write command to sensor A1.
    • Address frame = 0x22
    • R/W = W
    • Data frames = empty
  • There seems to be something wrong at the fundamental I2C protocol execution. There are no empty writes or reads in the library (I think this isn't even possible with the Wire library, which is used there). Also the spike at the end of the 0x44 write span (as in the image) is suspicious. The sensor is operating at 3.3V. Do you use a 3.3V Arduino? You didn't specify – chrisl Jan 9 at 8:53
  • 1
    I was using the 5V rail on the Arduino to power the sensors. I replaced the sensors, and I am now powering them off the Arduino's 3.3V rail, with the Arduino's internal I2C pullups disabled and external pullups to the 3.3V. Still having the same issue. I am going to try sending bits with an I2C host adapter, to see if it's a problem on the Arduino side. – Zach Morris Jan 9 at 21:29
  • By default the sensor adds trigger bits to the register address, so I'm having some trouble communicating with the device. I'm having some trouble getting the right initialization sequence. – Zach Morris Jan 14 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.