PatronP
Posts: 8
Joined: Thu Mar 31, 2016 7:04 am
Location: Sweden

I2C-0 and CM3

Tue Jan 24, 2017 3:27 pm

We have our own carrier board for the compute module where we use I2C-0 on GPIO 0 and 1 for EEPROM and other stuff.
It has been working just fine with CM1 but with CM3 we can’t do anything on the I2C-0 bus with the same setup as on CM1. The only thing we read is 0x1c and 0x43 and it is not on our I2C bus (GPIO0,1)

When investigating further it looks like the I2C-0 is now defaulting to GPIO 46 and 47 and I assume it is used for the I/O expander and something else.
GPIO 0 and 1 are turned into inputs with the same set up that worked on CM1, but with raspi_gpio I have manage to alter the GPIO 0 and 1 to ALT0 (I2C-0) and GPIO 46 and 47 to inputs.
After that the I2C-0 bus is accessible and our devices answering, at least for a while. When starting just about any program the I2C-0 is again moved to GPIO46,47.
That’s why I assume that the I2C-0 is no longer usable on CM3.
When reading the documentation for the CM3 I cannot find anywhere that the CM3 only has one usable I2C bus (I2C-1).

Is there any way to use the I2C-0 bus on CM3?
Is it possible to use any other I2C on either GPIO 46, 47 (for the VC?) and GPIO 0,1 (for us) or do we need to make a new HW version (or use bit banging)?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2536
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C-0 and CM3

Thu Jan 26, 2017 9:43 am

The intention was that I2C-0 is used for camera and display support, but for applications that use neither it would be free for other uses. For various reasons, on a early Pi2s and Pi3 I2C-0 was also used to drive the SMPS and GPIO expander, and that has carried over into CM3 because it works.

In response to your question I've been working on moving SMPS and GPIO support to software-driven ("bit-bashed") I2C. I think this is largely complete now, but as a change that affects most Pis it will require a lot of testing before it is released (assuming we don't find any gotchas).

dakiller
Posts: 6
Joined: Thu Oct 31, 2013 12:34 am

Re: I2C-0 and CM3

Fri Jan 27, 2017 2:51 am

I have just flashed the image of a setup I had on a CM1 onto a new CM3, and the system that it goes in uses I2C-0 on GPIO 0-1 for an RTC and a battery management IC.

The old CM1 was setup and working, but I see that I2C-0 isn't working on the CM3 out of the box.

Is there a fix to get I2C-0 working?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2536
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C-0 and CM3

Fri Jan 27, 2017 8:44 am

We should be able to get I2C-0 working on CM3 as it did on CM - apart from an anomaly with the 1.3 PiZero which we are investigating, testing looks promising. Until then, you should be able to use software I2C on GPIOs 0 and 1 for low-bandwidth applications by adding this to your config.txt:

Code: Select all

dtoverlay=i2c-gpio,i2c_gpio_sda=0,i2c_gpio_scl=1

dakiller
Posts: 6
Joined: Thu Oct 31, 2013 12:34 am

Re: I2C-0 and CM3

Sun Jan 29, 2017 9:35 pm

I added that config, but it hasn't worked

raspi-gpoio still has -

GPIO 00: level=1 fsel=0 alt= func=INPUT
GPIO 01: level=1 fsel=0 alt= func=INPUT
...
GPIO 46: level=1 fsel=4 alt=0 func=SDA0
GPIO 47: level=1 fsel=4 alt=0 func=SCL0

and

i2cdetect -y 0 shows devices at 1c and 43 which are not my devices

PatronP
Posts: 8
Joined: Thu Mar 31, 2016 7:04 am
Location: Sweden

Re: I2C-0 and CM3

Mon Jan 30, 2017 7:44 am

The thing is that it's no longer I2C-0 that's available at GPIO 0 and 1, it is I2C-3.
Try i2cdetect -y 3 and you will find all your devices.

creeswarlowe
Posts: 9
Joined: Mon Feb 06, 2017 2:27 am

Re: I2C-0 and CM3

Sun Feb 26, 2017 4:36 am

I was experiencing the exact same problem - i2c0 on CM1 was working great...if a CM3 is inserted into the same carrier board, i2c0 is no longer accessible (with the same software/device tree/config.txt). In the device tree, attempts to set GPIO pins 0/1 to ALT0 (i2c0) functions did not work...'gpio readall' still reported these pins as inputs. Doing an 'i2cdetect -y 0' and viewing the signals on the scope would not show any activity on the bus (scope), but show some internal devices (0x43 and 0x1c[??] were the two, as I recall). I did notice that 'gpio readall' reported GPIO 46/47 as ALT0 functions (i2c0).

Here's what I found to 'fix' it:
1. Insert 'dtparam=i2c_vc=on' in '/boot/config.txt'
2. In the device tree, configure GPIO 0/1 pins as 'function = "i2c0";', with termination as "no_pulling" or "pull_up", depending on your carrier board's configuration.
3. Edit (if it already exists) or insert the following in the device tree, 'pin_defines' section:

Code: Select all

            [email protected]_SDA {
               type = "internal";
               number = <0>;
            };
            [email protected]_SCL {
               type = "internal";
               number = <1>;
Before, those were number <46> and <47>. After making all of these changes, 'gpio readall' shows GPIO 46/47 as inputs, and GPIO 0/1 as ALT0. It also does a proper 'i2cdetect -y 0', and 'i2cdetect -y 1' (my board has two i2c busses). It's also still able to communicate with both camera ports; one on i2c0, one on i2c1.

Other functions seem to work properly as well, and we haven't found any bad effects from changing the SMPS GPIO (as mentioned above). Do you think this would potentially introduce a problem?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7759
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C-0 and CM3

Sun Feb 26, 2017 8:42 am

DON'T DO THIS
creeswarlowe wrote:I was experiencing the exact same problem - i2c0 on CM1 was working great...if a CM3 is inserted into the same carrier board, i2c0 is no longer accessible (with the same software/device tree/config.txt). In the device tree, attempts to set GPIO pins 0/1 to ALT0 (i2c0) functions did not work...'gpio readall' still reported these pins as inputs. Doing an 'i2cdetect -y 0' and viewing the signals on the scope would not show any activity on the bus (scope), but show some internal devices (0x43 and 0x1c[??] were the two, as I recall). I did notice that 'gpio readall' reported GPIO 46/47 as ALT0 functions (i2c0).

Here's what I found to 'fix' it:
1. Insert 'dtparam=i2c_vc=on' in '/boot/config.txt'
2. In the device tree, configure GPIO 0/1 pins as 'function = "i2c0";', with termination as "no_pulling" or "pull_up", depending on your carrier board's configuration.
3. Edit (if it already exists) or insert the following in the device tree, 'pin_defines' section:

Code: Select all

            [email protected]_SDA {
               type = "internal";
               number = <0>;
            };
            [email protected]_SCL {
               type = "internal";
               number = <1>;
Before, those were number <46> and <47>. After making all of these changes, 'gpio readall' shows GPIO 46/47 as inputs, and GPIO 0/1 as ALT0. It also does a proper 'i2cdetect -y 0', and 'i2cdetect -y 1' (my board has two i2c busses). It's also still able to communicate with both camera ports; one on i2c0, one on i2c1.

Other functions seem to work properly as well, and we haven't found any bad effects from changing the SMPS GPIO (as mentioned above). Do you think this would potentially introduce a problem?
You've told the GPU that the SMPS to control the power to the CM3 is now connected somewhere it isn't. The SMPS will boot with default values which may or may not be suitable (generally I was seeing kernel panics very early in boot). There is a GPIO expander driver also configured using those defines, so you've now lost HDMI hotplug and EMMC_ENABLE_N.

And it doesn't resolve the issue that the GPU will still be trying to use the I2C peripheral at the same time as the ARM, and there is no inter-processor arbitration so interrupts will get serviced by the wrong processor. You can't have two owners of the block.

The better thing to do is to update your firmware using rpi-update (I believe a new apt-get update is imminent). That has switched to the GPU bit-banging I2C to the SMPS and expander, so i2c-0 should now be safely available to use as long as you aren't also using the camera or display.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2536
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C-0 and CM3

Sun Feb 26, 2017 8:52 am

Yes, what 6by9 says. Your suggestion is potentially harmful and completely unnecessary.

creeswarlowe
Posts: 9
Joined: Mon Feb 06, 2017 2:27 am

Re: I2C-0 and CM3

Sun Feb 26, 2017 3:03 pm

Do you think this would potentially introduce a problem?
I guess so! Thanks for the follow-up and answering so quickly. We'll wait for the update.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2536
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: I2C-0 and CM3

Sun Feb 26, 2017 4:08 pm

You can rpi-update now, but you may prefer to wait for the apt-get release.

creeswarlowe
Posts: 9
Joined: Mon Feb 06, 2017 2:27 am

Re: I2C-0 and CM3

Mon Feb 27, 2017 1:29 am

I just did an rpi-update (after putting the device tree back to default) - everything functions properly, both buses are alive now. Thanks for the update!

Sohil.Mehta
Posts: 57
Joined: Thu Feb 01, 2018 6:45 am

Re: I2C-0 and CM3

Mon Apr 23, 2018 7:30 am

Hi,

I have an IMU (part# LSM9DS1) that I am trying to connect to I2C0 of a CM3L. When I do i2cdetect -y 0, I see that my IMU is connected to address 1e (accelerometer) and 6b (gyroscope). When I do raspi-gpio get 0-1, it shows the pins functionality as SDA0 and SCL0 respectively. Also, this only works if I include the following line in /boot/config.txt:

Code: Select all

dtparam=i2c0=on
Then I run my python code to read the sensor's readings, and I get this error:

Code: Select all

terminate called after throwing an instance of 'int'
Aborted

I feel there is nothing wrong with my code because I run the same python code on I2C1, and it works perfectly fine. This is something to do with the funny business that's happening with I2C0. I even tried doing what PhilE suggested i.e. adding "dtoverlay=i2c-gpio,i2c_gpio_sda=0,i2c_gpio_scl=1" in /boot/config.txt. I still can't get the I2C0 to work. Can someone help me please?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7759
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: I2C-0 and CM3

Mon Apr 23, 2018 8:38 am

Sohil.Mehta wrote:
Mon Apr 23, 2018 7:30 am
Hi,

I have an IMU (part# LSM9DS1) that I am trying to connect to I2C0 of a CM3L. When I do i2cdetect -y 0, I see that my IMU is connected to address 1e (accelerometer) and 6b (gyroscope). When I do raspi-gpio get 0-1, it shows the pins functionality as SDA0 and SCL0 respectively. Also, this only works if I include the following line in /boot/config.txt:

Code: Select all

dtparam=i2c0=on
Then I run my python code to read the sensor's readings, and I get this error:

Code: Select all

terminate called after throwing an instance of 'int'
Aborted

I feel there is nothing wrong with my code because I run the same python code on I2C1, and it works perfectly fine. This is something to do with the funny business that's happening with I2C0. I even tried doing what PhilE suggested i.e. adding "dtoverlay=i2c-gpio,i2c_gpio_sda=0,i2c_gpio_scl=1" in /boot/config.txt. I still can't get the I2C0 to work. Can someone help me please?
There is nothing strange going on with i2c-0 any more - it has been available since the discussion back in Feb 2017.

Without some more detail of your code and some context for that error message, there's next to nothing we can do to help. That's not a normal Python error message, so one would guess that you're calling into some random C++ code.
I'd also strongly suggest that you start a new thread as few will look at loosely connected random comments on old ones.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Sohil.Mehta
Posts: 57
Joined: Thu Feb 01, 2018 6:45 am

Re: I2C-0 and CM3

Mon Apr 23, 2018 9:10 am

Thanks 6by9. I will do that.

Return to “Compute Module”