<?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 problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14673/spi-problem-with-nrf52832-and-mpu-9250</link><description>Hi! 
 I&amp;#39;m trying to get the MPU-9250 chip working through SPI with my nRF52832. But I don&amp;#39;t seem to have much luck. 
 I have created a basic program for testing, based on the peripheral/spi example from the SDK. It&amp;#39;s supposed to make the LED I have</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Jun 2016 10:03:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14673/spi-problem-with-nrf52832-and-mpu-9250" /><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56008?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2016 10:03:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58b30c54-292f-401e-87f1-d7efebdc4809</guid><dc:creator>arne</dc:creator><description>&lt;p&gt;This did the trick! I&amp;#39;m now able to talk to the MPU-9250 over SPI.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56007?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2016 08:01:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bed22293-859c-4c2c-bef9-b3d63edcca67</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Using pins 9 and 10 will cause issues as they are default NFC pins, please see &lt;a href="https://devzone.nordicsemi.com/question/55696/struggling-with-basic-gpio-read-on-nrf52/"&gt;this answer&lt;/a&gt; for how to unset them. Sorry for not noticing this earlier, I was copy pasting your code, but didn&amp;#39;t change the spi_config from the one from my previous answer. As long as you change pins 9 and 10 (sck and mosi) your code compiles and runs successfully on the nRF52 DK, both using Keil and GNU make utility under Windows.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56004?ContentTypeID=1</link><pubDate>Fri, 24 Jun 2016 13:01:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a13bbd20-8668-43af-9010-3e8a604e9776</guid><dc:creator>arne</dc:creator><description>&lt;p&gt;What exactly do you mean by SPI events? If you ask whether or not the spi_event_handler is ran, the answer is no. I believe the code is getting stuck at «__WFE();», waiting for events that isn&amp;#39;t happening.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m compiling on linux using armgcc. Simply by running «make» in the armgcc folder, and I flash the board with «nrfjprog --chiperase --program nrf52832_xxaa.hex &amp;amp;&amp;amp; nrfjprog --reset -f nrf52»&lt;/p&gt;
&lt;p&gt;My LEDs are active high.&lt;/p&gt;
&lt;p&gt;I have not done any changes to nrf_drv_config.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56003?ContentTypeID=1</link><pubDate>Fri, 24 Jun 2016 12:09:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9486e94-0c2f-46ab-9796-79c109ebd601</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Are you getting SPI events now?&lt;/p&gt;
&lt;p&gt;What toolchain are you using?&lt;/p&gt;
&lt;p&gt;Are your LEDs active high or active low?&lt;/p&gt;
&lt;p&gt;Have you done any changes to the nrf_drv_config file found in &lt;code&gt;\examples\peripheral\spi\config\spi_pca10040&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56006?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2016 15:54:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e46a9ea2-fb1d-4704-a6c4-acf12f1ba5a5</guid><dc:creator>arne</dc:creator><description>&lt;p&gt;Great answer, but still not much luck. See the original post for the latest update.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56005?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2016 13:46:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be2a2941-897e-4b35-8050-de4aeb9e6bd2</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you are using the nRF52 DK be aware of a couple of things, LEDs are active low. Pins 7 and 8 are used as CTS and RXD in the UART module and 9 and 10 are used in the NFC module.&lt;/p&gt;
&lt;p&gt;Since the event handler is never called it is likely that either initialization or transfer fails, the event handler will be called even with no SPI device connected. To monitor this you can use APP_ERROR_CHECK along with the information from &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/#60126"&gt;this post&lt;/a&gt; to find which error you are experiencing.&lt;/p&gt;
&lt;p&gt;Doing this we find that both nrf_drv_spi_transfer sometimes fail with the return code NRF_ERROR_BUSY, this happens when the transfer function is called before the previous transfer is finished. When you get a returncode with APP_ERROR_CHECK that is different from NRF_SUCCESS and DEBUG is not defined in the list of preprocessors your application will reset.&lt;/p&gt;
&lt;p&gt;Try the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
{
    nrf_gpio_pin_toggle(17);
    nrf_delay_ms(200);
}

int main(void)
{
    nrf_gpio_cfg_output(17); // CH1, LED used for debug

    nrf_drv_spi_config_t spi_config = {
        .sck_pin        = 13,
        .mosi_pin       = 12,
        .miso_pin       = 11,
        .ss_pin         = 10,
        .irq_priority   = 3,
        .orc            = 0xFF,
        .frequency      = NRF_DRV_SPI_FREQ_125K,
        .mode           = NRF_DRV_SPI_MODE_3,
        .bit_order      = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,
    };

    uint32_t err_code = nrf_drv_spi_init(&amp;amp;spi, &amp;amp;spi_config, spi_event_handler);
    if (err_code != NRF_SUCCESS)
    {
        nrf_gpio_cfg_output(18); //Initialization failed, light LED as warning
    }

    while(1)
    {
        while(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, 1, m_rx_buf, m_length) != NRF_SUCCESS)
        {
            nrf_delay_ms(200); //Wait for the previous transfer to finish
        } 
        __WFE();       
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I also removed the calls to NRF_LOG_PRINTF which will not work unless you initialize the UART module, and changed to different pins. Note that using nrf_delay_ms is not a good way to wait in a final application. nrf_delay_ms uses __NOP to keep the time, this means that the CPU is active causing high current consumption. Implementing a timer is a better solution, for example by using the application timer as shown in &lt;a href="https://devzone.nordicsemi.com/tutorials/19/"&gt;this tutorial&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56001?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2016 10:53:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e1f169f-7fc1-41bf-9997-5def779ec526</guid><dc:creator>arne</dc:creator><description>&lt;p&gt;Hmm no, it doesn&amp;#39;t seem like I get SPI events. My breaking point inside the spi_event_handler isn&amp;#39;t triggered.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI problem with nRF52832 and MPU-9250</title><link>https://devzone.nordicsemi.com/thread/56002?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2016 10:25:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b331e618-22c3-4105-9ee5-65b26f0e1439</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Are you getting SPI events? Try setting breakpoints inside the spi_event_handler and see if they trigger, if so, just add a delay before nrf_gpio_pin_clear(3);. The current implementation will set and then immediately clear the pin.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>