I2C Resources

Hello!

I was looking around for some resources on using the I2C interface for any device other than the touchscreen. So far, I have been unsuccessful and am wondering if there are any Toradex resources on the I2C interface. I am using an Apalis iMX6 module on the Ixora carrier board.

Specifically, I am having a hard time with finding pins 5 & 6 on header X27 of the Ixora carrier board and finding working example code.

Here is what I have found so far: High performance, low power Embedded Computing Systems | Toradex Developer Center

Thank you for taking the time to answer my question!

Greetings @samantha!

Usually I2C devices use kernel device drivers to work. That’s what happens with touchscreens. You have to assign them on the device tree to a compatible kernel driver. Which device are you intending to use?

Besides that, you can always use I2C devices directly writing on their registers in userspace. Here’s the official kernel documentation for that.

To find the correct pins, please refer to the Ixora datasheet.

Usually I2C devices use kernel device drivers to work. That’s what happens with touchscreens. You have to assign them on the device tree to a compatible kernel driver. Which device are you intending to use?

I am using a Raspberry Pi acting as an I2C slave. As far as I know, there is not a kernel module available for this application.

Besides that, you can always use I2C devices directly writing on their registers in userspace. Here’s the official kernel documentation for that.

Thanks @gustavo.tx for the resource! That recommends loading the i2c-dev module, how would I do that using Toradex’s version of Linux? I am running V2.8 at the moment.

To find the correct pins, please refer to the Ixora datasheet.

Will do! Thank you so very much

@samantha,

You are right, there’s not a specific driver for using a Raspberry Pi as an I2C slave. Your way to go will be using i2c-dev.

The module should already be built into our image.

Please refer to this part of our I2C article. Our image comes with I2C tools ( i2cdetect , i2cset and i2cget), a set of command line tools which you can use to send and receive I2C data directly from the terminal.

Then you can follow the official kernel documentation to implement this in your application. Since this is native to Linux, there may be ports to other languages if that’s your case.

The I2C bus driver handles data transfer between master (Apalis) and slave (device). How exactly that data is used defined by particular device connected. Most I2C devices are handled by kernel drivers. The device tree or platform data binds the I2C bus to such drivers. From user space one accesses them then through the relevant subsystem rather than having to do low-level I2C access. For usage details please refer to particular device driver documentation.

Some examples of low-level access to I2C devices described here.

General documentation about Linux I2C subsystem available here.

What kind of I2C device you want to communicate with?

2319-ixora-x27.jpg

Hello @alex.tx ,

Thanks for the resources! They were helpful in preliminary setup, and hopefully future implementation.

I am trying to connect an LCD1602, which can be found using this link: https://www.sunfounder.com/learn/sensor-kit-v2-0-for-arduino/lesson-1-display-by-i2c-lcd1602-sensor-kit-v2-0-for-arduino.html

It is all connected and I have a pullup resistor to 3.3V setup for both SDA and SCL. Unfortunately, the IMX6 does not find the device when I run i2cdetect -y -r 1. Do you have any troubleshooting steps to get the IMX6 to recognize that there is a device on the bus?

Hello @gustavo.tx ,

Thank you for the quick and informative response!
Using i2cdetect -y -r 1, I am not seeing all of the devices I have plugged into the bus. I added the LCD1602 (https://www.sunfounder.com/learn/sensor-kit-v2-0-for-arduino/lesson-1-display-by-i2c-lcd1602-sensor-kit-v2-0-for-arduino.html) to the mix. Do you have some troubleshooting tips or tricks to get this working?

Thank you!

Could you please describe how exactly you did connect that module to Ixora? preferably with picture of your setup. And what is pull-up resistor values?

@alex.tx,

Thank you for continuing your support!

I have the SDA line connected to pin 5, SCL to pin 6 of the X27 header (according to picture above). Power for the LCD1602 is coming from an external source. The resistors are 10k, connected to 3.3V. I tested this setup using a Raspberry Pi 4 and it was able to find the lcd screen.
Here is the o-scope breakdown of the comms:

What is “external power” voltage? I’ve found module schematic - it already has a Pull Up resistors. If you connected module to 5V power supply it can cause a problem.

The Apalis I2C1 interface is mapped to i2c-0 bus at Linux (for Apalis iMX6). So you need to use i2cdetect -y -r 0 command

Thanks for the continued responses @alex.tx! This is SO helpful!

It is connected to a 3.3V power supply.

Do you recommend removing the external pullup resistors then?

I changed to using i2cdetect -y -r 0, it still does not show the device being found.
Here is a screen shot of the results:
2322-output.png

EDIT:
When I run i2cdetect -y -r 0, my o-scope does not pick up anything on the SDA and SCL lines. But it does pick up when I run i2cdetect -y -r 1. Maybe this is part of the issue?

Did you tested this LCD with other device like Arduino or RPi?

Yep! It works with address 0x27 on a Raspberry Pi 4.
Thank you @alex.tx!
Does the edit to my last comment help with troubleshooting? I used Toradex Easy Installer to install version V2.8 this morning, could the install have gone wrong?

Could you specify which exactly Linux image you are running on Apalis iMX6?

I am using V2.8 that automatically popped up on the Toradex Easy Installer

@alex.tx , I have yet to change any configurations for this install
2323-linuximage.png

Hi @samantha

Is the issue solved?

Best regards,
Jaski