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 :
#ifndef TWI_FREQ
#define TWI_FREQ 100000L
#endif
If you change that to
#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)
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?
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.
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?
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.
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.
So SCL determines the speed at which data is sent/received but some devices are not tolerant of a slower than expected clock?
Exactly!
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
):
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.
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?