Bosch Sensortec Community

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

    I'm trying to interface an nRF52832 to the BMA456 and load a config file

    I'm trying to interface an nRF52832 to the BMA456 and load a config file

    Jar444
    Member

    Hello everyone,

    I am attemping to interface an nRF52832 to the BMA456 and load a step counter/tracker. Has anyone already done this and if not does anyone have any ideas of how to get started? 

    27 REPLIES 27

    Screenshot 2023-05-23 171117.png

    now it has loaded 3 times correctly!

    The problem is it is taking a very long time to load and then check if it was loaded correctly 3-5 mins any idea on why that could be? 

    I fixed the timing issue!!!

    I am using the Grove - Step Counter Grove - Step Counter(BMA456) | Seeed Studio Wiki

    I am attempting to just output every step for testing so I can see the interface working. I have used the API from Bosch and have gotten the config file loaded sucessfully. I have enabled the step counter but when I read the register it is always 0. Any suggestions? Thank you in advance for any help.

    Here is my code:

    /**\
     * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
     *
     * SPDX-License-Identifier: BSD-3-Clause
     **/

    #include <stdio.h>
    #include "bma456h.h"
    #include "common.h"

    /******************************************************************************/
    /*!            Function                                                       */

    /* This function starts the execution of program. */
    int main(void)
    {
        /* Variable to store the status of API */
        int8_t rslt;

        /* Sensor initialization configuration */
        struct bma4_dev bma = { 0 };

        /* Variable to store step counter interrupt status */
        uint16_t int_status = 0;

        /* Variable to store step counter output */
        uint32_t step_out = 0;

        /* Interface reference is given as a parameter
         *         For I2C : BMA4_I2C_INTF
         *         For SPI : BMA4_SPI_INTF
         * Variant information given as parameter - BMA45X_VARIANT
         */
        printf("\nStart new step counter example\n");
        rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
        bma4_error_codes_print_result("bma4_interface_init", rslt);
        printf("bma4_interface_init status %d\n", rslt);

        /* Sensor initialization */
        rslt = bma456h_init(&bma);
        bma4_error_codes_print_result("bma456h_init status", rslt);
        printf("bma456h_init status %d\n", rslt);

        /* Upload the configuration file to enable the features of the sensor. */
        rslt = bma456h_write_config_file(&bma);
        bma4_error_codes_print_result("bma456h_write_config status", rslt);
        printf("bma456h_write_config status %d\n", rslt);

        /* Enable the accelerometer */
        rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
        bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);
        printf("bma4_set_accel_enable status %d\n", rslt);

        if (rslt == BMA4_OK)
        {
            /* Map the interrupt pin 1 for step counter */
            rslt = bma456h_map_interrupt(BMA4_INTR1_MAP, BMA456H_STEP_CNTR_INT, BMA4_ENABLE, &bma);
            bma4_error_codes_print_result("bma456h_map_interrupt status", rslt);
            printf("bma456h_map_interrupt status %d\n", rslt);
            if (rslt == BMA4_OK)
            {
                /* Setting watermark level 1, the output step resolution is 20 steps.
                 * Eg: 1 means, 1 * 20 = 20. Every 20 steps once output triggers
                 */
                // rslt = bma456h_step_counter_set_watermark(0, &bma);
                // bma4_error_codes_print_result("bma456h_step_counter_set_watermark status", rslt);
                // printf("set watermark status %d\n", rslt);
                if (rslt == BMA4_OK)
                {
                    /* Enabling step counter feature */
                    rslt = bma456h_feature_enable(BMA456H_STEP_COUNTER_EN, BMA4_ENABLE, &bma);
                    bma4_error_codes_print_result("bma456h_feature_enable status: step counter enabled", rslt);
                    printf("bma456h_feature_enable status %d\n", rslt);
                    rslt = bma456h_feature_enable(BMA456H_STEP_DETECTOR_EN, BMA4_ENABLE, &bma);
                    bma4_error_codes_print_result("bma456h_feature_enable status: step detector enabled", rslt);
                    printf("bma456h_feature_enable status %d\n", rslt);
                }
            }
           
            if (rslt == BMA4_OK)
            {
                printf("Step counter feature is enabled\n");

                //printf("Step counter watermark level is 1 (Output resolution is 20 steps)\n");

                printf("Move the board in steps to perform step counter\n");

                for (;;)
                {
                    /* Read interrupt status */
                    // rslt = bma456h_read_int_status(&int_status, &bma);
                    // bma4_error_codes_print_result("bma456h_read_int_status", rslt);
                   
                    // //printf("bma456h_read_int_status status %d\n", rslt);    
                    // /* Enters only if the obtained interrupt is step counter */
                    // if ((rslt == BMA4_OK) && (int_status & BMA456H_STEP_CNTR_INT))
                    // {
                        //printf("Step counter interrupt received when watermark level is reached (20 steps)\n");
                   
                        rslt = bma456h_step_counter_output(&step_out, &bma);
                        if (rslt == BMA4_OK && step_out > 0){
                            printf("The step counter output is %lu\n", (long unsigned int)step_out);
                            //break;
                        }
                       bma.delay_us(1000000, bma.intf_ptr);
                //    }

                   //int_status = 0;
                }
            }
        }  

        return rslt;
    }

    Here are three separate files of the i2c, The arduino-grove file works as a step tracker. The nrf52ard_grove is me changing the arduino code to work with the nrf52832 (the step counter nexer accumulates). The third is using the newest API from the Bosch git repository and adaping  it to work with the nrf52832 (never triggers an intterupt). Any help would be very appreaciated.

    Minhwan
    Community Moderator
    Community Moderator

    Hi Jar444, 

     

    Why you commented out some functions? 

    Would you enable all functions and run it again? 

    Then, can you read interrupt properly? For your testing, at least you have to walk 20 steps. (You can check it to swing your arm with app3.0)

    Also, could you just every return value (rslt) when you call functions? Any error returned? 

    Thank you. 

    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