Hello everybody,
That's my first post, if there is any problems, would you excuse me.
So, here is my problem :
I would like to use the IMU BMI160 with an arduino UNO ...
First question : Am i the first ? I didn't find any topic with this configuration in many forum.
First of all, I don't use the Library CurieIMU.h and BMI160.h
My problem is that i try to initialize my BMI160 on my setup() (code below) but it doesn't work. I think my real problem is that the NVM is not enable.
Registers of configuration of the BMI160 (0x1B and 0x03) feed me back that ACC and GYRO are Enable but not the non volatile memory (NVM).
The initialization of the BMI160 was copy in the Library BMI160.h (BMI160.cpp).
you will find below my init process with communication functions. If you want to build it, it works and write you back (0x1B and 0x03).
Is there anybody who had the same problem or did it like me ?
Thanking you in advance,
Waiting to reading you.
// the sensor communicates using SPI, so include the library:
#include <SPI.h>
#include <SD.h>
#include <avr/wdt.h>
//usefull register
const int BMI160_RA_CMD = 0x7E;
const int BMI160_CMD_START_FOC =0x03;
const int BMI160_CMD_ACC_MODE_NORMAL =0x11;
const int BMI160_CMD_GYR_MODE_NORMAL =0x15;
const int BMI160_CMD_MAG_MODE_NORMAL =0x19;
const int BMI160_CMD_STEP_CNT_CLR =0xB2;
const int BMI160_CMD_SOFT_RESET =0xB6;
const int DATA_RATE = 0b00101100; // 160 Hz
const int GYRO_RANGE = 0b00000100; // GYRO_RAGE -> +- 125°/s : 3.8m°/LSB
const int ACC_RANGE = 0b00001111; //+- 2g
const int IF_CONF = 0b00000001; // SPI Enable
const int NV_CONF = 0b00000000; //SPI 4 wire Enable
const int READ = 0b10000000; // MSB READ or WRITE + 7 bit d'adresse
const int WRITE = 0b01111111; // MSB READ or WRITE + 7 bit d'adresse
const int chipSelectSD = 4;
const int chipSelectBMI160 =10;
const int RED_LED = 6;
const int GREEN_LED = 7;
const int YELLOW_LED = 5;
const bool RST_SWITCH = 3;
const int RUN_PIN = 2;
void setup() {
Serial.begin(9600);
// start the SPI library:
SPI.begin();
/*-------- SPI ENABLE BMI160 --------*/
digitalWrite(chipSelectBMI160, LOW);
digitalWrite(chipSelectBMI160, HIGH);
/*-------- BMI 160 INIT -------------*/
digitalWrite(YELLOW_LED,HIGH);
writeRegister (BMI160_RA_CMD, BMI160_CMD_SOFT_RESET); //soft reset to clean register
delay(200);
readRegister(0x7F);
delay(1);
writeRegister (0x70, NV_CONF);
delay(200);
writeRegister (BMI160_RA_CMD, BMI160_CMD_ACC_MODE_NORMAL); //power up acc
delay(600);
writeRegister(BMI160_RA_CMD, BMI160_CMD_GYR_MODE_NORMAL); //power up gyr
delay(600);
writeRegister (0x043,GYRO_RANGE); // GYRO_RAGE -> +- 125°/s : 3.8m°/LSB
delay(200);
writeRegister(0x41, ACC_RANGE); // ACC_RANGE => +- 2g
delay(200);
writeRegister (0x40,DATA_RATE); // ACC_CONF data rate : 1600Hz
delay(200);
writeRegister (0x42, DATA_RATE); // GYRO_CONF data rate : 1600Hz
delay(200);
byte ID = readRegister(0x00);
Serial.print("ID=");
Serial.print(ID);
delay(50);
Serial.print(";\t");
writeRegister (0x6D,0b00001101);
delay(60);
byte self_test = readRegister(0x1B);
Serial.print("selftest=");
Serial.print(self_test);
Serial.print(";\t");
byte stat = readRegister (0x03);
delay(60);
Serial.print("status=");
Serial.print(stat);
Serial.print("\r\n");
}
void loop() {
// put your main code here, to run repeatedly:
}
void writeRegister(byte thisRegister, byte thisValue) {
// now combine the register address and the command into one byte:
byte dataToSend = thisRegister & WRITE; // masque write
// take the chip select low to select the device:
digitalWrite(chipSelectBMI160, LOW);
SPI.transfer(dataToSend); //Send register location
SPI.transfer(thisValue); //Send value to record into register
// take the chip select high to de-select:
digitalWrite(chipSelectBMI160, HIGH);
}
//Read from BMI160
unsigned int readRegister(byte thisRegister) {
//digitalWrite(GREEN_LED, HIGH);
int result = 0; // result to return
//Serial.print("\r\n");
// now combine the address and the command into one byte
byte dataToSend = thisRegister | READ;
digitalWrite(chipSelectBMI160, LOW);
// send the device the register you want to read:
SPI.transfer(dataToSend);
result=SPI.transfer(0x00);
// take the chip select high to de-select:
digitalWrite(chipSelectBMI160, HIGH);
// return the result:
return (result);
}
Datasheet Breakboard BMI160.pdf (514 KB)