Pages: [1]   Go Down
Author Topic: Wire lib vs I2C lib - interrupts, performance.  (Read 1091 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From my look at the Wire Lib and the I2C lib (http://dsscircuits.com/articles/arduino-i2c-master-library.html), its apparent that the Wire Lib uses interrupts whereas the I2C lib polls and essentially blocks activity until the function has completed.

I understand the advantage of interrupts in general, but what are the differences in performance between I2C and the Wire lib?
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 277
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you scroll down the page on dsscircuits.com you'll find a pretty detailed timing comparison between the I2C and wire library ;-)
That should explain any performance differences.
Logged


Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you scroll down the page on dsscircuits.com you'll find a pretty detailed timing comparison between the I2C and wire library ;-)
That should explain any performance differences.
It does - in favor of the Wire lib. Compare bytes/us or us/byte. You'll see the Wire library is faster (more bytes/us or less us/byte) in all three cases. However, the text says the results are out of date. Note that the interrupt code may not have been removed in that version of the library.

However, micro-controllers are about real-time events and polling tends to block the real-time system. Or does it?
« Last Edit: February 26, 2013, 09:46:37 pm by louarnold » Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wire...unless the text at http://playground.arduino.cc/Main/WireLibraryDetailedReference, section "The Wire Library" is out of date, the Wire library uses blocked I/O and not interrupts:

"The Wire library's I/O blocks. This means that when sending or receiving over the I2C bus, your application is prevented from running until the communication is complete. In truth the operation of the TWI hardware in your processor is interrupt-driven, so your application should be free to run at full speed while the TWI communication takes place, but this capability is not utilized by the Wire library. "

Have I misunderstood something?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I had a look at the two some time ago and went for the I2C library. The compile size of I2C was the main reason for me. I also did some basic speed tests (reading only) with I2C beeing the better. However, I tweaked the I2C code somewhat and managed to increase the speed a bit more. Unfortunately I don't have the test results left so I take it from the back of my head.

I attach the tweaked files if you would like to test for yourself. NO guarantees given they work - code is not thoroughly verified but they work for me. I have used them with Ardunio mini and Arduino Duemillanove boards and IDE ver 1.0.1 on Windows 7.

I2C can also be set to work with 400 Hz bus. I don't think you can do that with Wire - can you? Not sure.


Cheers!

* I2C.zip (6.43 KB - downloaded 13 times.)
« Last Edit: March 06, 2013, 12:58:17 pm by snoozerman » Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 277
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The I2c library is faster than the wire library. The values presented in the table are code-size in bytes and duration of whatever write read function. The calculation you did assumes that the first number given is the number of bytes transferred per time, which, again , is not what the numbers represent.
The I2C signals are realized in hardware, thus the likelyhood that your application will have to wait because of the " blocking" behavior is very small. Removing dependence on interrupts makes this library more flexible to use as it eliminates its chance of interfering with other libraries that may also want to use the same interrupts.

The reason this library worked better for me was because of the timeout and reset, a function the wire library does it offer, or at least did not when I write the software for my prject.
« Last Edit: March 05, 2013, 09:48:25 pm by Headroom » Logged


Offline Offline
Full Member
***
Karma: 1
Posts: 129
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To snoozerman and Headroom:
Thanks for sharing your experience and my apologies for my hasty review of the I2C stats.

I'll take the modified file and see what its like.

Regards.
« Last Edit: March 08, 2013, 12:45:43 pm by louarnold » Logged

Pages: [1]   Go Up
Jump to: