Hello,
I have a library, which uses some I2C based sensors. That works well on the Arduino UNO but when porting to the DUE the DUE just hangs.
I have reduced that to the bare minimum:
The library consists of those two files:
libTWI.h
#ifndef libTWI_h
#define libTWI_h
#include "Arduino.h"
#include "Wire.h"
class libTWI{
public:
libTWI(void);
// other methods removed
private:
unsigned char buf;
// all other stuff removed
};
#endif
libTWI.cpp:
#include "libTWI.h"
extern int duration; // for debugging issue
// all other things but the standard constructor are removed
libTWI::libTWI(void) {
Wire.begin(); //when disabling that line, the constructor is not longer hanging!
duration = 500;
}
And this is the program:
#include <Wire.h>
#include <libTWI.h>
int led = 13;
int duration = 1000;
// the following line calls the default constructor
libTWI mySensor;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(duration);
digitalWrite(led, LOW);
delay(duration);
}
As you can see, the program is just a standard Blink program, which includes one member of my totally reduced library.
The constructor of libTWI calls Wire.begin() and changes (for debugging only) the value of duration to 500.
If I download that program to the DUE, the DUE just hangs and is not starting the program (no blinking).
When I remove the Wire.begin() from the constructor, the program runs and is blinking with the expected higher frequency!
It looks like, that there is some weird interaction with the Wire library, I can't understand right now.
Any idea? What I am doing wrong? Why that works in the AVR world, but not here?