Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    bmi160 orientation use recognize interrupt

    bmi160 orientation use recognize interrupt

    jayden
    New Poster
    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.

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hello jayden,

    Do you read int_status.bit.orient_1_0 in read_sensor_data()?

    bmi160_get_int_status(int_status_sel, &int_status, &sensor);

     is this read interrupt1_0 reading data??

     

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Jayden,

    bmi160_get_int_status() function could read all interrupt status(0x1C~0x1F).

    I setup software on MCU, when I move the board left and right, MCU can receive the interrupt. It read the interrupt status in the interrupt service program and print it out. You can see the change in the value of 0x1f.

    bmi160_get_int_status(BMI160_INT_STATUS_ALL, &int_status, dev);

    BMI160 orientation test.pngBMI160 0X1C-1F registers.png

    int8_t Open_BMI160_ORIENTATION(struct bmi160_dev *dev)
    {
    int8_t rslt = BMI160_OK;

    struct bmi160_int_settg int_config;

    /* 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 = BMI160_ENABLE;// Enabling interrupt pins to act as output pin
    int_config.int_pin_settg.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin
    int_config.int_pin_settg.output_type = BMI160_ENABLE;// Choosing active high output
    int_config.int_pin_settg.edge_ctrl = BMI160_ENABLE;// Choosing edge triggered output
    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 orientation interrupt parameters */
    int_config.int_type_cfg.acc_orient_int.orient_mode = 3;//
    int_config.int_type_cfg.acc_orient_int.orient_blocking = 3;//
    int_config.int_type_cfg.acc_orient_int.orient_hyst = BMI160_ENABLE;//
    int_config.int_type_cfg.acc_orient_int.orient_theta = BMI160_ENABLE;//
    int_config.int_type_cfg.acc_orient_int.orient_ud_en = 1;//
    int_config.int_type_cfg.acc_orient_int.axes_ex = 1;//
    int_config.int_type_cfg.acc_orient_int.orient_en = BMI160_ENABLE;//

    /* Set the Any-motion interrupt */
    rslt = bmi160_set_int_config(&int_config, dev); /* sensor is an instance of the structure bmi160_dev */

    return rslt;
    }

     

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist