-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
How many I2C buses does Pi 4 has?
Hi, how many separate I2C buses are there in the Pi4?
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
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
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
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
Thank you. Do you mean these?cleverca22 wrote: ↑Mon Oct 05, 2020 9:01 pmhttps://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
• 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?
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
yepraspberry_user wrote: ↑Mon Oct 05, 2020 9:11 pmThank 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?
you can enable each of them in config.txt, and they will show up as /dev/i2c-* under linux
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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 wrote: ↑Mon Oct 05, 2020 9:19 pmyepraspberry_user wrote: ↑Mon Oct 05, 2020 9:11 pmThank 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?
you can enable each of them in config.txt, and they will show up as /dev/i2c-* under linux
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
they all appear to share a common clock input of (i think) 150mhzraspberry_user wrote: ↑Tue Oct 06, 2020 1:04 amThank 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?
but then each controller has its own clock division register, to set a per-controller speed for the actual data being moved
Re: How many I2C buses does Pi 4 has?
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.
By master they mean the hardware can only act as a bus master, not as a bus slave.
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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)?cleverca22 wrote: ↑Tue Oct 06, 2020 4:29 amthey all appear to share a common clock input of (i think) 150mhzraspberry_user wrote: ↑Tue Oct 06, 2020 1:04 amThank 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?
but then each controller has its own clock division register, to set a per-controller speed for the actual data being moved
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
-
- 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?
Datasheet for the Pi - https://www.raspberrypi.org/documentati ... 11_1p0.pdf
Page 31
(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).
Page 31
8 - 2 = 6 I2C interfaces available for use by user programs.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
(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.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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.6by9 wrote: ↑Tue Oct 06, 2020 10:11 amDatasheet for the Pi - https://www.raspberrypi.org/documentati ... 11_1p0.pdf
Page 318 - 2 = 6 I2C interfaces available for use by user programs.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
(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).
Re: How many I2C buses does Pi 4 has?
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.raspberry_user wrote: ↑Tue Oct 06, 2020 7:32 amIs Pi 4 faster than an I2C Multiplexer + (Arduino or Teensy)?
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
-
- 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?
Sharing of which bus exactly are you fretting over?raspberry_user wrote: ↑Tue Oct 06, 2020 12:58 pmI 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.
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.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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.6by9 wrote: ↑Tue Oct 06, 2020 4:24 pmSharing of which bus exactly are you fretting over?raspberry_user wrote: ↑Tue Oct 06, 2020 12:58 pmI 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.
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.
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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.
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.
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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?
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
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
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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 wrote: ↑Sun Oct 18, 2020 8:46 pmthese 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 rightCode: 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
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
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
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
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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?
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?
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
Code: Select all
cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
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 wrote: ↑Sun Oct 18, 2020 11:20 pmif 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 pinsCode: Select all
cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
-
- Posts: 5847
- Joined: Sat Aug 18, 2012 2:33 pm
Re: How many I2C buses does Pi 4 has?
did you run it as root? (sudo -i)raspberry_user wrote: ↑Mon Oct 19, 2020 12:14 amI 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 wrote: ↑Sun Oct 18, 2020 11:20 pmif 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 pinsCode: Select all
cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins
-
- Posts: 217
- Joined: Fri Jan 02, 2015 11:34 pm
Re: How many I2C buses does Pi 4 has?
I tried both "sudo" and "sudo -i" but I got the same error.cleverca22 wrote: ↑Mon Oct 19, 2020 12:45 amdid you run it as root? (sudo -i)raspberry_user wrote: ↑Mon Oct 19, 2020 12:14 amI 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 wrote: ↑Sun Oct 18, 2020 11:20 pmif 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 pinsCode: Select all
cat /sys/kernel/debug/pinctrl/*.gpio-pinctrl-bcm2835/pins