Wire lib vs I2C lib - interrupts, performance.

From my look at the Wire Lib and the I2C lib (DssCircuits.com is for sale | HugeDomains), 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?

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

Headroom:
If you scroll down the page on dsscircuits.com you'll find a pretty detailed timing comparison between the I2C and wire library :wink:
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?

Wire...unless the text at Arduino Playground - 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?

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)

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.

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.