adafruit / Adafruit_Python_Extended_Bus

Helper Library for Blinka to allow creating I2C and SPI busio objects by passing in the Bus ID
MIT License
33 stars 3 forks source link

frequency kwarg has no effect #11

Closed PaintYourDragon closed 2 years ago

PaintYourDragon commented 2 years ago

Regardless of “frequency” setting, actual I2C frequency is always about 155 KHz. i.e.. these all yield the same throughput:

i2c = I2C(2, frequency=100000)  # Extended bus on 22, 23 "
i2c = I2C(2, frequency=400000)  # Extended bus on 22, 23 "
i2c = I2C(2, frequency=1000000)  # Extended bus on 22, 23 "

Test system is Raspberry Pi 3 B+, configured with two extra I2C buses in /boot/config.txt:

dtoverlay=i2c-gpio,bus=2,i2c_gpio_sda=22,i2c_gpio_scl=23
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=17,i2c_gpio_scl=27

Happens on both buses. Not sure if this belongs here or is an underlying busio issue. Extra peculiar that it’s a somewhat non-standard-ish 155 KHz, not defaulting to an Arduino-like 100 KHz.

makermelissa commented 2 years ago

Good point. It appears to be unused and there's a commented out error message that says it's not settable, so it should probably just be removed. See: https://github.com/adafruit/Adafruit_Blinka/blob/main/src/adafruit_blinka/microcontroller/generic_linux/i2c.py#L18-L31

PaintYourDragon commented 2 years ago

Ah! OK. Fortunately I was able to eke out about an extra 30% by changing /boot/config.txt with:

dtoverlay=i2c-gpio,bus=2,i2c_gpio_sda=22,i2c_gpio_scl=23,i2c_gpio_delay_us=1
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=17,i2c_gpio_scl=27,i2c_gpio_delay_us=1

and that might be just enough for this project. There are different settings in that file for adjusting the “real” I2C interface, and possibly the second (normally used for HAT firmware stuff, if it’s safe to use). Will keep those in my back pocket for now, since it seems like above change + some library changes will do what I need.

PaintYourDragon commented 2 years ago

Thx for checking!