Pages: [1]   Go Down
Author Topic: Wire.h and timer interrupts  (Read 805 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am trying to read an ADXL accelerometer via I2C using the Wire library at regular intervals.  A periodic interrupt to fill a global buffer seems like a reasonable solution, but calls to Wire.endTransmission() crashes if called from within an interrupt service routine.  The amount of data I am reading is pretty minimal and the read takes only about 1 millisecond.  I am running the ISR at intervals of about 10 msec, so I think timing is not a problem.

Does anyone have ideas about why the Wire library and ISR might interfere with on another?  Thank you,

Charles
Logged

Landskrona
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Google is your mother's friend
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.
I  have the same problem, want to read from I2C inside an ISR. I found out that Wire use interrupts and inside an ISR interrupts are disabled.
Would be nice to find a solution to this but my knowledge in this subject is not so great  :-/
Logged

Rural Arizona
Offline Offline
Edison Member
*
Karma: 7
Posts: 1711
Incorrigible tinkerer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If your loop() routine is fairly short,  and you don't need really precise intervals between readings,  you could have the ISR set a global variable,  and take a reading in loop() when the flag is set.

Logged

Pages: [1]   Go Up
Jump to: