Bosch Sensortec Community

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

    BMA400 API question

    BMA400 API question

    Kmoore
    Established Member

    Hello I am working the BMA400 accelerometer. I have been using the BMA400 API on Git (https://github.com/BoschSensortec/BMA400-API) as reference point. I have run into an issue regarding the null_ptr_check() function. Below is an example.

    null_ptr_check.PNGI figured this function is suppose to check if any (or some )of "dev"'s parameters are NULL. If it succeeds it will return BMA400_OK. However, when I run this the return is -1 or BMA400_E_NULL_PTR. 

    I guess I did something wrong in the interface setting for the BMA400, but I am not sure. My set_interface function looks like the last picture. I assume that the function pointers for dev->read and dev->write should be replaced with my I2C functions. And the example on Git had dev->delay_ms pointing to a delay function too. I took that out and replaced the calls in the API with _delay_ms from util/delay. I think that's okay though. I am pretty sure the I2C read/write commands work, I just don't know why the null_ptr_check fails.

    set_interface.PNG

    I appriecate any help!

    Ken.

     

    5 REPLIES 5

    BSTRobin
    Community Moderator
    Community Moderator
    Hello Kmoore, Before you code call set_interface() function, have you defined an instance of struct bma400_dev? It is better to define a global instance of struct bma400_dev. example code like this: struct bma400_dev bma400dev; main(void) { int8_t rslt; set_interface(BMA400_SPI_INTF, &bma400dev); print_rslt(rslt); rslt = bma400_init(&bma400dev); print_rslt(rslt); .... }

    Kmoore
    Established Member

    Thanks for replying BSTRobin,

    I have defined the structures for the bma400 like this above main().

    DefinesFifo.PNGI don't know if it cannot be done this way. I assume you can create the instances like this.

    Kmoore
    Established Member

    In main(), the following is used to test the BMA400.

    MainFifo.PNGHowever, it seems to fail at the first startup test, bma400_init(&bma) when checking for null.

    Kmoore
    Established Member

    I think I found it, the delay_ms function pointer must be set in the set_interface call. This solution works, since I use calls to _delay_ms from util for the delays that bma400 structure needs.Fix.PNG

    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