0
Offline
Newbie
Karma: 0
Posts: 4
Arduino rocks
|
 |
« on: May 06, 2009, 10:57:24 pm » |
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
Faraday Member
Karma: 12
Posts: 2857
ruggedcircuits.com
|
 |
« Reply #1 on: May 06, 2009, 11:43:09 pm » |
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
God Member
Karma: 0
Posts: 869
|
 |
« Reply #2 on: May 07, 2009, 02:12:28 am » |
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) Eberhard
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 4
Arduino rocks
|
 |
« Reply #3 on: May 07, 2009, 08:14:30 am » |
It worked. Thanks for the advice.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 16
Arduino rocks
|
 |
« Reply #4 on: August 08, 2009, 05:05:50 am » |
thanks a lot! it worked fine with a max 6956.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 26
Arduino rocks
|
 |
« Reply #5 on: August 18, 2009, 09:09:05 am » |
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
God Member
Karma: 0
Posts: 869
|
 |
« Reply #6 on: August 18, 2009, 09:23:38 am » |
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
Newbie
Karma: 0
Posts: 26
Arduino rocks
|
 |
« Reply #7 on: August 18, 2009, 09:49:04 am » |
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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #8 on: August 18, 2009, 09:53:22 am » |
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.
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 26
Arduino rocks
|
 |
« Reply #9 on: August 18, 2009, 11:50:26 am » |
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
Full Member
Karma: 0
Posts: 167
Arduino rocks
|
 |
« Reply #10 on: September 04, 2009, 12:13:04 pm » |
Hi KenS, 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
Newbie
Karma: 0
Posts: 26
Arduino rocks
|
 |
« Reply #11 on: September 04, 2009, 12:55:25 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Full Member
Karma: 0
Posts: 167
Arduino rocks
|
 |
« Reply #12 on: September 06, 2009, 04:38:00 am » |
Hi KenS, 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): #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
Newbie
Karma: 0
Posts: 26
Arduino rocks
|
 |
« Reply #13 on: September 06, 2009, 08:09:17 am » |
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
|
|
|
|
|
|
|
|