I2C speed setting

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
Sebbi
Posts: 478
Joined: Sun Jul 08, 2012 1:08 am
Location: Germany
Contact:

I2C speed setting

Post by Sebbi »

Hi there,

I hadn't have a lot of time for MultiWii in the last months, but I am beginning to work my way back. While doing this I noticed a few things about the I2C handling, maybe one of the devs can look into it.

There is a define I2C_SPEED in config.h which is set to 100000L (100 kHz) and is used in i2c_init() to set the bus speed. This gets overwritten in the CRIUS_AIO_PRO_V1 section in def.h and is only used in WMP and Nunchuck code sections. All other sensors have the speed hardcoded as 400 kHz with the line "TWBR = ((F_CPU / 400000L) - 16) / 2;" in their readout functions ... except the MPU6050 and MPU3050, those sensors set the speed in their init functions only.

This seems like work being done twice (I know setting the TWBR register might not take up that much time) most of the time, e.g. for everyone who isn't using WMP/Nunchuck sensors. I recommend setting the I2C speed in i2c_init() to 400 kHz and just switch to slow mode and back to 400 kHz again in the WMP/Nunchuck functions if necessary.

Sebbi
Posts: 478
Joined: Sun Jul 08, 2012 1:08 am
Location: Germany
Contact:

Re: I2C speed setting

Post by Sebbi »

No reply? ;-)

Wouldn't it be more efficient to set the I2C bus to 400 kHz by default and just temporarily switch to 100 kHz in the WMP/Nunchuck sensor methods instead of having 100 kHz the default and switching to 400 kHz for every sensor (except the MPUs)?

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: I2C speed setting

Post by Alexinparis »

Sebbi wrote:No reply? ;-)

Wouldn't it be more efficient to set the I2C bus to 400 kHz by default and just temporarily switch to 100 kHz in the WMP/Nunchuck sensor methods instead of having 100 kHz the default and switching to 400 kHz for every sensor (except the MPUs)?


This is a good idea and here is a reply: https://code.google.com/p/multiwii/source/detail?r=1626
I should maybe write more in the forum ;)

Sebbi
Posts: 478
Joined: Sun Jul 08, 2012 1:08 am
Location: Germany
Contact:

Re: I2C speed setting

Post by Sebbi »

Oh ... changed 40 hours ago ;-)

This is why I like Github and its patch submission system ... notifications ;-)

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: I2C speed setting

Post by Mis »

My idea is removing all "TWBR = ((F_CPU / 400000L) - 16) / 2;" in sensors local code.
Then if config.h says 400kHz - all communicacions is done at 400kHz. If some sensors can't work with 400kHz we should slow down ALL communications to 100kHz (via config.h declaration), because during communication with other sensor on 400k the slow device can malfunction, and disturb i2c lines.

Post Reply