melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 11:46 am

I have a rpi 3 and i was using the matlab support package for rpi but when i tried starting a connection with raspi() an error came up and i traced it back to it failing to read the i2c baud rate. The command they use is
sudo cat /sys/module/i2c_bcm2708/parameters/baudrate

When i run it it comes back as file not found. And checking the appropriate directory the file is not there but i2c works because i have an rtc connected to it. And ideas on why it doesn't exist?
I am using raspbian 2017 03 02 full and kernel 4.9.24

Melvin

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12409
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 11:54 am

I2C doesn't have a "baud rate" like a serial (UART) based communication system, there are however different varieties of I2C that can handle higher clock speeds than 100KHz, depending on the I2C chips used.

see https://en.wikipedia.org/wiki/I2C

Perhaps you can ask at the mathlab community forum.

melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 11:57 am

I was making a reference to the command used by matlab to determine the i2c speed. I referred to it as baudrate because the file is called baudrate. It doesn't work on my pi which is weird. Hence my confusion why would they put it if it wouldn't work? Matlab aside if i run the said command it should work.

Melvin
Last edited by melvonic.demon on Sun Apr 23, 2017 11:59 am, edited 1 time in total.

User avatar
joan
Posts: 14472
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 11:59 am

Perhaps the command used to work on an older version of the kernel.

DirkS
Posts: 10017
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:01 pm

I just checked and the file does exist on my pi3b (contains '0').
Did you activate I2C using raspi-config or the Raspberry Pi configuration utility?

User avatar
joan
Posts: 14472
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:02 pm

Recent Pis probably use i2c_bcm2835 rather than i2c_bcm2708. But i2c_bcm2835 doesn't have that parameter.

melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:04 pm

joan wrote:Perhaps the command used to work on an older version of the kernel.
Perhaps but when i lsmod i see a i2c_bcm2835 which i naturally substituted in place of the bcm2708 part but alas it doesn't work. I tried googling or my problem but nothing helpful was available. In reply to DirkS, i used raspi config to enable it. I tried disabling and enabling it.

Ok so if the newer pi doesn't have that command then how do i query my i2c speed?

User avatar
DougieLawson
Posts: 36549
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:08 pm

melvonic.demon wrote:The command they use is
sudo cat /sys/module/i2c_bcm2708/parameters/baudrate
That's no longer there because the bcm2708 I²C driver got replaced with a bcm2835 version (I think around the time that the device tree came in (June 2015)). So your instructions must date back a long while.

Assume until you've measured it that it's fixed at 100,000 or go and read the code at https://github.com/raspberrypi/linux
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:12 pm

DougieLawson wrote:
melvonic.demon wrote:The command they use is
sudo cat /sys/module/i2c_bcm2708/parameters/baudrate
That's no longer there because the bcm2708 I²C driver got replaced with a bcm2835 version (I think around the time that the device tree came in (June 2015)). So your instructions must date back a long while.

Assume until you've measured it that it's fixed at 100,000 or go and read the code at https://github.com/raspberrypi/linux
You have a point i can assume its 100khz but i would wonder why the folks at mathworks wouldn't know about this. How would i change the speed and verify it by checking some parameters on the system itself instead of actually measuring it? Guess i should report this to mathworks as well

User avatar
DougieLawson
Posts: 36549
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:19 pm

Since you're paying real green $$$$s for your Matlab software you should contact their technical support (it's one of the things your $$$$s pay for).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:27 pm

DougieLawson wrote:Since you're paying real green $$$$s for your Matlab software you should contact their technical support (it's one of the things your $$$$s pay for).
Valid point again, i will be getting in contact with them soon. But back to the pi, how do i set the i2c baud rate or better still query it on the pi 3?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12409
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:33 pm

just from first principles, and what DirkS said, I assume you create a file called baudrate filled with a single ascii character '0' and place it at /sys/module/i2c_bcm2708/parameters/

as far as I understand this the RPI3 doesn't support anything but 100KHz, so querying for the clock speed parameter isn't needed/possible anymore.

melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 12:37 pm

mahjongg wrote:just from first principles, I assume you create a file called baudrate filled with a single ascii character '0' and place it at /sys/module/i2c_bcm2708/parameters/

as far as I understand this the RPI3 doesn't support anything but 100KHz, so querying for the clock speed parameter isn't needed/possible anymore.
I was looking at the dtoverlay and by default its a 100khz so no problem there, can i create that baudrate file and put 100000 instead, just to satisfy matlab? Till they fix it. On my system i can modify what i need but not on others.

User avatar
davidcoton
Posts: 4251
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 5:07 pm

melvonic.demon wrote:can i create that baudrate file and put 100000 instead, just to satisfy matlab?
Who knows? Try it and see. Unlikely to break anything :)
Signature retired

melvonic.demon
Posts: 8
Joined: Sun Apr 23, 2017 11:38 am

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 5:15 pm

davidcoton wrote:
melvonic.demon wrote:can i create that baudrate file and put 100000 instead, just to satisfy matlab?
Who knows? Try it and see. Unlikely to break anything :)
Tried that but normal mkdir with root privies doesn't work guess its because it's a system thing. For now i just modified the annoyances in matlab its working with the pi so that's fixed.

Thanks to everyone one for their help.

Melvin

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

Re: Cannot determine i2c baud rate on rpi 3

Sun Apr 23, 2017 10:04 pm

See these threads:
viewtopic.php?f=66&t=176579
viewtopic.php?f=29&t=167934&start=125

The 4.9.x kernel has both the i2c_bcm2835 and i2c_bcm2708 modules. i2c_bcm2835 is the default.

Changing i2c_arm_baudrate still works with i2c_bcm2835. In /boot/config.txt:

Code: Select all

dtparam=i2c_arm=on,i2c_arm_baudrate=32000
You can get the current value with something like this:

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
32000

amcdonley
Posts: 182
Joined: Mon Jan 26, 2015 5:56 pm
Location: Florida, USA

Re: Cannot determine i2c baud rate on rpi 3

Tue Nov 12, 2019 2:54 pm

ktb wrote:
Sun Apr 23, 2017 10:04 pm

You can get the current value with something like this: ...
Thanks - I put your code into a file i2c_baudrate.sh (then chmod +x i2c_baudrate.sh):

Code: Select all

#!/bin/bash
# Print current maximum i2c rate
var="$(xxd /sys/class/i2c-adapter/i2c-1/of_node/clock-frequency | awk -F': ' '{print $2}')"
var=${var//[[:blank:].\}]/}
printf "I2C Clock Rate: %d Hz\n" 0x$var

Return to “Troubleshooting”