Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Error while interfacing bme680 sensor with my fpga board.

    Error while interfacing bme680 sensor with my fpga board.

    adityaseelam
    New Poster

    Ive inserted the bosch sesortec github library to my project which is https://github.com/boschsensortec/BME68x-Sensor-API/blob/master/bme68x.c#L234 but when Im running the program Iam not able to get the output. Im observing these two erros in my terminal window.

    I2C Interface
    API name [bme68x_init] Error [-3] : Device not found
    API name [bme68x_get_data] Warning [2] : No new data found

    The github files which ive included in my program are bme68x.h,bme68x.c and bme68x_defs.h.

    Actually Ive digged up further and tried to find out the error so Ive made few changes in the bme68x.c file. 

    int8_t bme68x_init(struct bme68x_dev *dev)
    {
    int8_t rslt;

    rslt = bme68x_soft_reset(dev);
    if (rslt == BME68X_OK)
    {
    rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);
    if (rslt == BME68X_OK)
    {
    if (dev->chip_id == BME68X_CHIP_ID)
    {
    /* Read Variant ID */
    rslt = read_variant_id(dev);

    if (rslt == BME68X_OK)
    {
    /* Get the Calibration data */
    rslt = get_calib_data(dev);
    }
    }
    else
    {
    printf( "BME680 Invalid Chip ID 0x%02x, expecting 0x%02x\r\n", dev->chip_id, BME68X_CHIP_ID );
    rslt = BME68X_E_DEV_NOT_FOUND;
    }
    }
    }

    return rslt;
    }

    In that,Ive written a printf statement for finding out the error so it appears that my chip id is not changing to bme6x chip id which is 0X61 instead my chip id is printing as 0x00. Can anyone help me to correct this error.

    Thank You

    Best Regards.,

    5 REPLIES 5

    BSTRobin
    Community Moderator
    Community Moderator

    Hi adityaseelam,

    As you used BME68x github code withI2C interface and haven't got chip ID value, you can check if I2C communication is normal?

    Hello Robin,
    Im sharing my i2c communication code with you. Im using AXI IIC bus to connect it to the Sensor. I've designed the block in vivado and have written the software code in Vitis IDE. Here is my i2c code.

     

     
    XIic IicInstance; // Declare the I2C instance as a global variable
     
    // Function to initialize the I2C communication
    BME68X_INTF_RET_TYPE bme68x_i2c_init(void) {
        // Initialize the I2C instance for your platform.
        XIic_Config *IicConfig;
        IicConfig = XIic_LookupConfig(IIC_INSTANCE);
        if (XIic_Initialize(&IicInstance, IIC_INSTANCE) != XST_SUCCESS) {
            // Handle initialization error
            return BME68X_E_COM_FAIL;
        }
     
        return BME68X_OK;
    }
     
    // Function to read data from a specific I2C device at a register address
    BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) {
        // Set the target device address.
        uint8_t device_addr = *(uint8_t*)intf_ptr;
        if (XIic_SetAddress(&IicInstance, XII_ADDR_TO_SEND_TYPE, device_addr) != XST_SUCCESS) {
            // Handle address setting error
            return BME68X_E_COM_FAIL;
        }
     
        // Perform the I2C read operation to read data from the sensor.
        if (XIic_MasterSend(&IicInstance, &reg_addr, 1) != XST_SUCCESS) {
            // Handle I2C register address write error
            return BME68X_E_COM_FAIL;
        }
     
        if (XIic_MasterRecv(&IicInstance, reg_data, len) != XST_SUCCESS) {
            // Handle I2C read error
            return BME68X_E_COM_FAIL;
        }
     
        return BME68X_OK;
    }
     
     
    BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr) {
        // Set the target device address.
    	 uint8_t device_addr = *(uint8_t*)intf_ptr;
    	 (void)intf_ptr;
        if (XIic_SetAddress(&IicInstance, XII_ADDR_TO_SEND_TYPE, device_addr) != XST_SUCCESS) {
            // Handle address setting error
            return BME68X_E_COM_FAIL;
        }
     
        // Perform the I2C write operation to write data to the sensor.
        if (XIic_MasterSend(&IicInstance, (u8 *)reg_data, len) != XST_SUCCESS) {
            // Handle I2C write error
        	return BME68X_E_COM_FAIL;
        }
     
     
        return BME68X_OK;// Return success or your custom success code
    }

     


    Best Regards,

    Hi adityaseelam,

    I upload example code on STM32 for your reference. You can strictly refer to the process of the example code.
    uint8_t GTXBuffer[512], GRXBuffer[2048];
    int8_t SensorAPI_I2Cx_Read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    uint8_t dev_addr = *(uint8_t*)intf_ptr;
    uint16_t DevAddress = dev_addr << 1;

    // send register address
    HAL_I2C_Master_Transmit(&I2C_HANDLE, DevAddress, &reg_addr, 1, BUS_TIMEOUT);
    HAL_I2C_Master_Receive(&I2C_HANDLE, DevAddress, reg_data, length, BUS_TIMEOUT);
    return 0;
    }

    int8_t SensorAPI_I2Cx_Write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    uint8_t dev_addr = *(uint8_t*)intf_ptr;
    uint16_t DevAddress = dev_addr << 1;

    GTXBuffer[0] = reg_addr;
    memcpy(&GTXBuffer[1], reg_data, length);

    // send register address
    HAL_I2C_Master_Transmit(&I2C_HANDLE, DevAddress, GTXBuffer, length+1, BUS_TIMEOUT);
    return 0;
    }

    Hello Robin, I'm sorry for the late response. I'm unable to write the code according to my instance. You have written the i2c commands as per STM32 microcontroller so Ive tried to write the code taking your reference as per my board(Zybo Z7-20 FPGA) but failed to do so.

    Thank You.

    Best Regards,

    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