EmbDev.net

Forum: µC & Digital Electronics Writing to bmi160 register fails


von Aditya K. (stadkama)


Attached files:

Rate this post
useful
not useful
Writing to bmi160 register fails

I am working on a SPI interface between ATSAM4e8c and bmi160 inertial 
sensor. When I try to
write to the sensor registers, it is not getting saved. On the 
oscilloscope I am able to see the correct signal
that is used for write to the sensors registers. Please find the screen 
shot attached of oscilloscope.
The screen shot shows accelerometer set to normal mode. Writing 0x11 to 
0x7e register in the format
0x7e11.


However when I read a register from the sensor, I am able to read all 
the default values correctly.
 I have followed the following SPI clock parameters
 SCLK- 1MHz, mode 11, 16 bits/transfer.

Find the code snippet for activating the spi, set accelerometer to 
normal mode, and then read the pmu_status register 0x03.
The issue is pmu_status register doesnot show its status bit 
acc_normal_mode set to 1. It is still showing as 0. This
confirms accelerometer is not set to normal mode. I have given a delay 
of 30ms after write operation.

Please let me know what can be the issue. Thank you in advance.

I have added only required parts of the code.
#define MASK 0x80
int main()
{
   /*
    * clock ,pin initialization.
    * set master initialization
    * set the clock parameters
    * enable the spi
    */

    uint8_t uc_chip_sel_index=0;
    uint16_t acc_normal_mode;
    uint16_t enable_spi;
    uint8_t read_pmu_status;
    uint16_t input;
    uint16_t temp=0x00;

    uc_chip_sel_index=1;
    acc_normal_mode=0x7e11;
    enable_spi=0xffff;
      read_pmu_status=0x03;
    input=0xff;
    temp=read_pmu_status|MASK;
    input|=(temp<<8);

    // activate the spi by dummy read of address 0x7f
  // uc_chip_sel_index is used to select the chip id

  spi_select_device(SPI_EXAMPLE, uc_chip_sel_index);
  spi_write(SPI_EXAMPLE, enable_spi, write_pcs,0 );
  //wait till the transmission register is empty
  while (!(SPI_EXAMPLE->SPI_SR & SPI_SR_TXEMPTY)) {}
  //read the spi data.
  spi_read(SPI_EXAMPLE, &data, &read_pcs);
  spi_deselect_device(SPI_EXAMPLE, uc_chip_sel_index);

  //set the accelerometer to normal mode by writing 0x11 to 0x7e 
register.
  spi_select_device(SPI_EXAMPLE, uc_chip_sel_index);
  spi_write(SPI_EXAMPLE, acc_normal_mode, write_pcs,0 );
  //wait till the transmission register is empty
  while (!(SPI_EXAMPLE->SPI_SR & SPI_SR_TXEMPTY)) {}
  //read the spi data.
  spi_read(SPI_EXAMPLE, &data, &read_pcs);
  spi_deselect_device(SPI_EXAMPLE, uc_chip_sel_index);

  delay(30); //30 milli seconds

  // read the pmu_status 0x03 register to check whether the
  // accelerometer is set to normal mode or not.
  // here i am not able to see the accelerometer status
  // set to normal mode.
  spi_select_device(SPI_EXAMPLE, uc_chip_sel_index);
  spi_write(SPI_EXAMPLE, input, write_pcs,0 );
  //wait till the transmission register is empty
  while (!(SPI_EXAMPLE->SPI_SR & SPI_SR_TXEMPTY)) {}
  //read the spi data.
  spi_read(SPI_EXAMPLE, &data, &read_pcs);
  spi_deselect_device(SPI_EXAMPLE, uc_chip_sel_index);

  return 0;
}

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.