UC GEE
UC GEE
DIIDevHeads IoT Integration Server
Created by UC GEE on 7/2/2024 in #middleware-and-os
Trying to interface the BMI088 IMU with an i2c multiplexer
@Middleware & OS I’m trying to interface the BMI088 IMU with an i2c multiplexer. The BMI088 has two different addresses for the accelerometer and gyroscope which makes it act like 2 different devices entirely. I have the mux on bus0 in my devicetree and I can address it just fine. I put the IMU on channel 2 of the mux and I have read that each channel on the mux is essentially a bus extension. I cannot find any specific information/examples on how to set up the individual BMI088 acc and gyro addresses on the mux channel in my device tree. Please, I'm making use of STM32 MCU. Could anyone reference any documentation or examples? Here's my i2c bus initializing code
/* Enable the I2C peripheral clock */
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
/* Configure the I2C pins */
GPIOB->MODER |= (GPIO_MODER_MODER6_1 | GPIO_MODER_MODER7_1); // Set PB6 and PB7 as alternate function
GPIOB->OTYPER |= (GPIO_OTYPER_OT_6 | GPIO_OTYPER_OT_7); // Set PB6 and PB7 as open-drain
GPIOB->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR6 | GPIO_OSPEEDER_OSPEEDR7); // Set high speed for PB6 and PB7
/* Configure the I2C peripheral */
I2C1->CR1 &= ~I2C_CR1_PE; // Disable the I2C peripheral
I2C1->CR1 |= I2C_CR1_SWRST; // Software reset the I2C peripheral
I2C1->CR1 &= ~I2C_CR1_SWRST; // Clear the software reset bit
I2C1->CR2 = (uint32_t)400000; // Set the I2C clock frequency to 400 kHz
I2C1->CCR = (uint32_t)((SystemCoreClock + (I2C_SPEED * 2)) / (I2C_SPEED * 4)); // Set the I2C clock control register
I2C1->TRISE = (uint32_t)((SystemCoreClock / 1000000) + 1); // Set the maximum rise time
I2C1->OAR1 = (uint16_t)(0x5A << 1); // Set the I2C slave address to 0x5A (7-bit address)
I2C1->OAR1 |= I2C_OAR1_ADD0; // Set the address mode to 7-bit
I2C1->CR1 |= I2C_CR1_PE; // Enable the I2C peripheral
/* Enable the I2C peripheral clock */
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
/* Configure the I2C pins */
GPIOB->MODER |= (GPIO_MODER_MODER6_1 | GPIO_MODER_MODER7_1); // Set PB6 and PB7 as alternate function
GPIOB->OTYPER |= (GPIO_OTYPER_OT_6 | GPIO_OTYPER_OT_7); // Set PB6 and PB7 as open-drain
GPIOB->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR6 | GPIO_OSPEEDER_OSPEEDR7); // Set high speed for PB6 and PB7
/* Configure the I2C peripheral */
I2C1->CR1 &= ~I2C_CR1_PE; // Disable the I2C peripheral
I2C1->CR1 |= I2C_CR1_SWRST; // Software reset the I2C peripheral
I2C1->CR1 &= ~I2C_CR1_SWRST; // Clear the software reset bit
I2C1->CR2 = (uint32_t)400000; // Set the I2C clock frequency to 400 kHz
I2C1->CCR = (uint32_t)((SystemCoreClock + (I2C_SPEED * 2)) / (I2C_SPEED * 4)); // Set the I2C clock control register
I2C1->TRISE = (uint32_t)((SystemCoreClock / 1000000) + 1); // Set the maximum rise time
I2C1->OAR1 = (uint16_t)(0x5A << 1); // Set the I2C slave address to 0x5A (7-bit address)
I2C1->OAR1 |= I2C_OAR1_ADD0; // Set the address mode to 7-bit
I2C1->CR1 |= I2C_CR1_PE; // Enable the I2C peripheral
9 replies