0

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 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

5 Comments

Sadly still not able to get detected by the NPX.
Do you have a logic analyzer? or another arduino board to make sure that your i2c line is really active? It's not recommended, you can damage your SOC but you can try direct connection with pull down resistors(~4.7k), just for validation. Also you can try to check your TTL sync board, applying 5v and check with voltmeter the out(should be 3.3)
I'll try hook two arduino together to help debug, I don't have a logic analyzer so i'm a bit in the dark. I guess if the two arduino are able to speak together something is fishy on the NPX side. Stay tuned and thanks for your time!
I2C work well between the two Arduino, I saw some issue with the connection of the level converter I used this documentation: learn.sparkfun.com/tutorials/…. But still no success, I now think the issue is really on the NPX side I'll continue dig-up
Ok, it looks like I had to reset the Arduino while hooked to the NPX to work. Not totally sure why I assume some handshake occurs when the slave address is set in the setup?! Now it seems to work fine with the code above. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.