<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55074/questions-about-spi-read-and-write-function-mapping</link><description>I&amp;#39;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 </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 29 Aug 2021 10:33:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55074/questions-about-spi-read-and-write-function-mapping" /><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/327072?ContentTypeID=1</link><pubDate>Sun, 29 Aug 2021 10:33:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8689c141-53df-4bc6-9c5d-9dd76f843fc6</guid><dc:creator>rayan4444</dc:creator><description>&lt;p&gt;I am facing the exact same issues with the exact same sensor. including 0xFF chip ID.&amp;nbsp;&lt;br /&gt;Could you share the solution you found in the end (spi read and write functions)? or a perhaps a link to a repository with a working example?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/262955?ContentTypeID=1</link><pubDate>Tue, 04 Aug 2020 10:29:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:686ecee2-77eb-4ee2-9dfd-176b7c21329c</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I use Bosch driver, there is no problem at all. Here is my SPI configuration:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define NRF_DRV_SPI_BMI088_DEFAULT_CONFIG                    \
{                                                            \
    .sck_pin      = NRF_DRV_SPI_PIN_NOT_USED,                \
    .mosi_pin     = NRF_DRV_SPI_PIN_NOT_USED,                \
    .miso_pin     = NRF_DRV_SPI_PIN_NOT_USED,                \
    .ss_pin       = NRF_DRV_SPI_PIN_NOT_USED,                \
    .irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY,         \
    .orc          = 0xFF,                                    \
    .frequency    = NRF_DRV_SPI_FREQ_8M,                     \
    .mode         = NRF_DRV_SPI_MODE_0,                      \
    .bit_order    = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,         \
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SPI_INSTANCE_0                  0                                           /**&amp;lt; SPI instance index. */

static const nrf_drv_spi_t spi_0_bmi088 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE_0);     /**&amp;lt; SPI instance. */


nrf_drv_spi_config_t spi_bmi088_config = NRF_DRV_SPI_BMI088_DEFAULT_CONFIG;

nrf_gpio_cfg_output(MCU_GPIO_BMI088_CSB1);
nrf_gpio_cfg_output(MCU_GPIO_BMI088_CSB2);
nrf_gpio_pin_set(MCU_GPIO_BMI088_CSB1);
nrf_gpio_pin_set(MCU_GPIO_BMI088_CSB2);

spi_bmi088_config.ss_pin   = NRF_DRV_SPI_PIN_NOT_USED;
spi_bmi088_config.miso_pin = SPI_BMI088_MISO_PIN;
spi_bmi088_config.mosi_pin = SPI_BMI088_MOSI_PIN;
spi_bmi088_config.sck_pin  = SPI_BMI088_SCK_PIN;
APP_ERROR_CHECK(nrf_drv_spi_init(&amp;amp;spi_0_bmi088, &amp;amp;spi_bmi088_config, spi_bmi088_event_handler, NULL));
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/262947?ContentTypeID=1</link><pubDate>Tue, 04 Aug 2020 10:07:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2eca2ff4-90fb-4208-9fb8-f67a5ed6d322</guid><dc:creator>pradeepyadav</dc:creator><description>&lt;p&gt;Hi june6,&lt;/p&gt;
&lt;p&gt;i got the same issue , i am trying to interface spi nor flash with nRF52840 but not able to read the device ID?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/228261?ContentTypeID=1</link><pubDate>Thu, 09 Jan 2020 07:30:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:351d0edf-b9bf-4d67-9d0a-299562a940e5</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Although I have solved the problem myself, thank you for replying to me!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/227738?ContentTypeID=1</link><pubDate>Mon, 06 Jan 2020 15:20:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6be14ed-0a41-4907-ab7c-3b510ea2394f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Sorry for the long wait.&lt;br /&gt;&lt;br /&gt;The read function should look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int8_t user_spi_read(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    nrfx_err_t ret_code = NRFX_SUCCESS;
    nrfx_spim_xfer_desc_t my_xfer_desc = NRFX_SPIM_XFER_RX(&amp;amp;data, (len + 1));
    
    uint8_t m_tx_buf[MAX_LENGTH];   // create buffer
    memset(&amp;amp;m_tx_buf, 0, sizeof(m_tx_buf)); //clear buffer
    
    m_tx_buf[0] = (1 &amp;lt;&amp;lt; 0) | (reg_addr &amp;lt;&amp;lt; 1);
    
    /* Configure the Chip Select pin, SPIM3 supports HW controlled CS pin*/
    NRF_SPIM3-&amp;gt;PSEL.CSN = cs_pin;
    
    ret_code = nrfx_spim_xfer(&amp;amp;my_spim_instance, my_xfer_desc, flags);
    APP_ERROR_CHECK(ret_code);
    
    return;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/224586?ContentTypeID=1</link><pubDate>Tue, 10 Dec 2019 03:31:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4466285e-586d-4896-9f3f-fac417bc4a34</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;The read function shown seems to be doing a write since the LS bit is &amp;#39;0&amp;#39;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int8_t user_spi_read(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    nrf_gpio_pin_clear(cs_pin);
    nrf_delay_us(1);
    if(len&amp;lt;=255)
    {
        uint8_t m_tx_buf[1] = {0};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I would expect setting the LS bit to &amp;#39;1&amp;#39; would perform a read, but that is either MSB first or LS Bit first, not sure which for this part:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int8_t user_spi_read(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    nrf_gpio_pin_clear(cs_pin);
    nrf_delay_us(1);
    if(len&amp;lt;=255)
    {
        uint8_t m_tx_buf[1] = {0x01}; // if MS Bit first
        uint8_t m_tx_buf[1] = {0x80}; // if LS Bit first&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It would help if you show both initialisation code (use SPI Mode 0) and detail pin connections as this part is not a simple SPI part (eg accelerometer has to be changed from I2C to SPI).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/224584?ContentTypeID=1</link><pubDate>Tue, 10 Dec 2019 02:23:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78367349-e009-4fb1-8383-15bfcad0b76b</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;peripheral\spi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/224011?ContentTypeID=1</link><pubDate>Thu, 05 Dec 2019 16:01:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:657ffe99-af73-4574-8082-5a920fe5ca0b</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Where do you set&amp;nbsp;spi_bmi088_xfer_done after the transfer is complete?&lt;br /&gt;&lt;br /&gt;what SDK and driver are you using?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/223529?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2019 09:50:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecc0f153-e13f-416c-bebb-d7270d45ef7e</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;please reply to me quickly！&lt;/p&gt;
&lt;p&gt;Thanks！&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/223528?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2019 09:49:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:885a0f82-3fba-4891-ae90-ee76c1012996</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Are the above function mapping operations normal?&lt;/p&gt;
&lt;p&gt;Which engineer can answer me？&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/223526?ContentTypeID=1</link><pubDate>Wed, 04 Dec 2019 09:48:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e898063d-846d-4597-aa91-18653071664e</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;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.&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*!
 *  @brief Function for reading the sensor&amp;#39;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 -&amp;gt; Success
 *  @retval &amp;gt;0 -&amp;gt; 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) &amp;amp;&amp;amp; (cs_pin != MCU_GPIO_BMI088_CSB2))
    {
        return -2;
    }
    nrf_delay_us(1);
    if (len &amp;lt;= 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(&amp;amp;m_tx_buf[1], &amp;amp;data, len);

        spi_bmi088_xfer_done = false;

        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi_0, m_tx_buf, m_tx_length, NULL, 0));
        while(!spi_bmi088_xfer_done)
        {
            __WFE();
        }
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;Spi write over length.&amp;quot;);
    }
    nrf_delay_us(1);
    nrf_gpio_pin_set(cs_pin);

    return 0;
}


/*!
 *  @brief Function for writing the sensor&amp;#39;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 -&amp;gt; Success
 *  @retval &amp;gt;0 -&amp;gt; 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) &amp;amp;&amp;amp; (cs_pin != MCU_GPIO_BMI088_CSB2))
    {
        return -2;
    }
    nrf_delay_us(1);
    if (len &amp;lt;= 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(&amp;amp;spi_0, m_tx_buf, m_tx_length, data, m_rx_length));
        while(!spi_bmi088_xfer_done)
        {
            __WFE();
        }
    }
    else
    {
        NRF_LOG_INFO(&amp;quot;Spi read over length.&amp;quot;);
    }
    nrf_delay_us(1);
    nrf_gpio_pin_set(cs_pin);

    return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/223175?ContentTypeID=1</link><pubDate>Tue, 03 Dec 2019 01:24:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a5b03a0-6499-446d-a946-982e4aee08dd</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;I have solved the above problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/222929?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 03:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3579b400-fb95-4de1-b0f9-60772b04412f</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;I try to call bmi08a_init, there is an operation to read the chip ID in this function, but the value read is always 0xFF, (correct 0x1E).&amp;nbsp;Where am I wrong about the mapping of SPI reads and writes?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/222928?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 02:59:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98563037-928b-4e4a-bcc0-d69f15f4c84e</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;SPI timing is&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1575255572435v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Questions about spi read and write function mapping</title><link>https://devzone.nordicsemi.com/thread/222927?ContentTypeID=1</link><pubDate>Mon, 02 Dec 2019 02:57:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e1b4da1-34e1-46b7-bdc3-91d959dacd1a</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;My approach is as follows:&lt;pre class="ui-code" data-mode="c_cpp"&gt;int8_t user_spi_read(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    nrf_gpio_pin_clear(cs_pin);
    nrf_delay_us(1);
    if(len&amp;lt;=255)
    {
        uint8_t m_tx_buf[1] = {0};
        uint8_t m_tx_length = 1;
        uint8_t m_rx_length = (uint8_t)len;
        m_tx_buf[0] = reg_addr;

        // Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, m_rx_length);
        spi_xfer_done = false;

        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, m_tx_length, m_rx_buf, m_rx_length));
        while (!spi_xfer_done)
        {
            __WFE();
        }
        memcpy_fast(data, m_rx_buf, m_rx_length);
    }
    else
    {
        NRF_LOG_DEBUG(&amp;quot;Spi read over length.&amp;quot;);
    }
    nrf_delay_us(1);
    nrf_gpio_pin_set(cs_pin);
}


int8_t user_spi_write(uint8_t cs_pin, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
    nrf_gpio_pin_clear(cs_pin);
    nrf_delay_us(1);
    if(len&amp;lt;=255)
    {
        uint8_t m_tx_buf[255] = {0};
        uint8_t m_length = (uint8_t)len;
        m_tx_buf[0] = reg_addr;
        memcpy(&amp;amp;m_tx_buf[1], data, strlen(data));
  
        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, m_length, m_rx_buf, m_length));
    }
    else
    {
        NRF_LOG_DEBUG(&amp;quot;Spi write over length.&amp;quot;);
    }
    nrf_delay_us(1);
    nrf_gpio_pin_set(cs_pin);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>