0
votes

I try to connect an NXP i.MX7D running Android Things to a Arduino UNO using I2C. The slave code is fairly simple :


#include <Wire.h>

void setup() {
  Wire.begin(0x08);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello "); // respond with message of 6 bytes
  // as expected by master
}

The two devices are connected like this:

NPX SDA Pin ---> 3.3v level converter 5v ----> Arduino PIN A4 NPX SCL Pin ---> 3.3v level converter 5v ----> Arduino PIN A5

When I use the PIO tool I can't seem to connect or read the Arduino slave. There is two BUS (I2C1, I2C2) on the NPX I tried both with the same result:

imx7d_pico:/ $ pio i2c I2C1 0x08 read-reg-byte 0x00                                                                   
[WARNING:client_errors.cc(35)] error 6: No such device or address
6|imx7d_pico:/ $ pio i2c I2C2 0x08 read-reg-byte 0x00                                                                 
[WARNING:client_errors.cc(35)] error 6: No such device or address

I assume the level converter work properly I did have limited success with UART connection (Arduino was able to emit to NPX but not NPX to Arduino, will investigate this after)

Here are some pictures of the connection.

NPX Connection SDA SDL Level Converter connection Level converter back for reference Arduino UNO A4-A5 Pins Overall mess

1

1 Answers

1
votes

Try to add on Wire.onReceive callback(together with onRequest) to your arduino code.

Like this:

#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop() {
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}