Go Down

Topic: Wire lib vs I2C lib - interrupts, performance. (Read 1 time) previous topic - next topic

louarnold

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?

Headroom

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.

louarnold

#2
Feb 27, 2013, 03:44 am Last Edit: Feb 27, 2013, 03:46 am by louarnold Reason: 1

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?

louarnold

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?

snoozerman

#4
Mar 05, 2013, 08:17 pm Last Edit: Mar 06, 2013, 06:58 pm by snoozerman Reason: 1
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!

Go Up