Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Nordic NRF52 with Bosch BMP3

    Nordic NRF52 with Bosch BMP3

    Jimmy123
    New Poster

    Hello,

    I am trying to get sensor readings from the BMP384 on a Nordic NRF52 chip. I am using segger embedded studio, as well as the Bosch libraries (bmp3.c, bmp3.h, bmp3_defs.h). Additionally I have intgreated the COINES common.c, and common.h libraries into the enviroment so I can use Bosch's starter code and examples.

    I am currently trying to run the read_sensor_data example: https://github.com/BoschSensortec/BMP3-Sensor-API/blob/master/examples/read_sensor_data/read_sensor_...

    I am running into an issue where the status.intr.drdy value is never enabled. I have force enabled the value but this only reads static values.

    My code github link is posted here: https://github.com/kbaseba/glider/tree/master

    I am also running into what I think is another issue. In the bmp3.c file, after the data is read through i2c and returns succesfully, the code still enters the communication error if case. This is shown below:

            else
            {
                /* Read the data using I2C */
                dev->intf_rslt = dev->read(reg_addr, reg_data, len, dev->intf_ptr);
            }
    
            /* Check for communication error */
            if (dev->intf_rslt != BMP3_INTF_RET_SUCCESS)
            {
                rslt = BMP3_E_COMM_FAIL;
            }

     My wrapper function for the coines common.c i2c read function is shown below:

    BMP3_INTF_RET_TYPE bmp3_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
        uint8_t dev_addr = *(uint8_t*)intf_ptr; 
        ret_code_t ret_code;
        ret_code = nrf_drv_twi_tx(&m_twi, dev_addr, ®_addr, 1, false);
        if(ret_code != NRF_SUCCESS)
        {
            return ret_code;
        }
    
        ret_code = nrf_drv_twi_rx(&m_twi, dev_addr, reg_data, len);
        if (ret_code == NRF_SUCCESS) 
            return BMP3_INTF_RET_SUCCESS;
        else 
            return 1;
    }

    This consistently returns succesfully with no errors, but somehow the code still enters the communication error case check.

    Any help with this issue would be very appreciated.

    Thank you!

    3 REPLIES 3

    Minhwan
    Community Moderator
    Community Moderator

    Hi Jimmy, 

     

    Could you capture your data using logic analyzer? 

    I think your hardware setting not properly set up yet, but it's difficult to check in code level. 

    Thanks, 

    I'm not very certain on how to do this.

    I have isolated the issue down to the interrupt signals never reading a high value. The data ready interrupt, watermark interrupt (on byte level) and FIFO full interrupt are all stuck at ground and never update. If I set these values to a high value, the sensor will read a temp and pressure value but it will never change.

    I am still using the example code above for reading temp data. Is there any common reason that this could be occuring. The only file I changed from the given driver files was the common.c file to remove the coines platform utilization (it is not compatible with the nrf chip).

    This is my updated bmp3_i2c_read function:

    BMP3_INTF_RET_TYPE bmp3_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
        uint8_t dev_addr = *(uint8_t*)intf_ptr; 
        ret_code_t ret_code;
        ret_code = nrf_drv_twi_tx(&m_twi, dev_addr, ®_addr, 1, false);
        if(ret_code != NRF_SUCCESS)
        {
            return ret_code;
        }
    
        ret_code = nrf_drv_twi_rx(&m_twi, dev_addr, reg_data, len);
        if (ret_code == NRF_SUCCESS) 
            return BMP3_INTF_RET_SUCCESS;
        else 
            return 1;
    }

     and this is my write function:

    BMP3_INTF_RET_TYPE bmp3_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
        uint8_t dev_addr = *(uint8_t*)intf_ptr;
    
        ret_code_t ret_code;
        ret_code = nrf_drv_twi_tx(&m_twi, dev_addr, reg_data, len, false); 
        if (ret_code == NRF_SUCCESS) 
            return BMP3_INTF_RET_SUCCESS;
        else 
            return 1;
    } 

    Additionally, I had to update the bmp3_interface_init function to the following:

    BMP3_INTF_RET_TYPE bmp3_interface_init(struct bmp3_dev *bmp3, uint8_t intf){
    
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_config = {
           .scl                = 27,
           .sda                = 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_config, NULL, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    
        //****************************
    
        int8_t rslt = BMP3_OK;
    
        if(bmp3 != NULL){
    
            /* Bus configuration : I2C */
            if (intf == BMP3_I2C_INTF){
    
             NRF_LOG_INFO("I2C Interface\n");
             dev_addr = BMP3_ADDR_I2C_PRIM;
             bmp3->read = bmp3_i2c_read;
             bmp3->write = bmp3_i2c_write;
             bmp3->intf = BMP3_I2C_INTF;
            }
    
            bmp3->delay_us = bmp3_delay_us;
            bmp3->intf_ptr = &dev_addr;
        }
    
        else{rslt = BMP3_E_NULL_PTR;}
    
        return rslt;
    }

     I am sure that my hardware settup is correct because when I run the same code using an arduino bootloader for the nrf chip0, I am able to get the correct temp reading with no issues, using the same starter code and settup. I am just incapable of puttin the chip into low power/sleep mode using the arduino bootloader.

    Thnak you for your time and help, this has been a very frustrating issue.

    Minhwan
    Community Moderator
    Community Moderator

    Hi Jimmy, 

     

    Sorry for your frustration. 

    Here is the steps how you can check your issue. 

    1) Check Hardware setting - Pull up resistors for I2C could be required. 

    2) Implement I2C code - You already did that.

    3) Check I2C streaming. - That's I asked for you using logic analyzer, but you can read the value with any, also you can share. 

     

    And also, every function in our example code has return value - https://github.com/BoschSensortec/BMP3-Sensor-API/blob/master/examples/read_sensor_data/read_sensor_...

    Could you please check rslt value and let me know where you got something wrong? 

    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