PDA

View Full Version : I2C communication with BMI088 IMU?



achilles03
- 4th August 2024, 19:42
Has anyone played around with the BMI088 IMU? Or possibly a similar IMU from Bosch? I'm having trouble getting valid data using I2C from it. I've run some code to read the registers from both the accelerometer (address=$18) and the gyro (address=$68), but get back $20 (dec 32) for all registers.

I have it configured for I2C with the following pins:

Pin 5 (CSB2) - NC
Pin 7 (PS) - VDD
Pin 10 (SD02) - GND
Pin 14 (CSB1) - VDD
Pin 15 (SD01) - GND

Section 6.2 of the datasheet (under the "I2C Read Access" heading at the bottom of page 50) along with figure 5 seems to indicate I need to perform an I2C write command to the relevant address to specify the starting register, then perform an I2C read command to the same address without specifying a register to get the data. Is my interpretation of this correct? I have posted Figure 5 for convenience below:
9701

I am using a 18F25k20 and the relevant parts of the code I have used to date is below:

#config
__CONFIG _CONFIG1H, _FOSC_HSPLL_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _HFOFST_ON_3H & _MCLRE_OFF_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
#ENDCONFIG

'serial comm pins
PIN_OUT var PORTb.3
PIN_IN var PORTb.2
'BMI088 I2C pins
MPUCLK var PORTa.4
MPUSDA var PORTa.5

'variables
tmpbyte var byte
'MPU sensor variables
mpu_aadr var byte
mpu_gadr var byte
mpu_areg var byte
mpu_greg var byte

ANSEL = %00000000 ' Configure unused analog inputs for digital I/O
ANSELH = %00000000 ' Configure unused analog inputs for digital I/O

TRISA = %00000011 ' set porta to digital output except push-button pins a.0 and a.1
TRISB = %10000101 ' set portb to digital input or output (b.7=eeprom DQI=input; b.2=serin=input; b.0=ppm in=input)
TRISC = %00000000 ' set portc to digital input or output

'BMI088 constants
GYROREAD con $68
AXCELREAD con $18
ACC_PWR_CNTL con $7D
ACC_PWR_CNF con $7C
STARTAX con $12
STARTGX con $02

'configure accel
mpu_aadr=AXCELREAD
mpu_gadr=GYROREAD
mpu_areg=ACC_PWR_CNTL
I2CWRITE MPUSDA,MPUCLK,mpu_aadr,mpu_areg,[4]
pause 1
mpu_areg=ACC_PWR_CNF
I2CWRITE MPUSDA,MPUCLK,mpu_aadr,mpu_areg,[0]
mpu_areg=STARTAX

serout2 PIN_OUT,6,["MPU REGS",13,10]
for mpu_areg=0 to 126
I2CREAD MPUSDA,MPUCLK,mpu_aadr,mpu_areg,[tmpbyte]
serout2 PIN_OUT,6,[dec mpu_aadr," ",dec mpu_areg," : ",DEC tmpbyte,13,10]
pause 1
next mpu_areg

for mpu_greg=0 to 126
I2CREAD MPUSDA,MPUCLK,mpu_gadr,mpu_greg,[tmpbyte]
serout2 PIN_OUT,6,[dec mpu_gadr," ",dec mpu_greg," : ",DEC tmpbyte,13,10]
pause 1
next mpu_greg

Any help is appreciated!

Thanks!
Dave

Ioannis
- 4th August 2024, 19:47
I think accelerometer is at address $30.

Ioannis

achilles03
- 4th August 2024, 20:46
I think accelerometer is at address $30.

Ioannis

I don't think that's correct. In the picture of figure 5 that I attached in my post, it shows the accelerometer address as "0x18". Also page 61 of the datasheet states:


The default I2C addresses are:
> Accelerometer:
SD01 pin pulled to 'GND': 0011000b (0x018)
SD01 pin pulled to 'VDDIO': 0011001b (0x019)
> Gyroscope:
SD02 pin pulled to 'GND': 1101000b (0x068)
SD02 pin pulled to 'VDDIO': 1101001b (0x069)

Is there a reason you think it is $30?

achilles03
- 4th August 2024, 23:33
Is there a reason you think it is $30?

Ah, yes, you think it should be $30 because I'm an idiot and it should be $30. :-) I always consolidate the R/W bit in the address and forget about it until the next new sensor I try to interface and have to remember it all over again. There's a small chance that one day I'll learn.

Thanks!
Dave

Ioannis
- 5th August 2024, 10:05
You are welcome!
Ioannis