This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Questions about spi read and write function mapping

I'm having trouble driving the BMI088 with the official driver of Bosch BMI088 (link to this driver) in the ble_app_uart routine. I never get the chip ID. Bosch BMI088 official driver link address: https://github.com/BoschSensortec/BMI08x-Sensor-API . The spi read and write functions are encapsulated into the following two APIs: 

int8_t user_spi_write(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len);

int8_t user_spi_read(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len);

So How can I map these two APIs into Nordic operation functions? 

   

And The automatic selection between [CPOL = '0' and CPHA = '0'] and [CPOL = '1' and CPHA = '1'] is controlled based on the value of SCK after a falling edge of CSB (1 or 2). What SPI mode should I configure?

Parents
  • At present, in the process of communicating with the BMI088 sensor, I suspect that the spi read and write commands are abnormal. In order to determine that the function mapping I made is not a problem, I will paste a piece of function mapping code below.

    /*!
     *  @brief Function for reading the sensor's registers through SPI bus.
     *
     *  @param[in] cs_pin   : Chip selection pin.
     *  @param[in] reg_addr : Register address.
     *  @param[in] data     : Pointer to the data buffer to store the read data.
     *  @param[in] len      : No of bytes to read.
     *
     *  @return Status of execution
     *  @retval 0 -> Success
     *  @retval >0 -> Failure Info
     *
     */
    int8_t user_bmi088_spi_write(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
    {
        if (cs_pin == MCU_GPIO_BMI088_CSB1)
        {
            nrf_gpio_pin_set(MCU_GPIO_BMI088_CSB2);
            nrf_gpio_pin_clear(MCU_GPIO_BMI088_CSB1);
        }
        else if (cs_pin == MCU_GPIO_BMI088_CSB2)
        {
            nrf_gpio_pin_set(MCU_GPIO_BMI088_CSB1);
            nrf_gpio_pin_clear(MCU_GPIO_BMI088_CSB2);
        }
        else if ((cs_pin != MCU_GPIO_BMI088_CSB1) && (cs_pin != MCU_GPIO_BMI088_CSB2))
        {
            return -2;
        }
        nrf_delay_us(1);
        if (len <= 32)
        {
            uint8_t m_tx_buf[33] = {0};
            m_tx_buf[0] = reg_addr;
            uint8_t m_tx_length = ((uint8_t)len) + 1;
    //        const uint8_t m_rx_length = 0;
            memcpy(&m_tx_buf[1], &data, len);
    
            spi_bmi088_xfer_done = false;
    
            APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi_0, m_tx_buf, m_tx_length, NULL, 0));
            while(!spi_bmi088_xfer_done)
            {
                __WFE();
            }
        }
        else
        {
            NRF_LOG_INFO("Spi write over length.");
        }
        nrf_delay_us(1);
        nrf_gpio_pin_set(cs_pin);
    
        return 0;
    }
    
    
    /*!
     *  @brief Function for writing the sensor's registers through SPI bus.
     *
     *  @param[in] cs_pin   : Chip selection pin.
     *  @param[in] reg_addr : Register address.
     *  @param[out]data     : Pointer to the data buffer whose value is to be written.
     *  @param[in] len      : No of bytes to write.
     *
     *  @return Status of execution
     *  @retval 0 -> Success
     *  @retval >0 -> Failure Info
     *
     */
    int8_t user_bmi088_spi_read(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
    {
        if (cs_pin == MCU_GPIO_BMI088_CSB1)
        {
            nrf_gpio_pin_set(MCU_GPIO_BMI088_CSB2);
            nrf_gpio_pin_clear(MCU_GPIO_BMI088_CSB1);
        }
        else if (cs_pin == MCU_GPIO_BMI088_CSB2)
        {
            nrf_gpio_pin_set(MCU_GPIO_BMI088_CSB1);
            nrf_gpio_pin_clear(MCU_GPIO_BMI088_CSB2);
        }
        else if ((cs_pin != MCU_GPIO_BMI088_CSB1) && (cs_pin != MCU_GPIO_BMI088_CSB2))
        {
            return -2;
        }
        nrf_delay_us(1);
        if (len <= 32)
        {
            uint8_t m_tx_buf[1] = {reg_addr};
            uint8_t m_tx_length = 1;
            uint8_t m_rx_length = (uint8_t)len;
    				
            spi_bmi088_xfer_done = false;
    
            APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi_0, m_tx_buf, m_tx_length, data, m_rx_length));
            while(!spi_bmi088_xfer_done)
            {
                __WFE();
            }
        }
        else
        {
            NRF_LOG_INFO("Spi read over length.");
        }
        nrf_delay_us(1);
        nrf_gpio_pin_set(cs_pin);
    
        return 0;
    }

  • Are the above function mapping operations normal?

    Which engineer can answer me?

  • Where do you set spi_bmi088_xfer_done after the transfer is complete?

    what SDK and driver are you using?

Reply Children
No Data
Related