This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52 + BMI160 on I2c

Hi,

I have a peculiar problem problem with BMI160 and nrf52. BMI160 is connected to nrf52 via pins 12 and 13. I am using peripheral/twi_sensor example. After configuring it via I2c I am able to read the chip ID of 0x1d , but the chip does not go to normal mode and the accelerometer value always return zero. Do you see any issues with the below code. Kindly help.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include
#include "boards.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "bmi160.h"
/* TWI instance ID. */
#define TWI_INSTANCE_ID 0
struct bmi160_dev sensor;
struct bmi160_sensor_data accel;
struct bmi160_sensor_data gyro;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi,

    Can you post the definitions of bmi160_set_power_mode() and bmi160_get_regs()?

    Can you provide a logic trace of the TWI-bus communication between the nRF and the sensor?

    I see that in Acc_i2c_Read(), you set the no_stop parameter to false, have you checked that this is correct according to the communication protocol of the sensor, described in the datasheet? Typically, this kind of sensors does not expect a stop between writing the control byte and reading the response, rather a repeated start condition.

    Best regards,
    Jørgen

  • Jorgen, Thank  you for your reply. 

    I could resolve this issue. There was a bug in the code " rslt = nrf_drv_twi_tx(&m_twi, dev_id, reg_data, len + 1, false);" It should be "data" here and not "reg_data". Thankyou for your help