<?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>SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83751/spi-burst-write-fails-on-nrf52832</link><description>I am trying to use the NRF52832 to connect to the BMA456 Accelerometer from Bosch using SPI and am running into the following issue: 
 
 All read/write commands work fine except for the burst write of the configuration file. 
 I decoded every single SPI</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 25 Jan 2022 14:54:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83751/spi-burst-write-fails-on-nrf52832" /><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/349589?ContentTypeID=1</link><pubDate>Tue, 25 Jan 2022 14:54:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ddb75848-68f4-45e2-a6b9-efc30cfcdd54</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you try to analyze the SPI using a logic analyzer that is capable of decoding the output signal?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just to see if the output data equals what you think you are sending?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/348859?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 08:50:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15843846-4f64-4fdb-ab8e-fc742de02574</guid><dc:creator>rayan4444</dc:creator><description>&lt;p&gt;I just looked into this and I&amp;#39;m pretty sure the data is copied in RAM before getting sent:&amp;nbsp;&lt;br /&gt;Unless I missed something?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I can also see the signal on the oscilloscope directly so I know data is going out. I am just confused as to why it seems to get corrupted during the transfer.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int8_t spi_write(uint8_t cs_pin, uint8_t reg_addr, uint8_t *reg_data, uint8_t length)
{
    ret_code_t ret;
    
    // I copy the data in RAM here //
    uint8_t temp_buff[length +1];
    temp_buff[0]=reg_addr;
    memcpy(&amp;amp;temp_buff[1], reg_data, length);

    spi_xfer_done = false;
    ret = nrf_drv_spi_transfer(&amp;amp;spi_instance, temp_buff, length+1, NULL, 0);
    while(!spi_xfer_done)
    {
        __WFE();
    }
    return ret;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/348858?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 08:45:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7e52090-488b-4954-ad76-02e5261f56da</guid><dc:creator>rayan4444</dc:creator><description>&lt;p&gt;In SPI modes 1 and 2 there is no response at all from the sensor, which is normal because it is only compatible with modes 3 and 0. In modes 3 and zero I get the same behaviour:&lt;br /&gt;- I can read and write all commands I need, the only operation that fails is writing the sensor configuration file.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The initialization sequence is the following:&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*!
 * @brief Initialize and configure the BMA accelerometer 
 * @param[in]  bma      : pointer to the BMA struct
 * @param[in]  imu      : the specific IMU we want to initialize
 * @param[in] interrupt : wether we want to tie the interupt pin or not
 */
int8_t bma456_imu_init(struct bma4_dev *bma, bool interrupt){
    printf(&amp;quot;initializing started\n&amp;quot;);
    int8_t ret = BMA4_OK;

    bma-&amp;gt;intf = BMA4_SPI_INTF;                 /*Select SPI Interface */
    bma-&amp;gt;read_write_len = BMA456_READ_WRITE_LEN;   /*! Read/write length */
    bma-&amp;gt;delay_us = user_delay;                     /*! Delay(in microsecond) function pointer */

    /* Function to select interface between SPI and I2C, according to that the device structure gets updated */
    /* THIS WORKS */
    ret = bma4_interface_selection(bma);
    printf(&amp;quot;SS pin: %d\n&amp;quot;, (int)SPI_SS0_PIN);
    printf(&amp;quot;interface: %d\n&amp;quot;, bma-&amp;gt;intf);
    bma4_error_codes_print_result(&amp;quot;bma4_interface_selection status&amp;quot;, ret);

    /* Sensor initialization */
    /* THIS WORKS */
    ret = bma456_init(bma);
    printf(&amp;quot;resolution: %d\n&amp;quot;, bma-&amp;gt;resolution);
    bma4_error_codes_print_result(&amp;quot;bma456_init status&amp;quot;, ret);

    if (ret == 0) { 
        
        printf(&amp;quot;soft reset\n&amp;quot;);
        /*Soft reset*/
        ret = bma4_soft_reset(bma);
        bma4_error_codes_print_result(&amp;quot;bma456 soft reset status&amp;quot;, ret);
    }
    
    /* Upload the configuration file to enable the features of the sensor. */
    /* THIS DOESN&amp;#39;T WORK */
    ret = bma456_write_config_file(bma);
    bma4_error_codes_print_result(&amp;quot;bma456_write_config status&amp;quot;, ret);

    /* Enable the accelerometer */
    /* THIS WORKS */
    ret = bma4_set_accel_enable(BMA4_ENABLE, bma);
    bma4_error_codes_print_result(&amp;quot;bma4_set_accel_enable status&amp;quot;, ret);

    /* Accelerometer configuration settings */
    struct bma4_accel_config accel_conf = { 0 };

    accel_conf.odr = BMA4_OUTPUT_DATA_RATE_100HZ; /* Output data Rate */

    /* Gravity range of the sensor (+/- 2G, 4G, 8G, 16G) */
    accel_conf.range = BMA4_ACCEL_RANGE_16G;

    /* The bandwidth parameter is used to configure the number of sensor samples that are averaged
     * if it is set to 2, then 2^(bandwidth parameter) samples
     * are averaged, resulting in 4 averaged samples
     * Note1 : For more information, refer the datasheet.
     * Note2 : A higher number of averaged samples will result in a less noisier signal, but
     * this has an adverse effect on the power consumed.
     */
    accel_conf.bandwidth = BMA4_ACCEL_NORMAL_AVG4;

    /* Enable the filter performance mode where averaging of samples
     * will be done based on above set bandwidth and ODR.
     * There are two modes
     *  0 -&amp;gt; Averaging samples (Default)
     *  1 -&amp;gt; No averaging
     * For more info on No Averaging mode refer datasheet.
     */
    // accel_conf.perf_mode = BMA4_CONTINUOUS_MODE;
    accel_conf.perf_mode = BMA4_CIC_AVG_MODE;

    /* Set the accel configurations */
    /* THIS WORKS */
    ret = bma4_set_accel_config(&amp;amp;accel_conf, bma);
    bma4_error_codes_print_result(&amp;quot;bma4_set_accel_config status&amp;quot;, ret);

    if (interrupt)
    {
        /* Mapping data ready interrupt with interrupt pin 1 to get interrupt status once getting new accel data */
        ret = bma456_map_interrupt(BMA4_INTR1_MAP, BMA4_DATA_RDY_INT, BMA4_ENABLE, bma);
        bma4_error_codes_print_result(&amp;quot;bma456_map_interrupt status&amp;quot;, ret);
    }
    printf(&amp;quot;init done\n&amp;quot;);

    return ret;    
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You are right, most examples are for i2C, and SPI does require a dummy byte, but that is handled by the bosch API here:&lt;br /&gt;(in fact, I can read data just fine, it&amp;#39;s that specific write operation that fails)&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*!
 *  @brief This API reads the 8-bit data from the given register
 *  in the sensor.
 */
static int8_t read_regs(uint8_t addr, uint8_t *data, uint32_t len, struct bma4_dev *dev)
{
    int8_t rslt;

    /* Check the dev structure as NULL */
    rslt = null_pointer_check(dev);

    if ((rslt == BMA4_OK) &amp;amp;&amp;amp; (data != NULL))
    {
        /* variable used to return the status of communication result*/
        uint32_t temp_len = len + dev-&amp;gt;dummy_byte;
        uint16_t indx;
        uint8_t temp_buff[temp_len];

        if (dev-&amp;gt;intf == BMA4_SPI_INTF)
        {
            /* SPI mask added */
            addr = addr | BMA4_SPI_RD_MASK;
        }

        /* Read the data from the register */
        dev-&amp;gt;intf_rslt = dev-&amp;gt;bus_read(dev-&amp;gt;cs_pin, addr, temp_buff, temp_len);

        if (dev-&amp;gt;intf_rslt == BMA4_INTF_RET_SUCCESS)
        {
            for (indx = 0; indx &amp;lt; len; indx++)
            {
                /* Parsing and storing the valid data */
                data[indx] = temp_buff[indx + dev-&amp;gt;dummy_byte];
            }
        }
        else
        {
            rslt = BMA4_E_COM_FAIL;
        }
    }
    else
    {
        rslt = BMA4_E_NULL_PTR;
    }

    return rslt;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/348567?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 16:16:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da668dd1-8399-4b92-80f9-95b487d08a81</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;At first sight it&amp;#39;s worth checking the memory location of the data you are trying to stream; if it&amp;#39;s the config data note this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;const uint8_t bma456_config_file[] = {&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;const&lt;/em&gt; means this data is in flash memory which will not work with DMA unless first copied to RAM. Put a breakpoint in your &lt;em&gt;spi_write()&lt;/em&gt; function and look at the memory address the buffer is pointing to; if the source address is actually &lt;em&gt;bma456_config_file[]&lt;/em&gt;&amp;nbsp;(or any other const data) then this is the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/348466?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 11:07:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b250f38c-2302-45ab-91bb-9c8631a21d85</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;What is the difference between &amp;quot;don&amp;#39;t work&amp;quot; and &amp;quot;same behavior as the original post&amp;quot;. How does it behave exactly?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have never used this sensor before, nor used the driver that you linked to. What does your&amp;nbsp;bma456_imu_init() look like?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also noticed that most of the README.md is written for I2C. When I searched for SPI I found &lt;a href="https://github.com/BoschSensortec/BMA456-Sensor-API#get-any-motion-interrupt"&gt;this&lt;/a&gt;. Do you use the dummy_read to switch the sensor to SPI?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/348331?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 14:51:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f2726ac-3e6f-4080-993d-c92257b007eb</guid><dc:creator>rayan4444</dc:creator><description>&lt;p&gt;Hello! Thank you for getting back to me :)&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve tried all the SPI modes:&lt;br /&gt;- Modes 1 and 2 don&amp;#39;t work with the sensor (and that is expected, given the datasheet)&lt;br /&gt;- Modes 0 and 3 have the same behavior as the original post&lt;br /&gt;&lt;br /&gt;Is there anything else you&amp;#39;d suggest looking into?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI burst write fails on NRF52832</title><link>https://devzone.nordicsemi.com/thread/348301?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 13:39:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1b5a935-6a9d-4da2-8017-0da4e550a0f5</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The first thing that comes to mind is that you are using the wrong SPI mode. I don&amp;#39;t think the state of the MOSI pin matters when the clock has stopped.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Try changing&amp;nbsp;NRF_DRV_SPI_MODE_0 to&amp;nbsp;NRF_DRV_SPI_MODE_1,&amp;nbsp;NRF_DRV_SPI_MODE_2, or&amp;nbsp;NRF_DRV_SPI_MODE_3. If none of them works, please let me know.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>