09-27-2019 10:03 PM - edited 09-27-2019 10:05 PM
I am trying to have SPI connectio as interface protocol between BMI160 shuttle board/MSP432P401R. What I need is the accel/gyroscope data continuously. The main functions I am using is from BMI160 drivers found on github:
https://github.com/BoschSensortec/BMI160_driver
I have defined the user_spi_read/user_spi_write as below:
int8_t user_spi_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 */
SPI_BMI160_BEGIN;
/* send register address byte */
SPI_BMI160_TX(reg_addr);
/* Storing chip status */
// SPI_BMI160_RX(rslt);
for (i = 0; i < len; i++)
{
SPI_BMI160_TX(*reg_data);
reg_data++;
}
return (rslt);
}
And
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 */
int i;
/* Pull CS_N low*/
SPI_BMI160_BEGIN;
/* send register address byte */
SPI_BMI160_TX(reg_addr);
/* Storing chip status */
//SPI_BMI160_RX(rslt);/////////////////?????
/* Communicate len number of bytes: if RX - the procedure sends 0x00 to push bytes from slave*/
for (i = 0; i < len; i++)
{
SPI_BMI160_TX(0); /* Possible to combining read and write as one access type */
// SPI_WAIT_DONE();
SPI_BMI160_RX(*reg_data); /* Store pData from last pData RX */
reg_data++;
}
//}
/* Pull CS_N low*/
SPI_BMI160_END;
/* return the status byte value */
return(rslt);
}
The functions for SPI (in MSP432p401R) abbreviated as below:
#define SPI_BMI160_BEGIN P6OUT &= ~BIT2;
#define SPI_BMI160_TX(x) do{while(!(UCTXIFG & UCB1IFG));UCB1TXBUF= (x);}while(1==-1)
#define SPI_BMI160_RX(x) do{while(!(UCRXIFG & UCB1IFG));(x)=UCB1RXBUF;}while(1==-1)
#define SPI_BMI160_END P6OUT |= BIT2;
Is this correct form for SPI wirte/read functions? Seems SPI is not working.
Thanks
Saber
10-21-2019 02:05 PM - edited 10-21-2019 02:06 PM
In your case, do something like this:
int8_t dummy;
user_spi_read(0, 0, &dummy, 1);
o_o