Go Down

Topic: Faster I2C (Read 23457 times) previous topic - next topic

micro571

I'm using MCP23017 I2C IO Expanders.  

They supports:
- 100 kHz
- 400 kHz
- 1.7MHz

I looked in wire.cpp and wire.h and didn't see any obvious place for changing the source to use a higher I2C speed.

Is it possible to use a faster I2C clock speed than 100 kHz on the arduino?

RuggedCircuits

In the Wire subdirectory named 'utility', look at twi.c. At about line 85 you will see code relating to the clock frequency of the TWI.

wayoda

Hi,
the atmega-hardware can do 400 KHz, but you have to tweak the Wire-library in file hardware/libraries/Wire/utility/twi.h.
Near the top of the file you see :
Code: [Select]

#ifndef TWI_FREQ
#define TWI_FREQ 100000L
#endif

If you change that to
Code: [Select]

#ifndef TWI_FREQ
#define TWI_FREQ 400000L
#endif

The I²C bus should run at 400kHz
But you also have to the delete the files
hardware/libraries/Wire/Wire.o
hardware/libraries/Wire/utility/twi.o
because the library must be re-compiled before it uses the new speed.
(This is done automaticaly when you open the Arduino-IDE)

Eberhard

micro571

It worked.  Thanks for the advice.

Tattik

thanks a lot! it worked fine with a max 6956.

KenS

How do slave devices know the speed of the i2c bus?

I have a Duemilanove working perfectly at 100kHz with a Devantech LCD03. I want to add a Nunchuck to the bus. Various postings say that the Nunchuck operates at 400kHz. If I increase the speed in the wire library will the LCD03 and the Nunchuck work together?

wayoda

Hi,
can't find a datasheet for the LCD, but you can't break anything.
If you don't have any serious performance problems there is no need to increase the speed anyway.  The NunChuck is working fine at 100KHz.

Eberhard

KenS

So slave devices such as a Nunchuck automagically operate at the speed of the host? Why do several of the Nunchuck articles say that the speed in TWI.h must be changed?

AWOL

#8
Aug 18, 2009, 04:53 pm Last Edit: Aug 18, 2009, 04:55 pm by AWOL Reason: 1
Quote
How do slave devices know the speed of the i2c bus?

They operate at the speed of SCL, provided by the master.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

KenS

Any idea why articles such as http://www.windmeadow.com/node/42 say "Since the nunchuck uses "Fast" I2C, we will need to change the default speed: #define TWI_FREQ 400000L."? I guess that higher speeds may be slightly more responsive but it seems strange to imply that 400kHz operation is required.

Mike T

Hi KenS,

Quote
Any idea why articles such as http://www.windmeadow.com/node/42 say "Since the nunchuck uses "Fast" I2C, we will need to change the default speed"?


The reason is, that it will not work with the default speed for all devices because you are out of spec. It may work with one specific Nunchuck, but not with all others. My Wireless Nunchuck (from Blazepro) requires 400k TWI speed.

 MikeT



KenS

So SCL determines the speed at which data is sent/received but some devices are not tolerant of a slower than expected clock?

I don't have the funny triangular screwdriver so I can't get the unit apart without risking destruction.  >:( What chip does the Nunchuck use?


Mike T

Hi KenS,

Quote
So SCL determines the speed at which data is sent/received but some devices are not tolerant of a slower than expected clock?

Exactly!

Quote
What chip does the Nunchuck use?

There is not something like "the Nunchuck". Multiple vendors are using different hardware to build their own Nunchuck and all follow the interface definition.

You should always design against the defined interface and not against a specific implementation (e.g. the original Nunchuck from Sony).

When you want to avoid changing the standard library files, you can just set the TWI speed using the following code (copied from my posting at http://www.windmeadow.com/node/42#comment-28
):
Code: [Select]
#define TWI_FREQ_NUNCHUCK 400000L
TWBR = ((CPU_FREQ / TWI_FREQ_NUNCHUCK) - 16) / 2;

Is there any reason, why you want to avoid changing the speed? When there are other TWI devices which need lower TWI speeds you could try to switch the speed before accessing each of the devices.

 MikeT

KenS

Thanks for the additional information! I had missed the suggestion to set the speed without changing the library. Yes, I have several other devices on the i2c bus (LCD/keypad, motor controller) so I didn't want to change the speed and things worked fine without the speed change.

I certainly appreciate the value of working to the standard and would like to if at all possible. Is a description of the Nunchuck standard interface available online?

Mike T

The most comprehensive information about the Wii remote can be found at http://wiibrew.org/wiki/Wiimote and specifically for the Nunchuck under http://wiibrew.org/wiki/Wiimote/Extension_Controllers

 MikeT

Go Up