Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMA423 Step Counter and Any Motion with interrupt Features

    BMA423 Step Counter and Any Motion with interrupt Features

    vojjta96
    Member

    Hello,

    I am currently trying to enable Step-counter and Any-motion feature on BMA423.

    Application note is saying that for enabling:
    Step-counter I need to just set FEATURE_IN.step_counter.settings_26.en_counter - done by bma423_feature_enable(BMA423_STEP_CNTR, BMA4_ENABLE, &bma423).

    Any-motion I need to set one of the axes in FEATURE_IN.any_motion.settings_2.x_en/y_en/z_en - done by bma423_anymotion_enable_axis(BMA423_Z_AXIS_EN, &bma423).

    Tried that and neither works.

    My main questions are:

    1. What is correct sequence of BMA423 driver commands for initialization?
      1. Is it just:
        rslt |= bma423_init(&bma423);
        rslt |= bma423_write_config_file(&bma423);
    2. What is correct sequence of BMA423 driver commands for enabling Step-counter feature?
      1. Is it just:
        rslt |= bma423_feature_enable(BMA423_STEP_CNTR, BMA4_ENABLE, &bma423);
    3. What is correct sequence of BMA423 driver commands for enabling Any-motion feature?
      1. Is it just:
        bma423_anymotion_enable_axis(BMA423_Z_AXIS_EN, &bma423);
        OR
        bma423_feature_enable(BMA423_ANY_MOTION, BMA4_ENABLE, &bma423);
        BOTH?
    4. What is correct sequence of BMA423 driver commands for enabling and setting up Interrupt triggered by Any-motion feature?
      1. For enabling:
        bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ANY_NO_MOTION_INT, BMA4_ENABLE, &bma423);
      2. For setting up Intterupt:
        int_config.edge_ctrl = BMA4_LEVEL_TRIGGER;
        int_config.lvl = BMA4_ACTIVE_HIGH;
        int_config.od = BMA4_PUSH_PULL;
        int_config.output_en = BMA4_OUTPUT_ENABLE;
        int_config.input_en = BMA4_INPUT_DISABLE;
        bma4_set_int_pin_config(&int_config, BMA4_INTR1_MAP, &bma423);
    5. How should I set int pin when I need it to be High while no interrupt is triggered and for Low when it is triggered? Correcponding pin in MCU is set to Input, internal Pullup, Interrupt Negative Edge.

    I've tried different combinations of code sequences, but none works.
    Code below prints BMA4_OK, so no errors occurred during writing into registers.

    Can anyone see what I am doing wrong? Please point me in the right direction. I will be glad for any advice or help.
    Thank you very much.

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------

    #include "bma423.h"
    struct bma4_dev bma423;

    void BMA423_initialization()
    {
    uint16_t rslt = BMA4_OK;
    struct bma4_int_pin_config int_config;
    struct bma423_anymotion_config anymotion_conf;

    bma423.interface = BMA4_SPI_INTERFACE;
    bma423.bus_read = BMA423_reg_read;
    bma423.bus_write = BMA423_reg_write;
    bma423.delay = delay_ms;
    bma423.read_write_len = 64;

    rslt |= bma423_init(&bma423);

    rslt |= bma423_write_config_file(&bma423);

    // Tried if enabling and setting the accel would help. Didnt
    // rslt |= bma4_set_accel_enable(BMA4_ENABLE, &bma423);
    // /* Declare an accelerometer configuration structure */
    // struct bma4_accel_config accel_conf;
    //
    // /* Assign the desired settings */
    // accel_conf.odr = BMA4_OUTPUT_DATA_RATE_1600HZ;
    // accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;
    // accel_conf.range = BMA4_ACCEL_RANGE_4G;
    // accel_conf.perf_mode = BMA4_CONTINUOUS_MODE;
    //
    // /* Set the configuration */
    // rslt |= bma4_set_accel_config(&accel_conf, &bma423);

    rslt |= bma423_select_platform(BMA423_WRIST_CONFIG, &bma423);


    rslt |= bma423_map_interrupt(BMA4_INTR1_MAP, BMA423_ANY_NO_MOTION_INT, BMA4_ENABLE, &bma423);

    /* Configure INT1 pin */
    int_config.edge_ctrl = BMA4_LEVEL_TRIGGER;
    int_config.lvl = BMA4_ACTIVE_HIGH;
    int_config.od = BMA4_PUSH_PULL;
    int_config.output_en = BMA4_OUTPUT_ENABLE;
    int_config.input_en = BMA4_INPUT_DISABLE;
    rslt |= bma4_set_int_pin_config(&int_config, BMA4_INTR1_MAP, &bma423);

    anymotion_conf.threshold = 0xAA; // 0xAA(170) 83mg; 0xCC(204) 100mg
    anymotion_conf.duration = 1; // X*20ms

    rslt |= bma423_set_any_motion_config(&anymotion_conf, &bma423);

    rslt |= bma423_anymotion_enable_axis(BMA423_Z_AXIS_EN, &bma423);

    rslt |= bma423_feature_enable(BMA423_ANY_MOTION, BMA4_ENABLE, &bma423);


    rslt |= bma423_reset_step_counter(&bma423);

    rslt |= bma423_step_detector_enable(BMA4_ENABLE, &bma423);

    rslt |= bma423_feature_enable(BMA423_STEP_CNTR, BMA4_ENABLE, &bma423);


    print_rslt(rslt, line_offset);
    line_offset++;

    if(rslt != BMA4_OK) {
    while(1);
    }
    }

    For gettings Step-counter values I use:

    uint32_t step_count = 0;
    bma423_step_counter_output(&step_count, &bma423);
    Display_print1(dispHandle, line_offset, 0, "Step count: %ld", (uint16_t)step_count);

     

    4 REPLIES 4

    Vincent
    Community Moderator
    Community Moderator

    You steps in item 1 - 4 are both correct. 

    For item 5, you need to select int_config.lvl = BMA4_ACTIVE_LOW,  then the pin will keep high when interrupt is not generated.

    Your code looks good, just one thing missing:  after power on,  sensor is in sleep mode.  you need change the power mode of sensor to normal mode first.

    If sensor is not working, no data sample generated, then there obviously no interrupt generated. 

    Thank you for your response.

    I am not sure what do you mean by Normal power mode, but I changed power mode to Performance mode with:
    ACC_CONF.acc_perf_mode = 0b1    (accel_conf.perf_mode = BMA4_CONTINUOUS_MODE;)
    PWR_CTRL.acc_en = 0b1    (bma4_set_accel_enable(BMA4_ENABLE, &bma423);)
    This however did not help - I still can not get any Interrupt when I shake with the sensor (checking witch osciloscope and by reading int_status register) and I can not get step_count different from zero.

    1. When I enable any_motion on all axes, does it mean that the threshold has to be exceeded on all of the axes or it has to be exceeded on one of the three axes? (X || Y || Z) or (X && Y && Z)
    2. Can I leave out command bma423_select_platform(BMA423_WRIST_CONFIG, &bma423)? Wrist_config is deafult anyway, right? For some reason is this command causing sudden stop of program execution after approx 1 sec from start.
    3. Do I need to enable step_detector for step_counter to work properly?

    Would you check my modified code below for any other mistake, please? Thank you again for helping me.

    SELF REPLY

    1.  It has to  exceed the threshold on one of the three axes - X || Y || Z.
    2. bma423_select_platform(BMA423_WRIST_CONFIG, &bma423) can be left out - Wrist_config is deafult.
    3. There is no need to enable step_detector for step_counter to work properly.

    Thanks again Vincent for pointing out, that I did not set power mode. It was the main issue. 

    Code below enables step-counting and any-motion functions properly. For testing step_counter you can just wave with the sensor back and forth for at least 10 times.

    bma423.c   rev 1.1.4
    bma4.c        rev 2.1.9

    Vincent
    Community Moderator
    Community Moderator

    Did you download the configure string of BMA423 during initialization? 

    without this step, the interrupt is not suppose to work

    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