1

I am working on a RPi 5 running Bookworm with C.

Adding the line dtparam i2c_arm=on to the config.txt enables I2C on GP Pins 2/3 accessed through /dev/i2c_1. Reboot to activate. This works fine on Chip 4 lines 2/3.

However: if libgpiod functions are used to control the pins, then any I2C attempt will fail thereafter, unless the BCM function flags are reset to ALT0(?), or the system is rebooted. Not unreasonable - but it seems fragile.

Using gpioinfo does not report the I2C setting for the pins, even if the I2C connection is active.

Am I missing something? Is there another function I can use to ensure that gpioinfo will report correctly? And ideally lock out the other libgpiod functions and protect I2C?

To be sure of what is going on, I have a digital analyzer connected to the pins. It shows that lines 2/3 are working with I2C but tend to adopt the last gpioset value in a way that blocks I2C.

Kent Gibson
  • 244
  • 3
  • 11
Nic A
  • 11
  • 1

1 Answers1

2

libgpiod controls GPIO i.e. it allows pins to be sent to INPUT, OUTPUT (and pullups) and NOTHING ELSE. This is well documented and discussed if you search.

If you want to use other functions e.g. I²C you need to use the kernel drivers - again discussed many times. libgpiod knows nothing about other pin functions.

If you want to use I²C then don't fiddle with the pins using libgpiod.
Joan's lg may be able to restore functionality but I have not tried.

I have written a program gpioreadall which lists all pins/functions.
This uses the pinctrl debug tool which you can use directly.

You may not like this (and neither do many of us) but the kernel purists at Raspberry Pi Ltd. now rule.
None of the older libraries which directly access SOC registers work on the Pi5.

Milliways
  • 62,573
  • 32
  • 113
  • 225