Pages: [1] 2   Go Down
Author Topic: Faster I2C  (Read 14261 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#ifndef TWI_FREQ
#define TWI_FREQ 100000L
#endif
If you change that to
Code:
#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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It worked.  Thanks for the advice.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24321
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How do slave devices know the speed of the i2c bus?
They operate at the speed of SCL, provided by the master.
« Last Edit: August 18, 2009, 09:55:27 am by AWOL » Logged

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  >smiley-sad What chip does the Nunchuck use?

Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: