0

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.

1 Answer 1

1

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.

11
  • Thanks for the clear answer. I half expected this to be the case. I had my own libraries accessing SOC registers - That's how i got here! :-)
    – Nic A
    Feb 23 at 8:34
  • 1
    Who are these "kernel purists", and what exactly did they do to move your cheese? Feb 28 at 1:30
  • @KentGibson post some examples (preferably usable by ordinary users NOT using automake); post some user documentation e.g. a man page NOT html which is not helpful on a command line. NOTE I was not referring to you put other Pi engineers who keep saying not to poke at registers and use gpiod but provide no help as to HOW. I know it is not your doing that the Pi implementation is >3 years old but expecting new users to build their own library is unrealistic. After all most Pi are a hobbist tool - why do they have to follow rules designed for a multi user system.
    – Milliways
    Feb 28 at 1:38
  • Examples of what? That belongs in another question. The Pi engineers didn't make that decision because they are kernel purists, but because they could not adopt a new architecture AND maintain backward compatibility. They are falling back to using kernel interfaces only because the kernel provides compatibility across platforms, including across Pi variants. Linux being multi-user is not relevant, the design is due to it supporting multi-tasking, i.e. being an OS. And trying to do that for every platform out there, not just the ones hobbyists happen to be using. Feb 28 at 12:40
  • @KentGibson the simple fact is for a device (at least originally) claiming to be an educational tool there are simply NO examples of code designed to help students. Over the years I have taught coding to many engineers (although my primary role was as a network planner). Can you point me to a single example of GPIO code (other than the contribution of enthusiasts).
    – Milliways
    Feb 28 at 13:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.