2020-07-30 02:29 PM
2- Does anyone have experience getting data from BMI160 with ST32 MCU?
Thanks
Saber
2020-07-30 02:53 PM
No, there might be ports, but typically here people use the HAL libraries
STM32Cube_FW_L4_V1.15.1\Projects\NUCLEO-L432KC\Examples\I2C
STM32Cube_FW_L4_V1.15.1\Projects\STM32L476G-EVAL\Examples\I2C\I2C_EEPROM
Should be able to read registers inside BMI160 using pretty generic I2C code.
I2C_HandleTypeDef I2CHandle = {0};
void I2Cx_Init(void) // PB6 I2C1_SCL, PB7 I2C1_SDA
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__I2C1_CLK_ENABLE();
__GPIOB_CLK_ENABLE();
/* I2C SCL/SDA GPIO pin configuration */
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Force the I2C peripheral clock reset */
__HAL_RCC_I2C1_FORCE_RESET();
/* Release the I2C peripheral clock reset */
__HAL_RCC_I2C1_RELEASE_RESET();
if (HAL_I2C_GetState(&I2CHandle) == HAL_I2C_STATE_RESET)
{
I2CHandle.Instance = I2C1;
I2CHandle.Init.Timing = I2C_TIMING;
I2CHandle.Init.OwnAddress1 = 0;
I2CHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2CHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
I2CHandle.Init.OwnAddress2 = 0;
I2CHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
I2CHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
/* Init the I2C */
HAL_I2C_Init(&I2CHandle);
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 0, 1);
HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
HAL_NVIC_SetPriority(I2C1_EV_IRQn, 0, 2);
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
}
else
puts("HAL_I2C_Init not called");
}
...
HAL_StatusTypeDef status = HAL_OK;
uint8_t addr = 0;
uint8_t value;
status = HAL_I2C_Mem_Read(&I2CHandle, SLAVE_I2C_ADDR, addr, I2C_MEMADD_SIZE_8BIT, &value, 1, 100);
2020-07-31 12:00 AM
The wire.h and some other Arduino libraries are already ported for stm32. check stm32duino project for more details.