Go Down

Topic: mstimer2 + I2C bug ? (Read 2315 times) previous topic - next topic



I am trying to use the library msTimer but I think there is a bug when usinf the "Wire.endTransmission" function of the wire.h library.

Wire.endTransmission freezes my application when it is used in an interrupt function.

I am using an Arduino Duemilanove / ATmega328

Best regards,


---------- here is my debug pg -----------

#include <Wire.h>
#include <MsTimer2.h>
int ID_pcf=0;
int Id_an=0;
int Id_in=0;
int tmps=0;

int mesure[8];  // tab des dernieres mesures
int id_an=0;    // num entrée ana à lire

void setup()
 Serial.println("Start Calibration");
 MsTimer2::set(400, myinterupt); // 500ms period
void loop() {
 Serial.print("\t id an= ");
 Serial.print(" \tmesure= ");

void myinterupt(){
 MsTimer2::stop() ;
 if  (id_an<4) ID_pcf= B1001001;
   else ID_pcf=B1001011;

 int Id_in=id_an%4;
 // Wire.endTransmission();
 //Wire.requestFrom(ID_pcf, 8);
 // mesure[id_an]=tmps;

if  (id_an==7) { id_an= 0;tmps++;}
   else {id_an ++;tmps++;}


In order for I2C to work, interrupts must be enabled. Interrupts are  enabled by default, but not so within your timer interrupt code. This may not be what you wanted to hear, but nevertheless this is by definition how interrupt handlers are designed on most (if not all) platforms.

The nature of your application suggests that you do not need interrupts at all. Rather you may consider the following:

Code: [Select]

void loop() {
 static word time_last = 0;

 if ((int)((word)millis()-time_last)>=500) {
   // code that needs to execute every 500 millisecond goes here

Go Up