Bosch Sensortec Community

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

    BMP388 MULTIPLE DEVICES USING SAME SPI BUS

    BMP388 MULTIPLE DEVICES USING SAME SPI BUS

    honoju
    Member

    Hello,

    I am using BMP388 sensors with the official Bosch API on a SPI bus of a STM32L476RG microcontroller. When I use only one BMP388 sensor, everything works fine.

    But I haven't succeded to communicate with multiple sensors on the same SPI bus, I can't even read the chip_ids. I am using the independant slave configuration as on the  image below ( the power supply being 3,3V and not 5V):

    honoju_0-1606314264165.png

     

    I have seen on this forum that with SPI protocol, one can use as many sensors as he needs with no added hardware. I have investigated the code run and I noticed that it is the sensor register reading that is problematic.

    Here is the location in the code where it bugs (it is in the bmp3_get_regs() function of the bmp3.c API file) :

     

    /* Read the data from the register */
    dev->intf_rslt = dev->read(reg_addr, temp_buff, temp_len, dev->intf_ptr);

     

     

    My user_spi_read function is as follows :

     

    int8_t user_spi_read(uint8_t addr_reg, uint8_t *data_reg, uint8_t len, void *intf_ptr)
    {
    	int8_t rslt = 0;
            
          /* resetting the good chip select pin */
    	if(intf_ptr == &dev_addr[0])
    		HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);
    	if(intf_ptr == &dev_addr[1])
    		HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_RESET);
    	if(intf_ptr == &dev_addr[2])
    		HAL_GPIO_WritePin(CS3_GPIO_Port, CS3_Pin, GPIO_PIN_RESET);
    	if(intf_ptr == &dev_addr[3])
    		HAL_GPIO_WritePin(CS4_GPIO_Port, CS4_Pin, GPIO_PIN_RESET);
    	if(intf_ptr == &dev_addr[4])
    		HAL_GPIO_WritePin(CS5_GPIO_Port, CS5_Pin, GPIO_PIN_RESET);
    	if(intf_ptr == &dev_addr[5])
    		HAL_GPIO_WritePin(CS6_GPIO_Port, CS6_Pin, GPIO_PIN_RESET);
    
             /* SPI transimission of the register to read*/
    	HAL_SPI_Transmit(&hspi1, &addr_reg, 1, HAL_MAX_DELAY);
    
             /* SPI reception of the data containedthe register read*/
    	HAL_SPI_Receive(&hspi1, data_reg, len, HAL_MAX_DELAY);
    
             /*setting the good chip select pin */
    	if(intf_ptr == &dev_addr[0])
    		HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);
    	if(intf_ptr == &dev_addr[1])
    		HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_SET);
    	if(intf_ptr == &dev_addr[2])
    		HAL_GPIO_WritePin(CS3_GPIO_Port, CS3_Pin, GPIO_PIN_SET);
    	if(intf_ptr == &dev_addr[3])
    		HAL_GPIO_WritePin(CS4_GPIO_Port, CS4_Pin, GPIO_PIN_SET);
    	if(intf_ptr == &dev_addr[4])
    		HAL_GPIO_WritePin(CS5_GPIO_Port, CS5_Pin, GPIO_PIN_SET);
    	if(intf_ptr == &dev_addr[5])
    		HAL_GPIO_WritePin(CS6_GPIO_Port, CS6_Pin, GPIO_PIN_SET);
    
    	return rslt;
    }

     

     

    With this code, I read n+1 bytes (the first one being the dummy byte) from the sensor registers. For example, to read the chip_id, when I use one sensor I get two bytes the first one being the dummy byte (0xFF)  and the second one being the real chip_id byte (0x50). But when I use multiple sensors, I read twice the dummy byte value (0xFF).

    I have also seen on the net that for the SPI multiple independant devices configuration to work, pull-up resistors are required for chip select pins as tristate buffers for SDO pins. Does the BMP388 have these features or do we have to add them in order to use multiples BMP388 sensors on the same SPI bus?

    Thanks in advance for your help,

    Regards

    14 REPLIES 14

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Honoju,

    In theory, it didn't need extra pull-up resistors for SDO.

    Under STM32 MCU platform, you could refer HAL_SPI_TransmitReceive() function to implement user_spi_read(). You need to set Size+1 when you call HAL_SPI_TransmitReceive(). And after call this function, you need copy pRxData+1 to data_reg.

    HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size,
    uint32_t Timeout)

    Hello BSTRobin,

    Thanks for the reply

    I tried your function but it gives the same result as my following functions :

    HAL_SPI_Transmit(&hspi1, &addr_reg, 1, HAL_MAX_DELAY);
    HAL_SPI_Receive(&hspi1, data_reg, len, HAL_MAX_DELAY);

    I think your function is the combination of my two functions.

    To give more details on my functions:

    HAL_SPI_Transmit(&hspi1, &addr_reg, 1, HAL_MAX_DELAY) sends one byte correspoing to the register to be read
    HAL_SPI_Receive(&hspi1, data_reg, len, HAL_MAX_DELAY) recieves len bytes. The API bmp3_get_regs() function manages to make len equal to (needed + 1) bytes as the first byte is a dummy one.

     


    In theory, it didn't need extra pull-up resistors for SDO.


    I disconnected all sensors from the master apart from one, and in that case, Isucceeded reading the chip_id so I am wondering if the SPI bus configuration is the matter. Especially I am worried about the SDO not being in high-impedance state when the sensor is not in communication with the master. And if it is the case, I am wondering if a tristate buffer is needed to force the SDO in the high-impedance state

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Honoju,

    I suggest you could do a test first.

    1.spi master was connected to BMP388, read BMP388 chip id and capture SPI waveform by logic analyzer.

    2. spi master was connected to BMP388 and your other spi slave device, read BMP388 chip id and capture SPI waveform by logic analyzer.

    Compare SPI waveform between step 1 and step 2.

    And by the way, besides on  BMP388, what is other spi slave device you used?

    Hello,

    Thanks for your reply and sorry for my late reply,

    Well, all devices are BMP388. We are using 6 of them

    I don't have a logic analyzer for the moment, could there be any other way?

    Thanks,

    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