0

When I boot my Raspberry Pi 3 GPIO port 2 (SDA.1) is in mode "IN" instead of "ALT0". This prevents I²C communication and causes i2cdetect -y 1 to wrongly show all addresses. As soon as I set the correct mode for the port (gpio -g mode 2 alt0) the I²C hardware and i2cdetect work as expected.

On fresh Raspbian installations the mode is "ALT0" on startup. So I think there's something wrong in my current configuration. I checked

  • /etc/rc.local
  • ~/.config/lxsession/LXDE-pi/autostart
  • If there is a driver configuration in /etc/modprobe.d regarding this

but couldn't find anything that switches the GPIO mode on startup. So it could be a driver or an init.d script. How can I find out where the mode is switched as quick as possible?


Note: The common assumption on the web is a hardware failure if i2cdetect shows all addresses, however a wrong mode could cause the same. I'm telling this here, because others may draw wrong conclusions like me. So don't change / throw away your Raspberry before having checked the correct mode "ALT0" being set for GPIO ports 2 and 3 by calling the gpio readall command!

  • 1
    On fresh Raspbian installations the default will be no I2C bus and the GPIO left as inputs. You have changed the defaults, by the sound of it you have changed the defaults in an inconsistent way. Perhaps edit your question to indicate the changes you have made? – joan Apr 20 '17 at 8:32
  • I agree with @joan. IF you want to enable I²C you should do it through raspi-config and NOT fiddle with generally obsolete files. Far better is to enable I²C and driver through Device Tree for supported hardware. – Milliways Apr 20 '17 at 8:38
  • @joan sorry I forgot to mention that I enabled I²C via raspi-config - then the default mode is ALT0 – fishbone Apr 20 '17 at 14:30
  • If you enabled I2C with raspi-config that should have made the correct device tree entry in /boot/config,txt. I don't know if raspi-config also adds the needed i2c-dev line to /etc/modules. The end result should be SDA/SCL (GPIO 2/3) being set to mode ALT0 during boot. – joan Apr 20 '17 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.