1

I'm relatively new to the I2C protocol and I have to write a c++ library for a particular sensor I have. I'm using a raspberry pi to interface and wiringpi (the i2c component) to handle the low level communications. This is a pretty standard library (read8bits, read16bits, readbuffer, same for write, that support register operations) so all I need to do is the specific, more higher level, sensor operations and export the sensor data to the main project.

But I have a problem, this particular sensor is a 10DOF IMU sensor (https://www.waveshare.com/product/10-DOF-IMU-Sensor-C.htm) - which provides temperature pressure accelerometer magnetormeter and gyroscope information - and I've managed to get the pressure and temperature sensor reporting just fine but the MPU component is just odd... So the sensor registers two I2C addresses, one for the pressure/temperature and one for the accelerometer/magnetometer/gyroscope. Waveshare has a C library which I am using to understand how the sensor works and, for some reason the library is writing to different addresses (different from the registered ones). This particular sensor registers two addresses, 0x77 and 0x68, which I check with i2cdetect but consulting the code it has a particular address for the gyroscope and accelerometer and a separate one for the magnetometer (0xD0, 0x18 again) which should be the same.

So is it normal to do read/writes on addresses other than the registered ones? Would that even work? What am I missing?

Tim
  • 4,790
  • 4
  • 33
  • 41
Kronephon
  • 325
  • 3
  • 12
  • I'm not sure where you got the 0x18 from, looking through the code, the second address (for the barometer) appears to be 0xEE. That said, the 0xD0 appears to be address combined with the R/W bit (consult I2C docs) -- i.e. a read (LSB set to 0) of the 7-bit address 0x68. Same thing with the 0xEE -- read from 0x77. – Dan Mašek Nov 28 '17 at 00:01
  • I got it from the library header files, on the defines for the MPU950.h Oh so you think that it's basically skipping a step by merging two commands into one? – Kronephon Nov 28 '17 at 00:25

1 Answers1

3

The MPU-9255 is actually 2 separate I2C devices, the accelerometer and gyro are accessed on I2C address 0x68 (or 0x69 depending on the logic level of the AD0 pin), the the magnetometer is accessed on I2C address 0x0C.

The accelerometer and gyro I2C address are covered in section 7.2 of the MPU-9255 product specification. The magnetometer I2C address is in section 4.11.

The values that you are seeing in the code (0xD0 and 0x18) are shifted by 1, which leaves room for the I2C read/write bit.

0x68 << 1 = 0xD0
0x0C << 1 = 0x18
Tim
  • 4,790
  • 4
  • 33
  • 41
  • I see, I thought one of the addresses was for the BMP and one for the MPU. I'm only getting 0x68 and 0x77 on the i2cdetect though but I understand the reasoning behind the shift now. Do you think I could bypass this by using the usual write8bits or a read8bits (depending on the r/w bit) functions and use the registered i2c address ? – Kronephon Nov 28 '17 at 00:45
  • I'm sorry to add to the confusion, I've checked this link with popular i2c addresses (https://learn.adafruit.com/i2c-addresses/the-list) and seems like 0x68 is the only one for the MPU and the 0x77 is for the BMP. So I'm a tad confused. – Kronephon Nov 28 '17 at 00:49
  • 1
    The I2C interface to the magnetometer is only enabled when the auxiliary I2C bus on the MPU-9255 is set to pass-through mode, so you won't see 0x0c on i2cdetect unless you configure it. – Tim Nov 28 '17 at 00:49
  • 1
    The list of I2C addresses on adafruit is incomplete. The magnetometer (which is an AK8963 embedded in the MPU-9255) has an I2C address of 0x0c. – Tim Nov 28 '17 at 00:54
  • FYI, see https://stackoverflow.com/questions/44409532/no-data-from-magnetometer-on-mpu9255/44421991#44421991 for how to enable the I2C passthrough mode. – Tim Nov 28 '17 at 00:58