mgregg
Posts: 3
Joined: Thu Dec 08, 2016 7:42 am

i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 7:48 am

I have some hats here with i2c devices on them.

I acquired a RPi 3, and promptly discovered I couldn't see them.

I was able to set the following in my /boot/config.txt to enable something i2s related:
dtparam=i2c_arm=on
dtparam=i2c_vc=on

I think that is what gave me the dev devices:
$ ls /dev/i2c-*
/dev/i2c-0 /dev/i2c-1

When I scan the ports, I get unexpected results:
$ sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

$ sudo i2cdetect -y 1 returns a bunch of errors.

I don't have any device on port 0 at 0x43. What gives? Is this some sort of expander on port 0? How do I access devices on it?

Thank you.

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

Re: i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 10:17 am

i2c-0 is not available on the Pi3 as it is used by the GPU firmware side to talk to a GPIO expander (uses GPIOs 46&47 IIRC), as well as HAT EEPROMs, the camera, and display. Accessing the i2c peripheral from both ARM and GPU will cause issues.

Being a pedant, if you've used GPIOs 0&1 (pins 27&28) for anything other than an ID EEPROM, then you expansion board is not a HAT according to the HAT specification.
The Pi schematics also specifically state:
ID_SD and ID_SC PINS:
These pins are reserved for ID EEPROM.
At boot time this I2C interface will be
interrogated to look for an EEPROM
that identifes the attached board and
allows automagic setup of the GPIOs
(and optionally, Linux drivers).
DO NOT USE these pins for anything other
than attaching an I2C ID EEPROM. Leave
unconnected if ID EEPROM not required
Whoever designed your board ignored that, so can't really complain that it now doesn't work. Oops.

You could use the i2c-gpio drivers on GPIOs 0&1 to bit-bang an I2C interface, but it'll be slow.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

mgregg
Posts: 3
Joined: Thu Dec 08, 2016 7:42 am

Re: i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 5:37 pm

These hats were built for the raspberry pi 1. The headers only go up to 27 pins.

I find it disappointing that the specification was changed in a way that breaks older hats.

It also looks like they are trying to redefine what a "Hat" is.

I'll look into bit banging the interface tonight. It's a RTC and a temp sensor. I can probably pull those off with low speeds.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5300
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 5:44 pm

i2c_vc has always been reserved for the firmware. i2c_gpio should work nicely though.

User avatar
DougieLawson
Posts: 33785
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 5:47 pm

mgregg wrote: I find it disappointing that the specification was changed in a way that breaks older hats.
Eh?

/dev/i2c-1 is on pin#3 & pin#5

It's only the really ancient Rev1 26-pin board that had /dev/i2c-0 on pin#3 & pin#5 and there are a tiny number of those Raspberries out in the wild. I got my first RPi 1B Rev2 in October 2012 and it's got a normal /dev/i2c-1 I²C interface.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

User avatar
bensimmo
Posts: 3190
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 6:07 pm

From something I was doing this morning (I2C stuff) it changed at Revision 3 (internal, at least that's what it tries to detect to auto select 1 or 0, it did work so I removed it)
Basically 256MB ram is 0 and 512MB onwards is on 1

All I did for I2C was tick the box in Raspi-Config and reboot.
Temp, pressure, giro and magnetometer are all working.
Using Smbus2 in python3


I think they where actually trying To Define what a HAT w.r.t. a Pi and not redefine.

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

Re: i2c-0 on RPi3 Where did you go

Thu Dec 08, 2016 10:34 pm

I think bensimmo is probably correct - the very original rev1 PiB 256MB did bring out i2c-0 to pins 3&5 on the 26pin header and your old boards are probably rev1. That changed when production was brought back to the UK, so Sept 2012. All subsequent boards (A+, B+, B2, B3, and Zero) have had i2c-1 on those pins.

The simple answer is do NOT enable i2c_vc=on on a Pi3 - bad things will happen. The 0x43 you are seeing is the GPIO expander (which slightly confuses me as I would have expected pin muxing woes resulting in nothing detected rather than seeing the expander).
/dev/i2c-1 is brought out on pins 3&5 of the 40 pin header, and that is available for use by your application.

If you need to support both, then you will need to check the board revision yourself and open /dev/i2c-0 or /dev/i2c-1 based on that. In neither case should you need i2c_vc=on, as i2c_arm=on will enable the correct device for your board revision.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

mgregg
Posts: 3
Joined: Thu Dec 08, 2016 7:42 am

Re: i2c-0 on RPi3 Where did you go

Fri Dec 09, 2016 6:25 am

6by9 wrote:I think bensimmo is probably correct - the very original rev1 PiB 256MB did bring out i2c-0 to pins 3&5 on the 26pin header and your old boards are probably rev1. That changed when production was brought back to the UK, so Sept 2012. All subsequent boards (A+, B+, B2, B3, and Zero) have had i2c-1 on those pins.

The simple answer is do NOT enable i2c_vc=on on a Pi3 - bad things will happen. The 0x43 you are seeing is the GPIO expander (which slightly confuses me as I would have expected pin muxing woes resulting in nothing detected rather than seeing the expander).
/dev/i2c-1 is brought out on pins 3&5 of the 40 pin header, and that is available for use by your application.

If you need to support both, then you will need to check the board revision yourself and open /dev/i2c-0 or /dev/i2c-1 based on that. In neither case should you need i2c_vc=on, as i2c_arm=on will enable the correct device for your board revision.
Turning off i2c_vc=on opens /dev/i2c-1 only. But that port doesn't find anything on that bus if they are plugged into pins 3&5.

I'll be happy if you can prove me wrong.

It looks as though if you have i2c on pins 3&5, without software i2c, you cannot use those devices.

User avatar
DougieLawson
Posts: 33785
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: i2c-0 on RPi3 Where did you go

Fri Dec 09, 2016 8:14 am

What board revision do you have?

cat /sys/firmware/devicetree/base/model
will tell you.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

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

Re: i2c-0 on RPi3 Where did you go

Fri Dec 09, 2016 10:13 am

mgregg wrote:Turning off i2c_vc=on opens /dev/i2c-1 only.
Correct. i2c_arm=on will enable /dev/i2c-1 on all revisions of the Pi, except on the 256MB rev1 model B from 2012 where it enables i2c-0.
It is there to enable the I2C controller that is available for the ARM to use, hence the name. i2c_vc is there for the I2C bus assigned to the GPU (VideoCore).
mgregg wrote:But that port doesn't find anything on that bus if they are plugged into pins 3&5.
Details of what you've done then. Many many people are using i2c-1 on pins 3&5 without issue.
mgregg wrote:I'll be happy if you can prove me wrong.
You need to provide a load more information then. No one else can see your setup.
- I am assuming this is a stock Raspbian, Raspbian Lite, or NOOBS install. I'm afraid if not then you're on your own/need to go to that distos support forum.
- As Dougie has just asked, what board revision are you dealing with on your old and new boards?
- The pin assignment of pin 13 also changed between rev1 & 2 from GPIO27 to GPIO21. I take it that you aren't using that to gate any of your I2C comms.
- Have you proved this exact board is fully working using a different Pi?
- (suck eggs) Is the board correctly aligned on the header?
- Does i2c-detect -y 1 run at a sensible speed, or is it slow? Slow response would be indicative of a short to ground on SCL enforcing clock stretching.
- Check with "sudo raspi-gpio --get" that GPIOs 2&3 are assigned to ALT0 and therefore SDA1 and SCL1. No other GPIOs should be assigned to the SDA1 or SCL1 function, otherwise you will get issues.
- Stick a scope or Piscope on pins 3&5/GPIOs 2&3. Are the lines waggling?
mgregg wrote:It looks as though if you have i2c on pins 3&5, without software i2c, you cannot use those devices.
Sorry, that is absolute twaddle.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4579
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: i2c-0 on RPi3 Where did you go

Sat Dec 10, 2016 10:22 pm

6by9 wrote: ...
- Check with "sudo raspi-gpio --get" that GPIOs 2&3 are assigned to ALT0 and therefore SDA1 and SCL1. No other GPIOs should be assigned to the SDA1 or SCL1 function, otherwise you will get issues.
...
It's also possible to use wiringPi's "gpio readall" command** to provide a similar check.
Trev.
** FWIW, some examples for various Pi's here:
http://www.cpmspectrepi.uk/raspberry_pi ... adall.html
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 5 guests