12-05-2020 10:06 AM
Hallo
I try to use this programm.When I use SPI, BMI runs normally.But in the process of using IIC, there was a problem. In the setup program, the value of rslt is not equal to the BMI_OK value.This means this connection was not successful.
09:58:59.151 rslt-> -2
09:58:59.151 BMI_OK-> 0
This is my setup program, what went wrong. Thank you very much
void setup() {
/* Variable to define result */
int8_t rslt;
pinMode(BMI270_CS, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
digitalWrite(BMI270_CS, HIGH);
// Wire.setModule(0);
Serial.begin(115200);
i2c_bus = 0x68;
// spi_bus = BMI270_CS;
/* To initialize the hal function */
//SPI.begin();
Wire.begin();
bmi2.intf_ptr = &i2c_bus;
bmi2.intf = BMI2_I2C_INTF;
bmi2.read = bmi2xy_hal_i2c_bus_read;
bmi2.write = bmi2xy_hal_i2c_bus_write;
bmi2.read_write_len = 32;
bmi2.delay_us = bmi2xy_hal_delay_usec;
/* Config file pointer should be assigned to NULL, so that default file address is assigned in bmi270_init */
bmi2.config_file_ptr = NULL;
/* Initialize bmi270 */
rslt = bmi270_init(&bmi2);
Serial.println("bmi270_init done");
rslt = bmi2_accel_gyro_set_config(&bmi2);
Serial.println(rslt);
Serial.println(BMI2_OK);
if (rslt == BMI2_OK)
{
Serial.println("Accel data Ready : X Y Z ");
Serial.println("Gyro data Ready : X Y Z ");
}
delay(250);
// Interrupt PINs configuration
struct bmi2_int_pin_config data_int_cfg;
data_int_cfg.pin_type = BMI2_INT1;
data_int_cfg.int_latch = BMI2_INT_NON_LATCH;
data_int_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE; // Output enabled
data_int_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL; // OpenDrain disabled
data_int_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_LOW; // Signal Low Active
data_int_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE; // Input Disabled
rslt = bmi2_set_int_pin_config( &data_int_cfg, &bmi2);
pinMode(interruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), RawDataHandler, FALLING);
}
12-08-2020 01:35 AM