rudiratlos
Posts: 129
Joined: Tue May 01, 2012 8:47 am

i2c speed

Tue Mar 07, 2017 1:58 pm

Hello,
since kernel 4.9,
dmesg | grep bcm2708_i2c
is not working anymore, to determine i2c speed/Baudrate.
Any idea, to get this info?

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

Re: i2c speed

Wed Mar 08, 2017 3:30 pm

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.
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.

rudiratlos
Posts: 129
Joined: Tue May 01, 2012 8:47 am

Re: i2c speed

Wed Mar 08, 2017 10:58 pm

Thanks for this hint. Is it possible that you post an example, to get via xxd a readable value.

ktb
Posts: 1380
Joined: Fri Dec 26, 2014 7:53 pm

Re: i2c speed

Thu Mar 09, 2017 12:33 am

This is super ugly, but I think it works. I bet somebody will come along and post something better.

Code: Select all

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

rudiratlos
Posts: 129
Joined: Tue May 01, 2012 8:47 am

Re: i2c speed

Sun Mar 19, 2017 3:38 pm

is there also a command to get the spi bus speed for newer kernel?

rudiratlos
Posts: 129
Joined: Tue May 01, 2012 8:47 am

Re: i2c speed

Sun Mar 19, 2017 3:42 pm

is that xxd /sys/class/spidev/spidev0.0/device/of_node/spi-max-frequency ?

golgot
Posts: 1
Joined: Wed Jul 05, 2017 7:41 am

Re: i2c speed

Wed Jul 05, 2017 7:46 am

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

Return to “Raspbian”