BMI160 SPI on RG firmware development
Hi,
I'm trying to work with BMI160 over SPI ( RG board ).
On nrf_drv_config.h:
/* SPI */
#define SPI0_ENABLED 1
#if (SPI0_ENABLED == 1)
#define SPI0_USE_EASY_DMA 0
#define SPI0_CONFIG_SCK_PIN 0
#define SPI0_CONFIG_MOSI_PIN 7
#define SPI0_CONFIG_MISO_PIN 11
#define SPI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPI0_INSTANCE_INDEX 0
#endif
On main.c:
void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
{
spi_xfer_done = true;
}
void spi_master_init(void)
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
spi_config.ss_pin = SPI_CS_PIN;
spi_config.miso_pin = SPI0_CONFIG_MISO_PIN;
spi_config.mosi_pin = SPI0_CONFIG_MOSI_PIN;
spi_config.sck_pin = SPI0_CONFIG_SCK_PIN;
spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
spi_config.mode = NRF_DRV_SPI_MODE_3;
spi_config.irq_priority = SPI0_CONFIG_IRQ_PRIORITY;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
}
On main routine:
m_tx_buf[0] = 0x00 | 0x80 ; // chip id reg adr | read_mask
memset(m_rx_buf, 0, SPI_BUFFER_SIZE);
spi_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, 1, m_rx_buf, 1));
while(spi_xfer_done == false){;}
After the while loop for spi_xfer_done m_rx_buf[0] is always 0xFF;
The main problem is that I can't use oscilloscope ( no test/pad pin on specifications ).
So, I can't understand what happen (debugging step by step seems good).
I tried to swap MISO and MOSI pin cause pdf spacifications is not so clear.
Other
strange thing is that in specification pdf there is a draw with i2c
BMI160 connection ( Figure 1 Block diagram ) but the "Internal Module
Pin list" says that BMI160 is connected via SPI.
Thank you for any answer.
I'm trying to work with BMI160 over SPI ( RG board ).
On nrf_drv_config.h:
/* SPI */
#define SPI0_ENABLED 1
#if (SPI0_ENABLED == 1)
#define SPI0_USE_EASY_DMA 0
#define SPI0_CONFIG_SCK_PIN 0
#define SPI0_CONFIG_MOSI_PIN 7
#define SPI0_CONFIG_MISO_PIN 11
#define SPI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW
#define SPI0_INSTANCE_INDEX 0
#endif
On main.c:
#define SPI_CS_PIN 10
#define SPI_BUFFER_SIZE 16
#define SPI_INSTANCE 0
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);
static volatile bool spi_xfer_done;
static uint8_t m_tx_buf[SPI_BUFFER_SIZE];
static uint8_t m_rx_buf[SPI_BUFFER_SIZE];
static const uint8_t m_length = SPI_BUFFER_SIZE;
void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
{
spi_xfer_done = true;
}
void spi_master_init(void)
{
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
spi_config.ss_pin = SPI_CS_PIN;
spi_config.miso_pin = SPI0_CONFIG_MISO_PIN;
spi_config.mosi_pin = SPI0_CONFIG_MOSI_PIN;
spi_config.sck_pin = SPI0_CONFIG_SCK_PIN;
spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
spi_config.mode = NRF_DRV_SPI_MODE_3;
spi_config.irq_priority = SPI0_CONFIG_IRQ_PRIORITY;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
}
On main routine:
m_tx_buf[0] = 0x00 | 0x80 ; // chip id reg adr | read_mask
memset(m_rx_buf, 0, SPI_BUFFER_SIZE);
spi_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, m_tx_buf, 1, m_rx_buf, 1));
while(spi_xfer_done == false){;}
After the while loop for spi_xfer_done m_rx_buf[0] is always 0xFF;
The main problem is that I can't use oscilloscope ( no test/pad pin on specifications ).
So, I can't understand what happen (debugging step by step seems good).
I tried to swap MISO and MOSI pin cause pdf spacifications is not so clear.
Other
strange thing is that in specification pdf there is a draw with i2c
BMI160 connection ( Figure 1 Block diagram ) but the "Internal Module
Pin list" says that BMI160 is connected via SPI.
Thank you for any answer.
This discussion has been closed.
Comments
So, I was using in wrong way the function nrf_drv_spi_transfer. The lengh of buffers was 1, not enought for 16bit clock cycle.
Thank you for reading.
Thank you.
I wish to discuss with you about this in more detail.
I can't understand your comments enoughly.
Did you realize the correct SPI interface firmware for BMI160?
If you realize it, did you read the correct CHIP_ID, 0xD1 for BMI160?
And didn't you use the function <nrf_drv_spi_transfer>?
I hope that you give the correct answer about this.
Thanks for your time.
From Minghui.
Yes SPI is working well by SPI.
Tell me what's not clear for you.
( sofware SPI routine was just for understand the problem )