07-27-2020 08:43 PM
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!
07-28-2020 01:24 AM
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.
07-28-2020 02:29 AM
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
07-28-2020 09:02 PM
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.