Bosch Sensortec Community

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

    BMP388 Pressure Problem

    BMP388 Pressure Problem

    yuxinmiao
    Member

    Hello, I am using the BMP388 sensor. The temperature value is OK. , but pressure value is wrong,  it is below 900 hPa.I use the BMP3-Sensor-API V2.0.1 code on the gitub website. 

    https://github.com/BoschSensortec/BMP3-Sensor-API 

    The experimental results are as follows.

    temperature : 2731.000000
    pressure : 7831998.000000

    The spi communication is working well as  the chip ID number is correctly get. My code is below , where is wrong?

    /* SPI2 init function */
    void MX_SPI2_Init(void)
    {

    hspi2.Instance = SPI2;
    hspi2.Init.Mode = SPI_MODE_MASTER;
    hspi2.Init.Direction = SPI_DIRECTION_2LINES;
    hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
    hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
    hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
    hspi2.Init.NSS = SPI_NSS_SOFT;
    hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
    hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
    hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    hspi2.Init.CRCPolynomial = 0x0;
    hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
    hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
    hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
    hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
    hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
    hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
    hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
    hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
    hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
    hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
    if (HAL_SPI_Init(&hspi2) != HAL_OK)
    {
    Error_Handler();
    }

    }

    uint8_t stm32_spi_writeBMP388(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    reg_addr &= 0x7f;
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
    HAL_SPI_Transmit(&hspi2, &reg_addr, 1, 50);
    while(HAL_SPI_GetState(&hspi2) == HAL_SPI_STATE_BUSY);
    HAL_SPI_Transmit(&hspi2, (uint8_t *)reg_data, length, 50);
    while(HAL_SPI_GetState(&hspi2) == HAL_SPI_STATE_BUSY);
    HAL_SPI_Transmit(&hspi2, &reg_addr, 1, 50);
    while(HAL_SPI_GetState(&hspi2) == HAL_SPI_STATE_BUSY);
    HAL_SPI_Transmit(&hspi2, (uint8_t *)reg_data, length, 50);
    while(HAL_SPI_GetState(&hspi2) == HAL_SPI_STATE_BUSY);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
    return 0;
    }
    uint8_t stm32_spi_readBMP388(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    reg_addr |= 0x80;
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
    delay_ms(5);
    // HAL_SPI_TransmitReceive(&hspi2, &reg_addr, (uint8_t*)reg_data, length, 0xffff);
    HAL_SPI_Transmit(&hspi2, &reg_addr, 1, 50);
    while(HAL_SPI_GetState(&hspi2) == HAL_SPI_STATE_BUSY);
    HAL_SPI_Receive(&hspi2, (uint8_t *)reg_data, length, 50);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
    return 0;
    }

    int8_t user_spi_readBMP388(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    stm32_spi_readBMP388(reg_addr, reg_data, length, intf_ptr);
    return 0;
    }

    int8_t user_spi_writeBMP388(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    stm32_spi_writeBMP388(reg_addr, reg_data, length, intf_ptr);
    return 0;
    }

    void user_delayBMP388(uint32_t period_us, void *intf_ptr)
    {
    delay_us(period_us);

    }

    void BMP388Init(void)
    {
    bmp388.intf = BMP3_SPI_INTF;
    bmp388.write = user_spi_writeBMP388;
    bmp388.read = user_spi_readBMP388;
    bmp388.delay_us = user_delayBMP388;
    bmp388.intf_ptr = &bmp388_addr;
    bmp388.dummy_byte = 1;
    }

    2 REPLIES 2

    Jet
    Occasional Contributor

    Hi Sir:

        If possible, please offer us the raw data and trim values, first we will confirm your results by my STM32F4 platform.

       Thank you.

    Thank you for your reply and help.I've run the same code on different boards.The experimental results confirmed that it was a hardware problem.

    Thanks for your help!

    Good luck!

    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