raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

How many I2C buses does Pi 4 has?

Mon Oct 05, 2020 8:31 pm

Hi, how many separate I2C buses are there in the Pi4?

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Mon Oct 05, 2020 9:01 pm

https://www.raspberrypi.org/documentati ... 11_1p0.pdf
page 31, it lists the addresses for 6 i2c controllers, but BSC2 was skipped and the text says there are 8 total

https://elinux.org/RPi_BCM2711_GPIOs
and page 98 of the previous pdf, then list which pins each i2c controller can be routed to

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Mon Oct 05, 2020 9:11 pm

cleverca22 wrote:
Mon Oct 05, 2020 9:01 pm
https://www.raspberrypi.org/documentati ... 11_1p0.pdf
page 31, it lists the addresses for 6 i2c controllers, but BSC2 was skipped and the text says there are 8 total

https://elinux.org/RPi_BCM2711_GPIOs
and page 98 of the previous pdf, then list which pins each i2c controller can be routed to
Thank you. Do you mean these?

• BSC0: 0x7E20 5000
• BSC1: 0x7E80 4000
• BSC3: 0x7E20 5600
• BSC4: 0x7E20 5800
• BSC5: 0x7E20 5A80
• BSC6: 0x7E20 5C00

By "master", does that mean these six are separate buses each can run at full speed?

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Mon Oct 05, 2020 9:19 pm

raspberry_user wrote:
Mon Oct 05, 2020 9:11 pm
Thank you. Do you mean these?

• BSC0: 0x7E20 5000
• BSC1: 0x7E80 4000
• BSC3: 0x7E20 5600
• BSC4: 0x7E20 5800
• BSC5: 0x7E20 5A80
• BSC6: 0x7E20 5C00

By "master", does that mean these six are separate buses each can run at full speed?
yep

you can enable each of them in config.txt, and they will show up as /dev/i2c-* under linux

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 1:04 am

cleverca22 wrote:
Mon Oct 05, 2020 9:19 pm
raspberry_user wrote:
Mon Oct 05, 2020 9:11 pm
Thank you. Do you mean these?

• BSC0: 0x7E20 5000
• BSC1: 0x7E80 4000
• BSC3: 0x7E20 5600
• BSC4: 0x7E20 5800
• BSC5: 0x7E20 5A80
• BSC6: 0x7E20 5C00

By "master", does that mean these six are separate buses each can run at full speed?
yep

you can enable each of them in config.txt, and they will show up as /dev/i2c-* under linux
Thank you. I am a bit confused about the bus speed. Somewhere I read it is 400Kb/s rather than 400MHz. Can all six I2C buses on the Pi 4 run independently at 400MHz or faster at the same time?

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 4:29 am

raspberry_user wrote:
Tue Oct 06, 2020 1:04 am
Thank you. I am a bit confused about the bus speed. Somewhere I read it is 400Kb/s rather than 400MHz. Can all six I2C buses on the Pi 4 run independently at 400MHz or faster at the same time?
they all appear to share a common clock input of (i think) 150mhz
but then each controller has its own clock division register, to set a per-controller speed for the actual data being moved

User avatar
joan
Posts: 15940
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 7:31 am

Assume they can run at 400kbps (400MHz or anywhere near is impossible).

By master they mean the hardware can only act as a bus master, not as a bus slave.

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 7:32 am

cleverca22 wrote:
Tue Oct 06, 2020 4:29 am
raspberry_user wrote:
Tue Oct 06, 2020 1:04 am
Thank you. I am a bit confused about the bus speed. Somewhere I read it is 400Kb/s rather than 400MHz. Can all six I2C buses on the Pi 4 run independently at 400MHz or faster at the same time?
they all appear to share a common clock input of (i think) 150mhz
but then each controller has its own clock division register, to set a per-controller speed for the actual data being moved
Thank you. Is there some kind of official document to clear the doubt? If I want 3 independent I2C channels to gather data at max speed, Is Pi 4 faster than an I2C Multiplexer + (Arduino or Teensy)?

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 7:40 am

joan wrote:
Tue Oct 06, 2020 7:31 am
Assume they can run at 400kbps (400MHz or anywhere near is impossible).

By master they mean the hardware can only act as a bus master, not as a bus slave.
Thank you. So the Pi4 has six I2C master buses?

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

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 10:11 am

Datasheet for the Pi - https://www.raspberrypi.org/documentati ... 11_1p0.pdf

Page 31
The Broadcom Serial Control (BSC) controller is a master, fast-mode (400Kb/s) BSC controller.
...
The BSC controller has eight memory-mapped registers. All accesses are assumed to be 32-bit. Note that the BSC2 and BSC7 masters are dedicated for use by the HDMI interfaces and should not be accessed by user programs
8 - 2 = 6 I2C interfaces available for use by user programs.

(I'd need to double check but I'm 99% certain that the HDMI I2C blocks are actually different from the BSC. There's a driver for them now (bcm2711-hdmi-i2c), but are not usable for generic purposes)

Page 98 gives the alternate GPIO assignments for breaking out those interfaces. (ALT5 on GPIOs 0-13, and 22-23).
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.

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 12:58 pm

6by9 wrote:
Tue Oct 06, 2020 10:11 am
Datasheet for the Pi - https://www.raspberrypi.org/documentati ... 11_1p0.pdf

Page 31
The Broadcom Serial Control (BSC) controller is a master, fast-mode (400Kb/s) BSC controller.
...
The BSC controller has eight memory-mapped registers. All accesses are assumed to be 32-bit. Note that the BSC2 and BSC7 masters are dedicated for use by the HDMI interfaces and should not be accessed by user programs
8 - 2 = 6 I2C interfaces available for use by user programs.

(I'd need to double check but I'm 99% certain that the HDMI I2C blocks are actually different from the BSC. There's a driver for them now (bcm2711-hdmi-i2c), but are not usable for generic purposes)

Page 98 gives the alternate GPIO assignments for breaking out those interfaces. (ALT5 on GPIOs 0-13, and 22-23).
I have read Page 31 but it does not say if these 6 I2C buses are independent (no sharing of bus), whether or not they are each operate at at maximum speed and how fast that maximum speed is when all six buses are used. Please double check. Thank you.

fanoush
Posts: 896
Joined: Mon Feb 27, 2012 2:37 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 1:33 pm

raspberry_user wrote:
Tue Oct 06, 2020 7:32 am
Is Pi 4 faster than an I2C Multiplexer + (Arduino or Teensy)?
i2c bus is quite slow when compared e.g. to SPI. 100kbits or 400kbits are typical i2c speeds so it is like serial UART. E.g SPI can go to 80Mbits and up so that's is 800x of that. Also the devices attached to i2c are typically not needed to be fast.

So any current $1 microcontroller can keep up with i2c speed, you don't need pi4 for that. Also i2c is even often bitbanged over two gpios as it is not that hard and speed is not important so sometimes the hw i2c is not used even if available on the microcontroller. See example here https://en.wikipedia.org/wiki/I%C2%B2C# ... r_protocol

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

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 4:24 pm

raspberry_user wrote:
Tue Oct 06, 2020 12:58 pm
I have read Page 31 but it does not say if these 6 I2C buses are independent (no sharing of bus), whether or not they are each operate at at maximum speed and how fast that maximum speed is when all six buses are used. Please double check. Thank you.
Sharing of which bus exactly are you fretting over?

They do sit on a common AMBA APB bus, but so do most of the peripherals on the SoC. Bandwidth there isn't an issue (somewhere around 1Gbyte/s).
They share an interrupt line, but seeing as each has a 16byte FIFO, generally speaking you only get one interrupt per transfer.
They are fed from a common 150MHz clock, but each has a CDIV register to allow them to operate at different bus frequencies.

Running all 6 simultaneously at 400kHz shouldn't be any issue.
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.

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Tue Oct 06, 2020 5:42 pm

6by9 wrote:
Tue Oct 06, 2020 4:24 pm
raspberry_user wrote:
Tue Oct 06, 2020 12:58 pm
I have read Page 31 but it does not say if these 6 I2C buses are independent (no sharing of bus), whether or not they are each operate at at maximum speed and how fast that maximum speed is when all six buses are used. Please double check. Thank you.
Sharing of which bus exactly are you fretting over?

They do sit on a common AMBA APB bus, but so do most of the peripherals on the SoC. Bandwidth there isn't an issue (somewhere around 1Gbyte/s).
They share an interrupt line, but seeing as each has a 16byte FIFO, generally speaking you only get one interrupt per transfer.
They are fed from a common 150MHz clock, but each has a CDIV register to allow them to operate at different bus frequencies.

Running all 6 simultaneously at 400kHz shouldn't be any issue.
Thank you. My experience with the Pi4 is just to use it for Octoprint. I don't know which bus I am fretting over. I am trying to decide whether to use the Pi4 or I2C Multiplexer + (Arduino or Teensy) for data logging of continuous analogue data from various sensors.

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 5:48 pm

Hi, I have the default I2C bus (GPIO 2 and 3) working on my Pi4 8GB. "sudo i2cdetect -y 1" shows a table with I2C device number shown. "ls /dev/i2c-*" shows /dev/i2c-1

How do I enable those five additional independent I2C buses and also make all six buses run at full speed? Any instructions? It seems that I may need to modify config.txt but I don't know where it is and what to put inside the file.


raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 8:12 pm

I have done that already. I thought it enables the default I2C bus only. So there is no need to modify the config.txt @cleverca22 mentioned?

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 8:46 pm

Code: Select all

[clever@amd-nixos:~/apps/rpi]$ ls firmware/boot/overlays/ | grep i2c
i2c0.dtbo
i2c1.dtbo
i2c3.dtbo
i2c4.dtbo
i2c5.dtbo
i2c6.dtbo
these are the overlays you would find on /boot/overlays, you can enable each one with `dtoverlay=i2c5` in config.txt, but they may also need a dtparam of some kind to set the pins right

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 9:10 pm

cleverca22 wrote:
Sun Oct 18, 2020 8:46 pm

Code: Select all

[clever@amd-nixos:~/apps/rpi]$ ls firmware/boot/overlays/ | grep i2c
i2c0.dtbo
i2c1.dtbo
i2c3.dtbo
i2c4.dtbo
i2c5.dtbo
i2c6.dtbo
these are the overlays you would find on /boot/overlays, you can enable each one with `dtoverlay=i2c5` in config.txt, but they may also need a dtparam of some kind to set the pins right
Thank you. I am not familiar with config.txt and the parameters mentioned. I worry that I will break the Pi. Is there a sample config.txt file that enables all those six buses at max speed?

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 9:13 pm

its not really possible to break it with config.txt changes
the worst is that it wont boot anymore until you undo the change

but you can always put the SD card into another computer and edit the config.txt from there to undo things

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 9:36 pm

OK. In the worst worst case, just reformat and reinstall the OS.

I am trying to make the file. How do I know which GPIO pins to assign to which bus? Earlier in this thread, the following table was linked:

https://elinux.org/RPi_BCM2711_GPIOs

I guess I assign the pins based on the second table? There is a column under GPIOs. I am a bit confused about how to use it. For example, under SDA3, GPIO2 and GPIO4 area listed. Then under SCL3, GPIO3 and GPIO5 are used. For SDA1, it has GPIO2, GPUO44, GPIO46 listed while SCL1, it has GPIO3, GPUI45, GPIO47 listed even though according to:

https://www.raspberrypi.org/documentation/usage/gpio/

GPIO2 is for SDA1 and GPUO3 is for SCL1 by default.

How to read these small lists under the GPIOs column?

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Sun Oct 18, 2020 11:20 pm

Code: Select all

cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
if you run this command as root, you should see what mode every pin is in, then you can look them up in the table to confirm which i2c controller is on those pins

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Mon Oct 19, 2020 12:14 am

cleverca22 wrote:
Sun Oct 18, 2020 11:20 pm

Code: Select all

cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
if you run this command as root, you should see what mode every pin is in, then you can look them up in the table to confirm which i2c controller is on those pins
I copied and pasted but it says that there is "No such file or directory". I guess my problem right now is to figure out which pins to assign to each of the additional five buses.

cleverca22
Posts: 5847
Joined: Sat Aug 18, 2012 2:33 pm

Re: How many I2C buses does Pi 4 has?

Mon Oct 19, 2020 12:45 am

raspberry_user wrote:
Mon Oct 19, 2020 12:14 am
cleverca22 wrote:
Sun Oct 18, 2020 11:20 pm

Code: Select all

cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
if you run this command as root, you should see what mode every pin is in, then you can look them up in the table to confirm which i2c controller is on those pins
I copied and pasted but it says that there is "No such file or directory". I guess my problem right now is to figure out which pins to assign to each of the additional five buses.
did you run it as root? (sudo -i)

raspberry_user
Posts: 217
Joined: Fri Jan 02, 2015 11:34 pm

Re: How many I2C buses does Pi 4 has?

Mon Oct 19, 2020 1:27 am

cleverca22 wrote:
Mon Oct 19, 2020 12:45 am
raspberry_user wrote:
Mon Oct 19, 2020 12:14 am
cleverca22 wrote:
Sun Oct 18, 2020 11:20 pm

Code: Select all

cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
if you run this command as root, you should see what mode every pin is in, then you can look them up in the table to confirm which i2c controller is on those pins
I copied and pasted but it says that there is "No such file or directory". I guess my problem right now is to figure out which pins to assign to each of the additional five buses.
did you run it as root? (sudo -i)
I tried both "sudo" and "sudo -i" but I got the same error.

Return to “General discussion”