Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI 160 Shuttle Board Wiring for 4 Wire SPI

    Highlighted
    Established Member

    BMI 160 Shuttle Board Wiring for 4 Wire SPI

    Hi

    I'd like to configure the bmi160 with 4 wire SPI. I have done it but got stuck! In other words, when I want to initialize the sensor with SPI function instances, the code goes to abnormal termination, and no logical behavior is seen.  I mean here: 

    struct bmi160_dev sensor;
    
    /* You may assign a chip select identifier to be handled later */
    sensor.id = 0;
    sensor.interface = BMI160_SPI_INTF;
    sensor.read = user_spi_read;
    sensor.write = user_spi_write;
    sensor.delay_ms = user_delay_ms;
    
    
    int8_t rslt = BMI160_OK;
    rslt = bmi160_init(&sensor);
    /* After the above function call, accel_cfg and gyro_cfg parameters in the device 
    structure are set with default values, found in the datasheet of the sensor */

     

    I have tried multiple things but the problem is still there. I have provided a photo of the shuttle board wiring. Can you please let me know if this is the correct way. Thanks!

    bmi160 wiring.png

     

    3 REPLIES 3
    Highlighted
    Community Moderator

    Re: BMI 160 Shuttle Board Wiring for 4 Wire SPI

    The hardwire connection is correct.

    According to source code, i need to check with you if you use our API and already put your own user_defined_spi read / write function into our code to replace the original dummy funciton? 

    If yes,  can you share us the logic analyzer result for better understanding the issue?

    Please also pay attention to the SPI mode,  we suport mode 0 and 3 but on some MCU,  it is coded by different mode name. 

    Highlighted
    Established Member

    Re: BMI 160 Shuttle Board Wiring for 4 Wire SPI

    Yes, The function instances are listed below:

    1- For spi_write

    int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t length)
    {
            int8_t rslt = BMI160_OK; /* Return 0 for Success, non-zero for failure*/
            reg_addr = reg_addr & 0x7F;
            P6OUT &= ~BIT2;/* Pull CS_N low*/
            /* send register address byte */
            while(!(UCTXIFG & UCB1IFG));  //UCB1 TX buffer ready?
            UCB1TXBUF= reg_addr;
           // SPI_BMI160_TX(reg_addr); // For write operations, the register should be ANDed with 0x7F.
             __delay_cycles(15);
                 /* Communicate len number of bytes: if TX - the procedure doesn't overwrite pData */
                 for (i = 0; i < length; i++)
                 {
                     while(!(UCTXIFG & UCB1IFG));  //UCB1 TX buffer ready?
                             UCB1TXBUF= *reg_data++;
                    // SPI_BMI160_TX(*reg_data++);
                 }
                 /* Pull CS_N high*/
                 P6OUT |= BIT2;
                 /* return the status byte value */
                 return rslt;
    }

    2- Spi_read

    int8_t user_spi_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 */
    
    P6OUT &= ~BIT2;/* Pull CS_N low*/
    
    /* send register address byte */
    
    while(!(UCTXIFG & UCB1IFG));  //UCB1 TX buffer ready?
    
    UCB1TXBUF= reg_addr;
    __delay_cycles(15); //after write operation, at least 2 micro-seconds is required for the next operation.
    //SPI_BMI160_RX(rslt);
    
    /* Storing chip status */
    while(!(UCRXIFG & UCB1IFG));//UCB1 RX buffer ready?
    
    rslt= UCB1RXBUF;
    
    /* Communicate len number of bytes: if RX - the procedure sends 0x00 to push bytes from slave*/
    for (i = 0; i < len; i++)
    {
    UCB1TXBUF=0; /* Possible to combining read and write as one access type */
    
    //while(!(UCRXIFG & UCB1IFG));//UCB1 RX buffer ready?
    
    *reg_data= UCB1RXBUF;
    
     /* Store pData from last pData RX */
    reg_data++;
    }
    //}
    /* Pull CS_N high*/
    P6OUT |= BIT2;
    /* return the status byte value */
    return(rslt);
    }

    The problem here is that upon calling the sensor_init(&sensor), the MCU in debugging mode goes to error mode (In Texas Instruments MSP, it goes to exit.c) and no pin behaviour on the logic analyzer is observed.

     

    Can you please explain a little more about the SPI modes that the BMI160 support? I appreciate it!

    Thanks

    Saber

    Highlighted
    Community Moderator

    Re: BMI 160 Shuttle Board Wiring for 4 Wire SPI

    You can get detail about the SPI timing for read and write in datasheet chapter 3.2.2 on page 88. 

    BMI160 follow the standard SPI protocol,  there is no special items need host to adopt. 

    BMI_init function will start with spi read register from address 0x00.   if you are not able to see any plotter on SPI bus,  you should focus on read function on the TI MCU platform first. 

    Can you see CS pin goes to low as expected? 

    I didn't find any abnormal in provided code which i think the standard driver for TI MCU SPI module. 

    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