Page 1 of 1

i2c speed

Posted: Tue Mar 07, 2017 1:58 pm
by rudiratlos
Hello,
since kernel 4.9,
dmesg | grep bcm2708_i2c
is not working anymore, to determine i2c speed/Baudrate.
Any idea, to get this info?

Re: i2c speed

Posted: Wed Mar 08, 2017 3:30 pm
by 6by9
It's using the upstream i2c_bcm2835 driver.
Look at /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency. It's binary, so use xxd or similar to read it.

Re: i2c speed

Posted: Wed Mar 08, 2017 10:58 pm
by rudiratlos
Thanks for this hint. Is it possible that you post an example, to get via xxd a readable value.

Re: i2c speed

Posted: Thu Mar 09, 2017 12:33 am
by ktb
This is super ugly, but I think it works. I bet somebody will come along and post something better.

Code: Select all

pi@raspberrypi:~ $ var="$(xxd /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency | awk -F': ' '{print $2}')"
pi@raspberrypi:~ $ var=${var//[[:blank:].]/}
pi@raspberrypi:~ $ printf "%d\n" 0x$var
100000

Re: i2c speed

Posted: Sun Mar 19, 2017 3:38 pm
by rudiratlos
is there also a command to get the spi bus speed for newer kernel?

Re: i2c speed

Posted: Sun Mar 19, 2017 3:42 pm
by rudiratlos
is that xxd /sys/class/spidev/spidev0.0/device/of_node/spi-max-frequency ?

Re: i2c speed

Posted: Wed Jul 05, 2017 7:46 am
by golgot
ktb wrote:This is super ugly, but I think it works. I bet somebody will come along and post something better.
Thanks, but this was not working for all speeds

Here is a little less ugly solution :? to determine the current baudrate

Code: Select all

echo 0x$(xxd /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency | cut -f 2,3 -d ' ' --output-delimiter='') | xargs printf "%d\n"
my 2 cents