Bosch Sensortec Community

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

    BMI I2C: Shuttle board connections and write/read functions

    BMI I2C: Shuttle board connections and write/read functions

    SaberKazemi1992
    Established Member

    Hi Bosch sesnrtec community

    I am using BMI160 IMU (shuttle board) as motion sesnor in my application. The MCU is MSP432P401R.

    1- What is the proper wiring configuration for the shuttle board for I2C protocol?

    2- I have written the code for I2C read/write functions like below:

    /************BMI160 I2C*********/
    UCB1CTLW0 |= UCSWRST; // **Initialize USCI state machine**
    P6SEL0 |= BIT4 + BIT5;
    P6SEL1 &= ~(BIT4 + BIT5); // | P6.3: UCB1SCLK| P6.4: UCB1SIMO | P6.5: UCB1SOMI (Refer to the datasheet, page: 159).
    UCB1CTLW0 |= UCCKPH + UCMST + UCMSB + UCSYNC + UCSSEL_2 + UCMODE_3; // 3-pin, 8-bit, SPI master
    UCB1BR0 = 12; // fSCL = SMCLK/12 = ~250kHz
    UCB1BR1 = 0;
    UCB1I2CSA = BMI160_I2C_ADDR; // Set slave address
    UCB1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**

    int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

    /*
    * The parameter dev_id can be used as a variable to store the I2C address of the device
    */
    UCB1CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition
    UCB1TXBUF = reg_addr; // Write reg_addr byte
    UCB1CTLW0 |= UCTXSTP; // I2C stop condition.

    UCB1I2CSA |= BMI160_I2C_ADDR; // Set slave address
    UCB1CTLW0 &=~UCA10; //10BIT ADDRESS
    UCB1CTLW0 &=~UCTR;//CLEAR TRANSMIT MODE
    UCB1CTLW0 |= UCTXSTT; // I2C RX, start condition
    int i=0;
    for (i=0;i<len;i++)
    {
    reg_data[i]=UCB1RXBUF;
    }
    UCB1CTLW0 |= UCTXSTP; // I2C stop condition.

    return rslt;
    }

    int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    UCB1CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition
    UCB1TXBUF = reg_addr; // Write reg_addr byte
    int i=0;
    for (i=0;i<len;i++)
    {
    UCB1TXBUF=reg_data[i];
    }
    UCB1CTLW0 |= UCTXSTP; // I2C stop condition.

    return rslt;
    }

     Is it the right statement for them?

    Thanks

    Saber

    6 REPLIES 6

    handytech
    Community Moderator
    Community Moderator

    @SaberKazemi1992 wrote:

    1- What is the proper wiring configuration for the shuttle board for I2C protocol?


    The protocol is automatically elected based on the CSB pin behavior after power-up. By default and if you would like to remain in I2C mode, CSB pin should be directly connected to VDDIO. In I2C mode please be aware of the I2C address selection via the SDO pin behavior. Below is a snippet from BMI160's datasheet showing the recommended connection diagram for the I2C protocol:

    clipboard_image_0.png

    The schematic of BMI160's shuttle board can be found here: BMI160 Shuttle Board flyer.


    @SaberKazemi1992 wrote:

    2- I have written the code for I2C read/write functions like below:

    /************BMI160 I2C*********/
    UCB1CTLW0 |= UCSWRST; // **Initialize USCI state machine**
    P6SEL0 |= BIT4 + BIT5;
    P6SEL1 &= ~(BIT4 + BIT5); // | P6.3: UCB1SCLK| P6.4: UCB1SIMO | P6.5: UCB1SOMI (Refer to the datasheet, page: 159).
    UCB1CTLW0 |= UCCKPH + UCMST + UCMSB + UCSYNC + UCSSEL_2 + UCMODE_3; // 3-pin, 8-bit, SPI master
    UCB1BR0 = 12; // fSCL = SMCLK/12 = ~250kHz
    UCB1BR1 = 0;
    UCB1I2CSA = BMI160_I2C_ADDR; // Set slave address
    UCB1CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**

    int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

    /*
    * The parameter dev_id can be used as a variable to store the I2C address of the device
    */
    UCB1CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition
    UCB1TXBUF = reg_addr; // Write reg_addr byte
    UCB1CTLW0 |= UCTXSTP; // I2C stop condition.

    UCB1I2CSA |= BMI160_I2C_ADDR; // Set slave address
    UCB1CTLW0 &=~UCA10; //10BIT ADDRESS
    UCB1CTLW0 &=~UCTR;//CLEAR TRANSMIT MODE
    UCB1CTLW0 |= UCTXSTT; // I2C RX, start condition
    int i=0;
    for (i=0;i<len;i++)
    {
    reg_data[i]=UCB1RXBUF;
    }
    UCB1CTLW0 |= UCTXSTP; // I2C stop condition.

    return rslt;
    }

    int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
    {
    int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
    UCB1CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition
    UCB1TXBUF = reg_addr; // Write reg_addr byte
    int i=0;
    for (i=0;i<len;i++)
    {
    UCB1TXBUF=reg_data[i];
    }
    UCB1CTLW0 |= UCTXSTP; // I2C stop condition.

    return rslt;
    }


    I am not very familiar with the MSP432P401R in particular, but I do not see the slaved address (UCB1I2CSA?) being used in the write function. Note that when using our official sensor API in I2C mode, the I2C address of BMI160 (defined in 1- above) should be initialized in the id  element (e.g. here), and this value will be transmitted to the dev_id argument of your user read/write functions. For reference, the two snippets below (from the datasheet) also show the expected read/write sequences on the bus:

    clipboard_image_1.png

    clipboard_image_2.png

    Thanks for your reply.

    For pin connections, I see in the datasheet, a pin SA0 for I2C protocol, it is connected to GND. Is it correct?

    When I connected this pin to the GND, the MCU crashed!

    Thanks

    Saber

    And also, one more question:

    - What is the difference between VDD and VDDIO? Both goes to 3.3V pin of the MCU? 

    Thanks

    Saber


    @SaberKazemi1992 wrote:

    - What is the difference between VDD and VDDIO? Both goes to 3.3V pin of the MCU? 


    • VDD is the main power supply for the internal blocks (analog, etc.).
    • VDDIO is a seprate power supply used for the supply of the digital interface.

    Both pins must be power, and can be tied together. 3.3V is fine.


    @SaberKazemi1992 wrote:

    For pin connections, I see in the datasheet, a pin SA0 for I2C protocol, it is connected to GND. Is it correct?

    When I connected this pin to the GND, the MCU crashed!


    Ouchies 😯  The SDO pin of the BMI160 can act differently depending on the protocol selected. In I2C mode, this pin acts as an I2C address selector. This means connecting SDO pin to GND will results in I2C address 0x68 for the BMI160, but connecting it to VDDIO will results in the alternative I2C address 0x69.

    Note that SDO is pin#1 of BMI160's package, but routed to pin#4 (and pin#15) of the shuttle board.

    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