Wire.endTransmission and Timer no function

Hello,

For a project I am trying to read data from a Bosch BNO055 with the I2C connection every 20 ms. For reading data at the correct frequency I am using a timer (I tried MsTimer2, TimerOne, TimerThree, milis() and elapsedMilis). However everytime I call the function Wire.endTransmission for the I2C connection, the program seems to stop.
Does somebody know why this happens? And/or does know a solution to this problem?
Thanks!

Cheers,
Vivian

Does somebody know why this happens?

There is something wrong with your code.

And/or does know a solution to this problem?

Fix your code.

There is nothing wrong with my code, for in this simple code it doesn't work either.
Tell me where I made a mistake in this code.

#include <Wire.h>
#include <MsTimer2.h>

#define BNO055 0x29
#define EUL_DATA_X_LSB 0x1A
void setup() {
Serial.begin(9600);
MsTimer2::set(100,startLoop);
MsTimer2::start();
}

void loop() {
}

void startLoop(){
Wire.beginTransmission(BNO055); // Could also be left out, no difference.
Wire.write(EUL_DATA_X_LSB); // Could also be left out, no difference.
Wire.endTransmission(); // If this line is commentated out, it works fine.
Serial.println("Hello");
}

It looks to me that you might be calling something that requires interrupts to be enabled, inside an ISR.

So yes, there is something wrong with your code.

Also you haven't read the "sticky" about using code tags, so there is also something wrong with the way you posted your code.

Vivian_anoek:
There is nothing wrong with my code, for in this simple code it doesn't work either.

If the error is not in your code, where is it?

It looks to me that you might be calling something that requires interrupts to be enabled, inside an ISR.

Like Serial.print().

Wire.beginTransmission(BNO055);    // Could also be left out, no difference.

Perhaps you ought to pay some attention to what these functions ACTUALLY do. This sets up a buffer to hold some data. Of course not doing that won't cause the ISR problems.

Wire.write(EUL_DATA_X_LSB);         // Could also be left out, no difference.

Put some data in the buffer. Of course not doing that won't cause the ISR problems.

  Wire.endTransmission();                 // If this line is commentated out, it works fine.

Actually communicate with the device, sending the data in the buffer. If you don't do that, and you don't have a problem, then just stop doing it.

If you stop doing it, and you have a problem, then you need to stop pissing and moaning and figure out why the Arduino can't talk to the device!