It is recommended to observe the waveform using a logic analyzer or oscilloscope.
Here are some suggestions in terms of the code:
After power-on reset, the BMI160 is in I2C state by default. Therefore, a dummy read of register 0x00 is required to switch to SPI bus.
For write operations, reg_address should be ANDed with 0x7f and then sent out. For example, to write the address 0x40, 0x40 is ANDed with 0x7f, i.e. 0x40 & 0x7f, and the result 0x40 is sent out.
For read operations, reg_address should be ORed with 0x80 and then sent out. For example, to read the address 0x40, 0x40 is ORed with 0x80, i.e. 0x40 | 0x80, and the result 0xC0 is sent out.
... View more