3

The raspberry pi 3 B has a fixed i2c speed of 100kHz because of productions errors. I assumed that they have fixed it in the new version Raspberry pi 4, but of course there have been newer standards since then too of speed reaching up to the MHz range. Given the previous errors, it would make me doubt what the software is saying that it is running on

Does anyone know what is the maximum speed the pi 4 can handle, it would be better if you have actually scoped the lines yourself. I unfortunately dont have easy access to a scope and am pretty much blind.

tlfong01
  • 4,665
  • 3
  • 10
  • 24
Jack
  • 686
  • 3
  • 7
  • 19
  • 1
    Ah, let me refresh my memory on the Rpi3B+ I2C speed bug: (1) "Raspberry Pi3 I2C baud rate setting": https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=219675. And as the wise old guy Warren Buffett says: "There's never just one cockroach in the kitchen.". I think I better use my US$300 Rigol DS1054 four-channel 50MHz digital storage oscilloscope to make sure. Stay tuned. :) – tlfong01 Mar 02 '20 at 01:40
  • 1
    Just now I have confirmed that the Rpi4B buster I2C can set to 50kHz, 100kHz, 400kHz, and 1MHz. So I have made a quick and dirty answer. Cheers. – tlfong01 Mar 04 '20 at 13:02

4 Answers4

6

Answer

I have confirmed that Rpi4B 4GB v1.2 buster 2020feb13 I2C #1 can set speed other than 100kHz.

Figures

i2c 1


i2c 2


i2c 3


io2c 4


i2c 5


i2c 6


i2c 7


Appendices

Appendix A - /boot/config.txt tlfong01 2020mar04

# /boot/config.txt 2020feb0801  tlfong01  2020feb08hkt1701
# last update 2020feb13hkt2238
# last update 2020mar02hkt1521 
# last update 2020mar04hkt1830

# *** Display ***

disable_overscan=1
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

# *** Audio ***

dtparam=audio=on

# *** UART ***

enable_uart=1

# *** I2C ***

# dtparam=i2c_arm=on,i2c_arm_baudrate=50000
#dtparam=i2c_arm=on,i2c_arm_baudrate=100000
#dtparam=i2c_arm=on,i2c_arm_baudrate=400000
dtparam=i2c_arm=on,i2c_arm_baudrate=1000000

dtoverlay=i2c1,pins_2_3   (board pins  3,  5)
dtoverlay=i2c3,pins_4_5   (board pins  7, 29)
# dtoverlay=i2c4,pins_6_7   (board pins 31, 26)
# dtoverlay=i2c5,pins_12_13 (board pins 32, 33)
# dtoverlay=i2c6,pins_22_23 (board pins 15, 16)

# *** SPI ***

dtparam=spi=on
dtoverlay=spi1-3cs

# *** End of config.txt ***

Appendix B - Python program listing to test I2C Speed Setting

Python program listing to test I2C Speed Setting


tlfong01
  • 4,665
  • 3
  • 10
  • 24
6

As a side note to anyone experimenting with the i2c baudrate, you don't have to set the baudrate via config.txt, which requires a reboot. You can do it at runtime by configuring the kernel module with modprobe:

sudo rmmod i2c_bcm2708
sudo modprobe i2c_bcm2708 baudrate=400000

Also bear in mind that Pi does not support clock stretching on I2C, so I2C devices which rely on this feature will not work at their specified maximum clock rate. Setting the clock frequency to a smaller value usually helps.

Dmitry Grigoryev
  • 27,928
  • 6
  • 53
  • 144
5

The maximum supported speed is 400 Kb/s.

I am not aware of any difference in the I2C implementation between Pi models.

The Broadcom Serial Controller (BSC) controller is a master, fast-mode (400Kb/s) BSC controller. The Broadcom Serial Control bus is a proprietary bus compliant with the Philips® I2C bus/interface version 2.1 January 2000.

See page 28 of BCM2835 ARM Peripherals.

As to whether any particular speed is achievable will depend on the wiring, termination, capacitance etc.

To change the I2C baud rate to 400 kb/s add the following entry to /boot/config.txt

dtparam=i2c_baudrate=400000

I just set 3MHz and the appropriate clock was sent. I don't have any devices which work at that speed so have no idea if it actually would work in practice.

enter image description here

joan
  • 71,024
  • 5
  • 73
  • 106
  • so does the error in the old model fixed in the new one? will it actually run the 400 Kb/s? – Jack Mar 01 '20 at 16:48
  • 1
    I did not know there was an error. Could you add a link to your question? – joan Mar 01 '20 at 16:57
  • i do not have the exact source since it was a year(s) ago that i got a wind of it. but a quick google search led me to this thread. It would seem that @tlfong01 investigated this, hope he sees this to clarify if he was able to successfully probe a 400khz signal on the Rpi3 – Jack Mar 01 '20 at 17:09
  • 1
    That thread was about setting a low baud rate of 40 kbps. – joan Mar 01 '20 at 17:35
  • yes, but he mentioned that Just now I also tried setting 400kHz, but no effect. To summarize, whether I set 40kHz, 50kHz, 100kHz, or 400kHz, Rpi always runs at 100kHz (checked with a scope). So its kinda fixed at 100khz according to his test. Another guy posted that the clock can go upto 1.6Mhz, does that mean 400kHz is not the actual highest? – Jack Mar 01 '20 at 18:00
  • I have edited my answer to show the correct entry to make to /boot/config.txt. – joan Mar 01 '20 at 20:37
  • what device are you probing sir the rpi3 or the rpi4? Well that is good news that it can go beyond 400 kHz, of course it must be design that it will be stable at that speed. – Jack Mar 02 '20 at 09:11
  • I open a random I2C device and try to write a byte. Of course the write fails but you can see the signals on SDA/SCL. pigs i2co 1 0x30 0 then pigs i2cwd 0 23 – joan Mar 02 '20 at 09:25
  • That test was on a Pi4B. – joan Mar 02 '20 at 09:49
  • Thanks for taking the time to probe it @joan. Now i can have the peace of mind that i know atleast i2c high - speed – Jack Mar 02 '20 at 12:13
  • I have a Pi Zero 2 W and currently set dtparam=i2c_arm=on,i2c_arm_baudrate=1700000 and get 23 frames per sec on a OLED display. Setting i2c_arm_baudrate=1600000 yields 22 frames per sec and setting i2c_arm_baudrate=400000 yields 6 frames per sec. I don't have an oscilloscope, but the frame rates are consistent. BCM2835_I2C_CLOCK_DIVIDER_626 corresponds to 399.3610 kHz (at 250 MHz sysclock rate -- which the Pi Zero 2 W runs at 4X that) So there is a bit of interplay between how the system clock is divided to generate the I2C clock. – David C. Rankin Feb 17 '24 at 13:12
5

WIth an RPi 4: Using i2cdetect program to make the lines wiggle.

Using an oscilloscope, if I just enable i2c in the config.txt with no other lines in the file, I see 10usec SCL periods (100kHz).

Adding the i2c_baudrate=400000 to the config.txt file I see 2.5usec SCL periods (400kHz).

Have not done the same experiment with the RPi 3 yet but obviously runs at full speed on the 4. I can post pics if necessary...

Larry Klein
  • 217
  • 1
  • 3