Setting up SPI for BMI160

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
8 posts / 0 new
Last post
ImagineSam
Offline
Last seen:10 months 3 weeks ago
加入:2017-06-08 09:00
Setting up SPI for BMI160

Hi,

I'm trying to communicate with BMI160 in the DA14681 Development Kit.

I am using the peripherals_demo example and trying to call the bmi160_get_chip_id to test the connection. However, it just returns 0xff, instead of the actual chip ID which is D1.

dev = ad_spi_open(BMI160);
uint8_t wbuf[2] = {0};

ad_spi_transact(dev, wbuf, 1, reg_data, 1);

if (reg_data[0] == 0xD1)
{
reg_data[1] = 0xA;
}
else
{
reg_data[2] = 0x05;
}
ad_spi_close(dev);

The pins are configured as follows:

HW_GPIO_PINCONFIG (HW_GPIO_PORT_3 HW_GPIO_PIN_2, OUTPUT_PUSH_PULL, SPI_CLK, true),
HW_GPIO_PINCONFIG (HW_GPIO_PORT_3 HW_GPIO_PIN_0, OUTPUT_PUSH_PULL, SPI_DO, true),
HW_GPIO_PINCONFIG (HW_GPIO_PORT_3 HW_GPIO_PIN_1, INPUT, SPI_DI, true),
HW_GPIO_PINCONFIG (HW_GPIO_PORT_3 HW_GPIO_PIN_3, OUTPUT_PUSH_PULL, SPI_EN, true),

SPI_SLAVE_DEVICE(SPI1, BMI160, HW_GPIO_PORT_3, HW_GPIO_PIN_3,
HW_SPI_WORD_8BIT, HW_SPI_POL_HIGH, HW_SPI_PHA_MODE_1,
HW_SPI_FREQ_DIV_2, HW_DMA_CHANNEL_0);

Thanks,
Sam

Device:
MT_dialog
Offline
Last seen:3 months 7 hours ago
工作人员
加入:2015-06-08 11:34
Hi ImagineSam,

Hi ImagineSam,

I dont see any issues on the code that you have attached. The pro kit daughterboard that you are using has a QFN or a CSP package ? Since the port 3 is not available on the CSP package. Also try to test that with a logic analyser and check if there are signals comming out of the 680, in order to verify that the code toggles the pins.

Thanks MT_dialog

ImagineSam
Offline
Last seen:10 months 3 weeks ago
加入:2017-06-08 09:00
Hi MT_dialog,

Hi MT_dialog,

The package is the QFN (I believe the DA14681 Wearable kit only comes in this package?).

The read and write functions seem to be working in the wearable device firmware (DA14681_WRBL_v_1.150.6) that is provided but when using the same pins in a more lightweight project it fails to work. Is it possible that there are other required configurations to make it work?

Sincerely,
Sam

MT_dialog
Offline
Last seen:3 months 7 hours ago
工作人员
加入:2015-06-08 11:34
Hi ImagineSam,

Hi ImagineSam,

Yes, the wearble comes to an QFN package (you didn't mentioned which kit you where using).

Had a look in the datasheet of the BMI160 p88 on that datasheet that i have, well it seems that the sensor requires that first bit of the byte sequence when you are about to read should be '1', so actually what you should send from the 68x is 0x80 and not 0x00, if you place 0x80 in the wbuf instead of 0x00 you will get the id that the BMI replies.

Thanks MT_dialog

ImagineSam
Offline
Last seen:10 months 3 weeks ago
加入:2017-06-08 09:00
MT_dialog,

MT_dialog,

Sorry, that was my bad, I meant to write "BMI160 in the DA14681 Wearable Development Kit".

I added the following line as you suggested but it still doesn't work.reg_datais returning a 0 for the device ID.

wbuf[0] = wbuf[0] | 0x80;

I have also tried it using this method which is how it's executed in the wearable firmware and it doesn't work either:

uint8_t reg_addr = 0x00;
uint8_t reg_data[10] = {0};
spi_transfer_data transfers[2] = {
{®_addr, NULL, 1},
{ NULL, reg_data, cnt}
};

reg_addr = reg_addr | 0x80;
ad_spi_complex_transact(dev, transfers, 2);
void ad_spi_transact(spi_device dev, const uint8_t *wbuf, size_t wlen, uint8_t *rbuf, size_t rlen);

Thanks,
Sam

MT_dialog
Offline
Last seen:3 months 7 hours ago
工作人员
加入:2015-06-08 11:34
Hi ImagineSam,

Hi ImagineSam,

Tested on a wearable board using the ble_adv example with the appropriate mods offcourse in order to enable the SPI hardware and the SPI adapters using the below #defines:

#define dg_configSPI_ADAPTER

#define dg_configUSE_HW_SPI

With the instructions below, i could see in debug mode that the data send back from the sensor is one byte 209 dec or 0xD1 which indicates the id of the BMI160.

bmi160_dev = ad_spi_open(BMI160);
data_wbuf[0]|=0x80;
ad_spi_transact(bmi160_dev, data_wbuf, 1, reg_data, 1);

Thanks MT_dialog

ImagineSam
Offline
Last seen:10 months 3 weeks ago
加入:2017-06-08 09:00
Hi MT_Dialog

Hi MT_Dialog

Thank you, using the ble_adv example I was able to get it to work like you did! And I have an actual stream of data coming in.

But is there any idea why it works in one project and not in the others? I have tried withperipherals_demoandpxp_reporter

Could the SDK be an issue?ble_advdidn't work for me in 1.0.10 sdk which is what I used for the other projects but when I changed to 1.0.12 ble_adv started working.

Sincerely,
Sam

MT_dialog
Offline
Last seen:3 months 7 hours ago
工作人员
加入:2015-06-08 11:34
Hi ImagineSam,

Hi ImagineSam,

Perhaps you missed any configuration, the peripherals demo is a quite loaded demo with a bunch of configurations and setups and you can easily miss something, in any case the SDK 1.0.12 is the latest version of the SDK and also i 've tested the same code and using the exact same settings on the SDK 1.0.10 and it operates on that SDK as well in the ble_adv demo.

Thanks MT_dialog