Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMM150 API functions not working, can read/write registers manually, but not through API functions.

    BMM150 API functions not working, can read/write registers manually, but not through API functions.

    Ixck
    Member

    For weeks now, I've been trying to get the API to work, but between the confusing and severlely lacking API and almost non-existant documentation referencing the API in the datasheet, I am totally lost.

    I've gotten to the point where I can read/write the sensor registers without issue through custom I2C read/write functions, but I absolutely cannot read/write through the API functions. They all return `0`, and seem to pass the error checks, however, they still do NOT actually read/write the registers.

    What am I missing here? Even when I run the provided mag_drdy_interrupt.c example, I get `-32,768` from the sensor axes... yet, I can get normal values when I use my own read functions.

    Even when I set a setting through the API functions, it doesn't appear to actually be setting that register to what I'm telling it to. I have no idea what is going on, and am at my wits end trying to troubleshoot Bosch sensors. Any help is greatly appreciated!

     

    #include <stdio.h>
    #include "boards.h"
    #include "app_util_platform.h"
    #include "app_error.h"
    #include "nrf_drv_twi.h"
    #include "nrfx_twi.h"
    #include "nrf_delay.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #include "bmm150.h"
    #include "bmm150_common.h"
    
    /* TWI instance ID. */
    #define TWI_INSTANCE_ID     0
    
    /* TWI instance. */
    static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
    
    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_lm75b_config = {
           .scl                = NRF_GPIO_PIN_MAP(0, 27),
           .sda                = NRF_GPIO_PIN_MAP(0, 26),
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_lm75b_config, NULL, NULL);
        //printf("Error Code init\t%d\n", err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }
    
    //=====================================================
    //                        MAIN
    //=====================================================
    
    int main(void)
    {
        struct bmm150_dev dev;
        struct bmm150_settings mySettings;
        struct bmm150_mag_data mag_data;
    
        int a1, a2, b, c, d, e, f, g, h, i;
    
        dev.intf = BMM150_I2C_INTF;
        dev.read = bmm150_user_i2c_reg_read;
        dev.write = bmm150_user_i2c_reg_write;
        dev.delay_us = 3;
    
        printf("Breaker 1\n");
    
        twi_init();
    
        uint8_t tempValx[8] = {0};
    
        bmm150_get_regs(0x4b, tempValx, 1, &dev);
    
        for(int a = 0; a < sizeof(tempValx); a++){
          printf("getRegs %d\t%d\n", a, tempValx[a]);
        }
        
        printf("Breaker 2\n");
    
        nrf_delay_ms(2500);
    
        a1 = bmm150_interface_selection(&dev);
        printf("rslt A1:\t%d\n", a1);
    
        a2 = bmm150_init(&dev);
        printf("rslt A2:\t%d\n", a2);
        
        mySettings.pwr_mode = BMM150_POWERMODE_NORMAL;
        b = bmm150_set_op_mode(&mySettings, &dev);
        printf("rslt B:\t%d\n", b);
    
        mySettings.preset_mode = BMM150_PRESETMODE_REGULAR;
        c = bmm150_set_presetmode(&mySettings, &dev);
        printf("rslt C:\t%d\n", c);
        
        mySettings.int_settings.drdy_pin_en = 0x01;
        d = bmm150_set_sensor_settings(BMM150_SEL_DRDY_PIN_EN, &mySettings, &dev);
        printf("rslt D:\t%d\n", d);
        
        e = bmm150_get_interrupt_status(&dev);
        printf("rslt E:\t%d\n", e);
    
        printf("Dev->int_status:\t%d\n", dev.int_status);
        printf("BMM150_INT_ASSRTED_DRDY:\t%d\n", BMM150_INT_ASSERTED_DRDY);
    
        //================================
        //    Startup Config Functions
        //================================
        
        printf("Mag X:\t%d\n", mag_data.x);
        printf("Mag Y:\t%d\n", mag_data.y);
        printf("Mag Z:\t%d\n", mag_data.z);
    
        while(true){
    
          uint8_t dsa = bmm150_read_mag_data(&mag_data, &dev);
          printf("bmm150_read_mag_data:\t%d\n", dsa);
    
          printf("Interrupt Status\t%d\n", dev.int_status);
    
          nrf_delay_ms(100);
        }
    
    }

     

     

    1 REPLY 1

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Ixck,

    I setup attached BMM150 example code on STM32 for your reference, it worked well. Please check your host MCU driver code.

    test result.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