void BMI160_init (void)
{
sensor.id = BMI160_I2C_ADDR; //0x69
sensor.intf = BMI160_I2C_INTF; //0x00
sensor.read = &Acc_i2c_Read;
sensor.write = &Acc_i2c_Write;
sensor.delay_ms = &Acc_delay_ms;
rslt = bmi160_init(&sensor);
APP_ERROR_CHECK(rslt);
if(rslt == BMI160_OK){
NRF_LOG_INFO("BMI160 Initialized...");
} else {
NRF_LOG_INFO("BMI160 not Initialized...");
}NRF_LOG_FLUSH();
sensor.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
sensor.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4;
sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
sensor.gyro_cfg.odr = BMI160_GYRO_ODR_100HZ;
sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS;
sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE;
sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
rslt = bmi160_set_sens_conf(&sensor);
APP_ERROR_CHECK(rslt);
if(rslt == BMI160_OK){
NRF_LOG_INFO("sensor Configured...");
} else {
NRF_LOG_INFO("sensor not Configured...");
}NRF_LOG_FLUSH();
/*BMI160_INT_CHANNEL_1 = BMI160_INT_CHANNEL_1;
senosr
rslt = set_accel_orientation_int(int_config, &sensor);
bmi160_set_int_config(BMI160_ACC_ORIENT_INT,*/
}
void BMI_INT_init (void)
{
/* Select the Interrupt channel/pin */
int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1
/* Select the Interrupt type */
int_config.int_type = BMI160_ACC_ORIENT_INT;// Choosing Any motion interrupt
/* Select the interrupt channel/pin settings */
int_config.int_pin_settg.output_en = 1; /* 0- output disabled ,1- output enabled */
int_config.int_pin_settg.output_mode = 0; /*! 0 - push-pull 1- open drain,only valid if output_en is set 1 */
int_config.int_pin_settg.output_type = 0; /*! 0 - active low , 1 - active high level.
* if output_en is 1,this applies to interrupts,else PMU_trigger */
int_config.int_pin_settg.edge_ctrl = 1; /*! 0 - level trigger , 1 - edge trigger */
int_config.int_pin_settg.input_en = BMI160_DISABLE;// Disabling interrupt pin to act as input
int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE;// non-latched output
/* Select the Any-motion interrupt parameters */
int_config.int_type_cfg.acc_orient_int.orient_mode = 3;// 1- Enable the any-motion, 0- disable any-motion
int_config.int_type_cfg.acc_orient_int.orient_blocking = 3;// Enabling x-axis for any motion interrupt
int_config.int_type_cfg.acc_orient_int.orient_hyst = BMI160_ENABLE;// Enabling y-axis for any motion interrupt
int_config.int_type_cfg.acc_orient_int.orient_theta = BMI160_ENABLE;// Enabling z-axis for any motion interrupt
int_config.int_type_cfg.acc_orient_int.orient_ud_en = 1;// any-motion duration
int_config.int_type_cfg.acc_orient_int.axes_ex = 1;// (2-g range) -> (slope_thr) * 3.91 mg, (4-g range) -> (slope_thr) * 7.81 mg, (8-g range) ->(slope_thr) * 15.63 mg, (16-g range) -> (slope_thr) * 31.25 mg
int_config.int_type_cfg.acc_orient_int.orient_en = 1;// (2-g range) -> (slope_thr) * 3.91 mg, (4-g range) -> (slope_thr) * 7.81 mg, (8-g range) ->(slope_thr) * 15.63 mg, (16-g range) -> (slope_thr) * 31.25 mg
/* Set the Any-motion interrupt */
rslt = bmi160_set_int_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev */
APP_ERROR_CHECK(rslt);
if(rslt == BMI160_OK){
NRF_LOG_INFO("interrupt Initialized...");
} else {
NRF_LOG_INFO("interrupt not Initialized...");
}NRF_LOG_FLUSH();
int_status_sel = BMI160_INT_STATUS_ALL;
bmi160_get_int_status(int_status_sel, &int_status, &sensor);
if(int_status.bit.orient_1_0)
{
printf("success");
}
}
int main(void)
{
bool erase_bonds;
// Initialize.
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
scheduler_init();
gap_params_init();
gatt_init();
advertising_init();
services_init();
sensor_simulator_init();
conn_params_init();
buffer_init();
peer_manager_init();
// Start execution.
NRF_LOG_INFO("HID Keyboard example started.");
timers_start();
advertising_start(erase_bonds);
twi_init();
BMI160_init();
BMI_INT_init();
initDT();
// Enter main loop.
for (;;)
{
//idle_state_handle();
//int_status_sel = BMI160_INT_STATUS_ALL;
//rslt = bmi160_get_int_status(int_status_sel, &int_status, &sensor);
// NRF_LOG_INFO("DataX:%d", int_status.bit.low_g);
read_sensor_data();
//NRF_LOG_FLUSH();
//read_sensor_data();
//idle_state_handle();
//CalibAccel();
/*calcDT();
calcAccelYPR();
calcGyroYPR();
calcFilteredYPR();
NRF_LOG_INFO("DataX:%d,DataY:%d,DataZ:%d", tmp_angle_x,tmp_angle_y,tmp_angle_z);
NRF_LOG_FLUSH();
nrf_delay_ms(100);
*/
}
} i want to use orientation recognize interrupt... but i do not read int_status.bit.orient_1_0. Let me know if there's any error.
... View more