Does anyone know if there exists an arduino I2C library that does not use interrupts? It shouldnt be impossible to create a polling based library.
I've seen this asked a few times, but I doubt a library exists as there really should be no need for one.
Most likely your application could be rewritten to work well without interrupt at all or in combination with a short interrupt routine and I2C handling in the main loop.
If there really was a need to do I2C from an interrupt handler it would be much easier to rewrite the I2C library to use buffered/interrupt driven output than to write a software I2C library.
Most likely your application could be rewritten to work well without interrupt at all or in combination with a short interrupt routine and I2C handling in the main loop.
Yes, but my application will then not function as well as it would when being run by interrupts. I use I2C to retrieve sensor data from gyro/accelerometer sensors. I could definitely put this in the main loop and measure how much time has passed since the last sampling. This is undesireable for two reasons:
Efficiency. If the sampling period is known at compile time, this can be integrated into the integer scaling factors very efficiently. If the sampling period varies between samples, this will have to be done during run-time.
Signal processing. It is much more desireable to have a fixed sampling frequency when designing sensor filters.
A general issue is that if you have other interrupts enabled (e.g. millis, serial or external) - these may delay your interval timer because they execute serially. As such it is typicaly impossible to get microsecond interval accuracy in most applications that use the Arduino core. If on the other hand you only need millisecond or slower accuracy, you can typically achieve this from within a well written main loop and without suffering the overhead of a timer interrupt.
One approach is to time your other code and "schedule" these to run (all within the main loop) so they never conflict with your sensor polling requirement. The overhead of such "scheduling" may still be less than that of your interrupt handler.
You of course knows best what your application needs.
Hmm... You may be right. I do not really need microsecond accuracy. It's probably much easier than rewriting the Wire library
On another note:
How do I change the I2C frequency? Is it enough to define the I2C frequency macro before including the Wire library, or do I need to recompile the Wire library itself (or are libraries recompiled whenever I compile for the device)?