06-09-2020 08:25 PM - edited 06-09-2020 08:37 PM
Hi
I'd like to configure BMI160 with desired registers. To this aim, The associated functions are defined as follows:
user_spi_write function
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 */
SPI_BMI160_BEGIN;
reg_addr = reg_addr & 0x7F;
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++)
{
SPI_BMI160_TX(*reg_data++);
}
SPI_BMI160_END;
return rslt;
}
user_spi_read function:
int8_t user_spi_read(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 */
/* Communicate len number of bytes: if RX - the procedure sends 0x00 to push bytes from slave*/
SPI_BMI160_BEGIN;
reg_addr = reg_addr | 0x80; // For read operation, the reg_addr should be ORed with 0x80.
SPI_BMI160_TX(reg_addr);
__delay_cycles(15); //after write operation, at least 2 micro-seconds is required for the next operation.
//SPI_BMI160_RX(rslt);
for (i = 0; i < length; i++)
{
SPI_BMI160_TX(0); /* Possible to combining read and write as one access type */
SPI_BMI160_RX(*reg_data++); /* Store pData from last pData RX */
}
SPI_BMI160_END;
return rslt;
}
user_delay_ms function:
int8_t user_delay_ms(uint32_t period)
{
int8_t rslt = BMI160_OK; /* Return 0 for Success, non-zero for failure */
a=0;
while(a<period)
{
__delay_cycles(1);
a++;
}
return rslt;
}
and also, I have defined a configure function that defines the registers:
int Configuring(void)
{
// You may assign a chip select identifier to be handled later
/**Initialize the BMI160***/
struct bmi160_dev sensor;
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;
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 */
/*********Configuring the acc/gyro*************/
// int8_t rslt = BMI160_OK;
/* Select the Output data rate, range of accelerometer sensor */
sensor.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
sensor.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4;
/* Select the Output data rate, range of Gyroscope sensor */
sensor.gyro_cfg.odr = BMI160_GYRO_ODR_3200HZ;
sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS;
sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE;
/* Select the power mode */
sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
/* Set the Power mode */
rslt = bmi160_set_power_mode(&sensor);
/* Set the sensor configuration */
rslt = bmi160_set_sens_conf(&sensor);
return rslt;
}
The problem I have here is that at the start of executing the code in debug mode, it goes to exit.c (on code composer studio). Where do you think the problem comes from? Thanks and regards!
Also for brevity, the spi functions are abbreviated as:
//**The code is implemented on MSP432P401R**//
#define SPI_BMI160_TX(X) {while(!(UCB1IFG & UCTXIFG));UCB1TXBUF=X;}while(1==-1)
#define SPI_BMI160_RX(X) {while(!(UCB1IFG & UCRXIFG));X=UCB1RXBUF;}while(1==-1)
#define SPI_BMI160_BEGIN P6OUT &= ~BIT2;
#define SPI_BMI160_END P6OUT |= BIT2;
06-10-2020 05:05 AM
Hi,
I couldn't find out the error quicly.
Maybe you can add printf() function and log more info, this can help you find the exception position.