07-29-2020 04:10 PM
Hi,
I'm working with the BMI270 with PIC32MZ204BEFH064 over SPI. I'm using the Gihub driver and I have problems with the initialization of the devide.
Debugging the code I noticed that the initialization fails when reading for the config files back after writing.
The "INTERNAL_STATUS (0x21)" value is 0x02 = init_err
The error I get is always `BMI2_E_CONFIG_LOAD`.
Following my initialization code:
#define SPI_BUFF_SZ (8+1)
void user_delay_us(uint32_t period_us, void *intf_ptr)
{
/* Wait for a period amount of microseconds. */
DelayUs((unsigned long int)period_us);
}
/*!
* @brief This function is for writing the sensor's registers through SPI bus.
*/
int8_t user_spi_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
/* Write to registers using SPI. Return 0 for a successful execution. */
int i;
uint8_t tmp_TX_buf[SPI_BUFF_SZ];
// if( length > (SPI_BUFF_SZ-1) )
// {
// return -1; //YOSSI TODO- implement Error_Handler();
// }
tmp_TX_buf[0] = k_SPI_WRITE_REG_VAL | reg_addr;
memcpy(tmp_TX_buf + 1, reg_data, length);
LATEbits.LATE4 = 0; //CS BMI270 = 0;
TP4 = 0;
//FREEing THE SPI BUF
while (SPI2STATbits.SPIRBF)
{
tmp_TX_buf[0] = SPI2BUF;
}
SPI2BUF = tmp_TX_buf[0] & 0xFF;
while(!SPI2STATbits.SPIRBF);
tmp_TX_buf[0] = SPI2BUF;
for(i=0; i<length; i++)
{
SPI2BUF = tmp_TX_buf[1+i] & 0xFF;
while(!SPI2STATbits.SPIRBF);
tmp_TX_buf[1+i] = SPI2BUF;
}
LATEbits.LATE4 = 1; //CS BMI270 = 1;
TP4 = 1;
return 0;
}
/*!
* @brief This function is for reading the sensor's registers through SPI bus.
*/
int8_t user_spi_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
/* Read from registers using SPI. Return 0 for a successful execution. */
int i;
uint8_t tmp_TX_buf[10];//,CRM_RX_buf[100];
LATEbits.LATE4 = 0; //CS BMI270 = 0;
TP4 = 0;
tmp_TX_buf[0] = k_SPI_READ_REG_VAL | reg_addr;
//FREEing THE SPI BUF
while (SPI2STATbits.SPIRBF)
{
reg_data[0] = SPI2BUF;
}
SPI2BUF = tmp_TX_buf[0] & 0xFF;
while(!SPI2STATbits.SPIRBF);
reg_data[0] = SPI2BUF; //
for(i=0;i<length;i++)
{
SPI2BUF = tmp_TX_buf[i] & 0xFF;
while(!SPI2STATbits.SPIRBF);
reg_data[i] = SPI2BUF; //
}
//BMI270 = 1;
LATEbits.LATE4 = 1;
TP4 = 1;
return 0;
}
int8_t bmi2_interface_selection(struct bmi2_dev *dev)
{
int8_t rslt = BMI2_OK;
if (dev != NULL)
{
/* Select the interface for execution
* For I2C : BMI2_I2C_INTF
* For SPI : BMI2_SPI_INTF
*/
dev->intf = BMI2_SPI_INTF;
....
Solved! Go to Solution.
08-02-2020 02:46 PM
FYI..... but still thanks pointing me to the issue.
08-03-2020 03:44 AM