I2C issues

Hello
I started to play with I2C communication.
For first testing I wrote the following short program:

void hMain() {

sys.setLogDev(&Serial);
sys.delay(2000);
printf("initializing ...\r\n");
printf("   selectI2C ...\r\n");
hSens1.getI2C().selectI2C();
printf("   setDataRate ...\r\n");
hSens1.getI2C().setDataRate(400000);
for (;;) {
   hLED1.toggle(); // Sign of life
   sys.delay(500);
 }
}

and get the following error message in the serial console:

initializing ...
error: ../../third-party/FreeRTOS/queue.c:1204

Any hints?
My I2C device is a MPU6050 (the MeGyro from Makeblock) connect via the Core2Block adapter.

Michael

Hi Michael.

The problem is you can’t use selectI2C() in this way:

hSens1.getI2C().selectI2C();

It should look like this:

hSens1.selectI2C();

After this change everything should work.

Regards,
Hubert.

Hi Hubert
This part works now, thanks.
But I came to the next problem with the following test program:

void hMain()
{
  sys.setLogDev(&Serial);
  sys.delay(2000);
  printf("initializing ...\r\n");
  hSens1.selectI2C();
  sys.delay(500);
  hSens1.i2c.setDataRate(100000);
  sys.delay(500);
  printf("   read value ...\r\n");
  uint8_t cmd = 0x75;
  uint8_t buffer[1];
  uint8_t r = hSens1.getI2C().rw(0x68, &cmd, 1, buffer, 1);
  printf("receive cmd: %d, data: %d, ret: %d\r\n", cmd, buffer[0], r);

  for (;;)
  {
     hLED1.toggle(); // Sign of life
     sys.delay(500);
  }
}

the result is:

initializing ...
   read value ...
I2C_TIMEOUT
receive cmd: 117, data: 84, ret: 0

Again my I2C device is a MPU6050 (the MeGyro from Makeblock) connect via the Core2Block adapter.
Testing with another I2C device (MeCompass) I got an I2C_NACK message and the values of the buffer are not changed by the read function.
I checked the wiring with a multimeter and that seems to be ok, soldering was done as described here.

Any suggestions / ideas?

Hi, we just added an example to the Web IDE (for CORE2): “Arduino MPU9250 example”. This example presents not only working I2C but also an Arduino compatibility layer for hFramework.

In this example we use MPU9250 - a very similar sensor to yours, working on Arduino library.

Where can I get this example in the Web IDE?

It’s here:

cloud.husarion.com → IDE → new project → CORE2 → select template “Arduino MPU9250 example”