<?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 MISO buffer doesn&amp;#39;t fill</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37551/spi-miso-buffer-doesn-t-fill</link><description>Hello, 
 I am using an nRF52840PDK (master) to use an SPI peripheral, where my code is based on examples\peripheral\spi. My IDE is Segger Embedded Studio and I am using SDK 15.0.0. I am using an oscilloscope to visualize the SPI bus activity. 
 I start</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 18 Sep 2018 13:09:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37551/spi-miso-buffer-doesn-t-fill" /><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/149245?ContentTypeID=1</link><pubDate>Tue, 18 Sep 2018 13:09:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa638e2a-57b2-4332-a080-c2dc15a68b31</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I suggest you use GPIOTE driver or app_button library instead of the Board Support Library.&lt;br /&gt;&lt;br /&gt;&amp;quot;&lt;span&gt;Should I only set&amp;nbsp;&lt;/span&gt;&lt;span&gt;SPI_DEFAULT_CONFIG_IRQ_PRIORITY&lt;/span&gt;&lt;span&gt;&amp;nbsp;or also set NRFX_SPIM_DEFAULT_CONFIG_IRQ to a higher priority value, or something different altogether?&amp;quot;&lt;br /&gt;&lt;/span&gt;- I would set both to the same value.&lt;br /&gt;&lt;br /&gt;&amp;quot;&lt;span&gt;Is it correct that&amp;nbsp;&lt;/span&gt;&lt;span&gt;GPIOTE_CONFIG_IRQ_PRIORITY is the relevant IRQ for the BSP handler?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- Yes, I believe so. The BSP uses the app_button library and it uses the GPIOTE peripheral.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;quot;Include the name of the source and/or header file in the driver/library documentation in the infocenter. This way it&amp;#39;s easier to match/find code files to documentation, or the other way around.&amp;quot;&lt;br /&gt;- I agree on this point, right now the library names do not reflect the naming convention&amp;nbsp;used in the SDK.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/148949?ContentTypeID=1</link><pubDate>Mon, 17 Sep 2018 08:24:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efba9ffe-fd14-4ab7-b4e0-ea20899207f9</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;I have found the solution and managed to confirm with &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/38519/spi-event-handler-not-beeing-called/148852#148852"&gt;another thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;It comes down to the interrupt priority not being set correctly. To quote MartinBL:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;It could be an issue with interrupt nesting. It seems like you start the SPI transfer 
from within the BSP event handler. If the SPI has lower interrupt priority than the 
BSP handler, then the SPI handler will not be executed before the BSP handler has 
completed. But since you are effectively waiting for the SPI in the BSP handler you 
end up in a dead lock. &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I have set SPI_DEFAULT_CONFIG_IRQ_PRIORITY to 6. I think the button is configured in GPIOTE_CONFIG_IRQ_PRIORITY which is set to 7.&lt;/p&gt;
&lt;p&gt;Due to this I have a few questions:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Should I only set&amp;nbsp;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;SPI_DEFAULT_CONFIG_IRQ_PRIORITY&lt;/span&gt; or also set NRFX_SPIM_DEFAULT_CONFIG_IRQ to a higher priority value, or something different altogether?&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Is it correct that&amp;nbsp;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;GPIOTE_CONFIG_IRQ_PRIORITY is the relevant IRQ for the BSP handler?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;I also want to do a suggestion:&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Include the name of the source and/or header file in the driver/library documentation in the infocenter. This way it&amp;#39;s easier to match/find code files to documentation, or the other way around.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/148584?ContentTypeID=1</link><pubDate>Thu, 13 Sep 2018 10:39:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67f8ad1c-50a2-47c4-9a64-93294cbccd9a</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;If it turns out I cannot get the code to work in seperate files I will try placing everything in main.c. This would in my opinion be a bad practice, so I will first try to get it to work in peripheral.c. I&amp;#39;m convinced it should be possible.&lt;br /&gt;I actually thought I had changed everything to now use the SPIM driver. I assume you are asking about the SPI driver because I had nrf_drv_spi.h included. I admittedly forgot to include nrfx_spim.h, which I have done now. I have also found that I was still using a few SPI driver types. I have now made the following changes:&lt;br /&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;extern void (*p_spim_event_handler)();        //Changed declaration
void spi_config(void)
{
  nrfx_spim_config_t spim_config = NRFX_SPIM_DEFAULT_CONFIG;
  spim_config.sck_pin = SPIM_SCK_PIN;
  spim_config.miso_pin = SPIM_MISO_PIN;
  spim_config.mosi_pin = SPIM_MOSI_PIN;
  spim_config.ss_pin = SPIM_SS_PIN != NRFX_SPIM_PIN_NOT_USED ? SPIM_SS_PIN : NRFX_SPIM_PIN_NOT_USED;    //Changed PIN_NOT_USED
  spim_config.frequency = SPIM_FREQUENCY;
  APP_ERROR_CHECK(nrfx_spim_init(p_spim_instance, &amp;amp;spim_config, *p_spim_event_handler, NULL));
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;peripheral.h&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;added
#include &amp;quot;nrfx_spim.h&amp;quot;

static void spim_event_handler(nrfx_spim_evt_t const *, void *);        //Added prototype
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;peripheral.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void spim_event_handler(nrfx_spim_evt_t const * p_event,                   //Changed parameter type
                       void *                  p_context)
{
    *p_spi_xfer_done = true;
    NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
    if (m_rx_buf[0] != 0)
    {
        NRF_LOG_INFO(&amp;quot; Received:&amp;quot;);
        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
    }
}
void (*p_spim_event_handler) = &amp;amp;spim_event_handler;

&lt;/pre&gt;&amp;nbsp;(I can edit to include the complete code again)&lt;/p&gt;
&lt;p&gt;There is actually a type &amp;quot;nrfx_spim_evt_handler_t&amp;quot;, but when I use this instead of void I get warnings for incompatible pointer types even though it does work. I have also tried making the event handler static or non-static and eliminating the function pointer.&lt;/p&gt;
&lt;p&gt;Regardless of everything I have tried, I can only make it work when I&amp;#39;m calling the read function from main(), but not when I press a button. Every time I use the button I can see the correct result in m_rx_buf, but the code stays in an infinite loop.&lt;/p&gt;
&lt;p&gt;For good measure I have placed the event handler in main.c without any pointers, removing the calls to the buffer. This shows the exact same behaviour where it works fine when calling the transfer from main(), but not when calling via a button press.&lt;/p&gt;
&lt;p&gt;Unfortunately it is essential for my project to be able to take user input (button) to start a transfer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147811?ContentTypeID=1</link><pubDate>Fri, 07 Sep 2018 12:48:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac047295-0123-4f20-aae1-2858fb170778</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Why do you use the SPI driver and not the SPIM driver?&lt;br /&gt;&lt;br /&gt;The easy fix is to place the code in main.c as I believe it executes&amp;nbsp;as intended when built in that compile unit.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147376?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 12:47:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e56396dc-1cd8-49f0-9a07-d7571cfd33c2</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;I have done single stepping through the driver when calling it from the button event handler before of which I have described the behaviour in a previous comment (4 September 14:43). I have now also tried single stepping through the driver when calling from main which causes it the a &amp;quot;softdevice: assertion failed&amp;quot; error. I assume this is due to timing requirements not being met as a result of single stepping. When I use breakpoints to evaluate specific points in the driver, specifically nrfx_spim.c line 536-540, the code immediately jumps to the spi event handler function. This behaviour seems correct to me.&lt;/p&gt;
&lt;p&gt;So the difference is that after line 540 in nrfx_spim.c I either jump to the infinite while-loop or the spi event handler, using the button event handler or call from main respectively.&lt;/p&gt;
&lt;p&gt;My optimization level for the solution has been set to &amp;quot;none&amp;quot; all the time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147363?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 12:09:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb749e3a-ddd6-4f7e-970a-0eeb19e12064</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;The SPIM driver controls the SS pin when using SPIM0-2.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Have you single stepped through the driver when you called the read function from main loop and compared it to when you called it from the button event handler?&lt;br /&gt;&lt;br /&gt;Have your tried turning off compiler optimization?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147206?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 13:55:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24cd0449-61ef-47b0-a818-115073156c79</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;When calling nrfx_spim_init: p_spi_event_handler = 0x00039e65&lt;/p&gt;
&lt;p&gt;Checking the value of&amp;nbsp;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;void (*p_spi_event_handler) = &amp;amp;spi_event_handler;&lt;/span&gt; in peripheral.h =&amp;nbsp;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;0x00039e65&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The event handler is also being called correctly during writing and continuous reading, just not when using the button to read.&lt;/p&gt;
&lt;p&gt;Sorry about the formatting, things get messed up when copy-pasting.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147205?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 13:48:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02500e3d-4452-481c-8354-e3471ca52cc5</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;I&amp;#39;ve seen &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/37731/nrf52840-spi-easydma-double-buffering"&gt;here &lt;/a&gt;that you note SPIM 0-2 do not have HW SS, while SPIM 3 does. I am however using SPIM0 and can observe SS toggling correctly with above code. It only stays at 0 when I&amp;#39;m also stuck in the infinite-loop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;This is quite confusing. Am I misunderstanding something about HW SS?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147204?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 13:46:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64ff60b9-0913-45e0-ba2c-ce87419e37a7</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;What is the value of&amp;nbsp;p_spi_event_handler when you execute&amp;nbsp;nrfx_spim_init?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147180?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 12:43:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8bb0477-525e-4efc-97cf-13012742bcee</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;Ok, so I have created some pre-processor conditions so I can easily swap between SPI and SPIM. I will show both in case I&amp;#39;ve made a mistake.&lt;/p&gt;
&lt;p&gt;Near the bottom of main() is a for(;;) loop to test continuous reading which works fine. Commenting this out and triggering the same read with a button enters an infinite while-loop in register_read() (peripheral.c). The buffer reflects the correct data, the event handler is simply not being called&lt;/p&gt;
&lt;p&gt;main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Button
#define USBBUTTON_BUTTON                BSP_EVENT_KEY_1                         /**&amp;lt; Button to start search for USB device */
//SPI
#define SPIM_INSTANCE                   0                                       /**&amp;lt; SPI instance index */
#if SPIM_DRIVER
#define SPIM_FREQUENCY                  NRF_SPIM_FREQ_4M                        /**&amp;lt; SPIM frequency */
//#define SPIM_HW_SS                      true                                    /**&amp;lt; SPIM use hardware slave select - only with SPIM3 */
#else
#define SPI_FREQUENCY                   NRF_DRV_SPI_FREQ_4M                     /**&amp;lt; SPI frequency */
#endif
#define SPIM_SCK_PIN                    3                                       /**&amp;lt; SPI_SCK_PIN - pin number */
#define SPIM_MOSI_PIN                   4                                       /**&amp;lt; SPI_SCK_PIN - pin number */
#define SPIM_MISO_PIN                   28                                      /**&amp;lt; SPI_SCK_PIN - pin number */
#define SPIM_SS_PIN                     29                                      /**&amp;lt; SPI_SCK_PIN - pin number */
//#define CUSTOM_SS_PIN                   29                                      /**&amp;lt; CUSTOM_SS_PIN - pin number */

#if SPIM_DRIVER
static const nrfx_spim_t peripheral = NRFX_SPIM_INSTANCE(SPIM_INSTANCE);       /**&amp;lt; SPIM instance */
const nrfx_spim_t *p_spim_instance = &amp;amp;peripheral;
#else
static const nrf_drv_spi_t peripheral = NRF_DRV_SPI_INSTANCE(SPIM_INSTANCE);       /**&amp;lt; SPI instance */
const nrf_drv_spi_t *p_spi_instance = &amp;amp;peripheral;
#endif
static volatile bool spi_xfer_done;                                             /**&amp;lt; Flag used to indicate that SPI instance completed the transfer */


void usb_timers_start(void)     //Triggered on button press
{
  peripheral_read_17();
}

extern void *p_spi_event_handler;
void spi_config(void)
{
#if SPIM_DRIVER
  nrfx_spim_config_t spim_config = NRFX_SPIM_DEFAULT_CONFIG;
  spim_config.sck_pin = SPIM_SCK_PIN;
  spim_config.miso_pin = SPIM_MISO_PIN;
  spim_config.mosi_pin = SPIM_MOSI_PIN;
  spim_config.ss_pin = SPIM_SS_PIN != NRF_DRV_SPI_PIN_NOT_USED ? SPIM_SS_PIN : NRF_DRV_SPI_PIN_NOT_USED;
  spim_config.frequency = SPIM_FREQUENCY;
//  spim_config.use_hw_ss = SPIM_HW_SS;
  APP_ERROR_CHECK(nrfx_spim_init(p_spim_instance, &amp;amp;spim_config, p_spi_event_handler, NULL));
#else
  nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
  spi_config.sck_pin  = SPIM_SCK_PIN;
  spi_config.miso_pin = SPIM_MISO_PIN;
  spi_config.mosi_pin = SPIM_MOSI_PIN;
  spi_config.ss_pin = SPIM_SS_PIN != NRF_DRV_SPI_PIN_NOT_USED ? SPIM_SS_PIN : NRF_DRV_SPI_PIN_NOT_USED;
  spi_config.frequency = SPI_FREQUENCY;
  APP_ERROR_CHECK(nrf_drv_spi_init(p_spi_instance, &amp;amp;spi_config, p_spi_event_handler, NULL));
#endif      //SPIM_DRIVER
  /*Configure GPIO as slave select for SPI*/
  //nrf_gpio_cfg_output(CUSTOM_SS_PIN);
  //nrf_gpio_pin_set(CUSTOM_SS_PIN);
}

static void bsp_event_handler(bsp_event_t event)
{
    ret_code_t err_code;

    switch (event)
    {
        //default cases from example
        //..
        case USBBUTTON_BUTTON:
          usb_timers_start();
          break;
        default:
            break;
    }
}

int main(void)
{
    bool erase_bonds;

    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init(&amp;amp;erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();

    //SPI configuration and initialization
    spi_config();
    //peripheral initialization
    peripheral_init(/*peripheral, */&amp;amp;spi_xfer_done);

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Template example started.&amp;quot;);
    //application_timers_start();
    advertising_start(erase_bonds);

//For testing - Comment this out for button to trigger peripheral_read_17();
for(;;)      //This works normally
{
nrf_delay_ms(500);
  peripheral_read_17();
}


    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;peripheral.h&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifndef PERIPHERAL_H__
#define PERIPHERAL_H__

#include &amp;quot;nrf_drv_spi.h&amp;quot;


#define SPIM_DRIVER       1         /**&amp;lt; SPI driver = 0 - SPIM driver = 1 */

#if SPIM_DRIVER
extern const nrfx_spim_t *p_spim_instance;
#else
extern const nrf_drv_spi_t *p_spi_instance;                                      /**&amp;lt; Pointer to SPI instance */
#endif      //SPIM_DRIVER

#endif  //PERIPHERAL_H__&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;peripheral.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;peripheral.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_drv_spi.h&amp;quot;
#include &amp;lt;stdint.h&amp;gt;

static volatile bool *p_spi_xfer_done;                                           /**&amp;lt; Pointer to SPI_xfer_done flag */
static uint8_t m_tx_buf[2] = {};                                                /**&amp;lt; TX buffer */
static uint8_t m_rx_buf[sizeof(m_tx_buf) + 1];                                  /**&amp;lt; RX buffer */
static const int8_t tx_buf_length = sizeof(m_tx_buf);                               /**&amp;lt; Transfer length */
static const int8_t rx_buf_length = sizeof(m_rx_buf);                               /**&amp;lt; Transfer length */

static void register_read(peripheral_host_registers_t register_to_access, int rx_length)
{
  peripheral_host_result_codes_t result;
  uint8_t command;

  memset(m_tx_buf, 0, tx_buf_length);
  memset(m_rx_buf, 0, rx_buf_length);
  *p_spi_xfer_done = false;

  m_tx_buf[0] = command_byte_set(register_to_access, read);
#if SPIM_DRIVER
  nrfx_spim_xfer_desc_t transfer_descriptor;                                      //SPIM
  transfer_descriptor.p_tx_buffer = m_tx_buf;
  transfer_descriptor.tx_length = 1;
  transfer_descriptor.p_rx_buffer = m_rx_buf;
  transfer_descriptor.rx_length = rx_length + 1;
  APP_ERROR_CHECK(nrfx_spim_xfer(p_spim_instance, &amp;amp;transfer_descriptor, 0));        //SPIM
#else
  APP_ERROR_CHECK(nrf_drv_spi_transfer(p_spi_instance, m_tx_buf, 1, m_rx_buf, rx_length + 1));      //SPI
#endif      //SPIM_DRIVER

  while (!*p_spi_xfer_done)                ////This is an infinite loop
  {
    __WFE();
  }
}

static void register_write(peripheral_host_registers_t register_to_access, uint8_t data, int tx_length)
{
  peripheral_host_result_codes_t result;
  uint8_t command;

  memset(m_tx_buf, 0, tx_buf_length);
  memset(m_rx_buf, 0, rx_buf_length);
  *p_spi_xfer_done = false;

  m_tx_buf[0] = command_byte_set(register_to_access, write);
  m_tx_buf[1] = data;         //append data to buffer

#if SPIM_DRIVER
  nrfx_spim_xfer_desc_t transfer_descriptor;                                      //SPIM
  transfer_descriptor.p_tx_buffer = m_tx_buf;
  transfer_descriptor.tx_length = tx_length + 1;
  transfer_descriptor.p_rx_buffer = m_rx_buf;
  transfer_descriptor.rx_length = 1;
  APP_ERROR_CHECK(nrfx_spim_xfer(p_spim_instance, &amp;amp;transfer_descriptor, 0));        //SPIM
#else
  APP_ERROR_CHECK(nrf_drv_spi_transfer(p_spi_instance, m_tx_buf, tx_length + 1, m_rx_buf, 1));        //SPI
#endif      //SPIM_DRIVER

  while (!*p_spi_xfer_done)
  {
    __WFE();
  }
}

void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    *p_spi_xfer_done = true;
    NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
    if (m_rx_buf[0] != 0)
    {
        NRF_LOG_INFO(&amp;quot; Received:&amp;quot;);
        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
    }
}
void (*p_spi_event_handler) = &amp;amp;spi_event_handler;                   //Function pointer declared in main.c

////Below this is the same as before

void peripheral_init(volatile bool *spi_xfer_done)
{
  p_spi_xfer_done = spi_xfer_done;

  register_init(17, 0, 0, 0, 1, 1, 0, 1, 0);        //creates byte with configuration value (0x1a) and calls register_write
}

static void register_init(peripheral_registers_t register_to_access,
                     uint8_t bit_value7,
                     uint8_t bit_value6,
                     uint8_t bit_value5,
                     uint8_t bit_value4,
                     uint8_t bit_value3,
                     uint8_t bit_value2,
                     uint8_t bit_value1,
                     uint8_t bit_value0)
{
  uint8_t register_value = 0;
  uint8_t bit_value_array[8] = {bit_value0, bit_value1, bit_value2, bit_value3, bit_value4, bit_value5, bit_value6, bit_value7};   //Array and binary MSB/LSB are reverse in order!

  for(int8_t bit_shift = 7; bit_shift &amp;gt;= 0; bit_shift--)
  {
    //Shift configuration bit into the right place of the register value
    register_value |= shift_bit(register_value, bit_value_array[bit_shift], bit_shift);
  }
  register_write(register_to_access, register_value, 1);
}

/**@brief Read register 17 on button press
 * Expected result is 0x1a
 */
void peripheral_read_17(void)
{
  uint8_t result;
  register_read(17, 1);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;When I follow the call to nrfx_spim_xfer (reading) I get up to nrfx_spim.c line 540, this seems to return NRFX_SUCCESS. After this I either enter the infinite while-loop or immediately get an error (softdevice assertion failed &amp;amp; spi_xfer_done symbol not found in watch). I assume getting the error is due to timing not working out after being stuck in the loop for a bit or stepping through the code.&lt;/p&gt;
&lt;p&gt;All of this is with NRFX_SPIM_ENABLED, NRFX_SPIM0_ENABLED, SPI_ENABLED, SPI0_ENABLED, SPI0_USE_EASY_DMA being enabled. The interrupt priorities of these are set to 7.&lt;/p&gt;
&lt;p&gt;Let me know if there is anything else you need to know&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/147115?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 08:39:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38b15a2b-82d8-470e-bfc8-f3af4faeaabc</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;&amp;quot;&lt;span&gt;Is there anything else I could try, or is it not possible to have an SPI transaction being triggered by a button?&amp;quot;&lt;br /&gt;- It is certainly possible.&lt;br /&gt;&lt;br /&gt;Do you mind sharing your updated code and show us where you&amp;#39;re stuck in a loop?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/146976?ContentTypeID=1</link><pubDate>Mon, 03 Sep 2018 12:46:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31e902f3-e99c-4730-827d-61dd27e74b63</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;Thank you for your clear response, but I have not managed to solve it completely yet. The received data now properly reflect in the receive buffer. Despite this I&amp;#39;m still stuck in the infinite loop in register_read().&lt;/p&gt;
&lt;p&gt;I have changed everything SPI related to use the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__nrfx__spim.html&amp;amp;cp=4_0_1_6_9_0_19_0"&gt;SPIM driver&lt;/a&gt;. With this I have had nrf_drv_spi enabled and also disabled (and commented out). I do not see any difference in behaviour between these two. I have also used &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__nrf__drv__spi.html&amp;amp;cp=4_0_1_6_9_0_18_0"&gt;regular SPI&lt;/a&gt;, which yields the same result.&lt;/p&gt;
&lt;p&gt;This infinite loop only occurs when I trigger a transfer by pressing a button. Any transfer started in main(), whether for configuration or repeatedly reading a register, works perfectly normal. I don&amp;#39;t have any timers running anymore to eliminate possibly disruptive sources, so the only difference I can think of is having the button or not. Note that the softdevice is running in every scenario.&lt;/p&gt;
&lt;p&gt;Is there anything else I could try, or is it not possible to have an SPI transaction being triggered by a button?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/146698?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 09:29:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c26efd3-525e-4054-83f0-358a784db987</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Use&amp;nbsp;&lt;a title="nrfx_spim_init" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__nrfx__spim.html?cp=4_0_1_6_9_0_19_0_22#ga1526d58f8151f86a86c38c56b00103ea"&gt;nrfx_spim_init&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a title="nrfx_spim_xfer" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__nrfx__spim.html?cp=4_0_1_6_9_0_19_0_25#gae4b5f522da698ed536ce915ede1216ac"&gt;nrfx_spim_xfer&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;quot;&lt;span&gt;To ensure this I have been commenting the legacy layer SPI&amp;nbsp; configurations in sdk_config.h out. Is this the right way to go?&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-No, not really. You should leave it as is, and enable the SPI instance in the legacy layer SPI of sdk_config.h, I believe the nrfx driver has an #ifdef or two that requires it.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;quot;&lt;span&gt;Lastly, should I create the SPI instance as in the SPI master example (NRF_DRV_SPI_INSTANCE() macro) or the nrfx version?&amp;quot;&lt;br /&gt;&lt;/span&gt;- Yes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I suggest you try this out and verify the implementation by reading the SPIM registers before and after you&amp;#39;ve called&amp;nbsp;&lt;a title="nrfx_spim_xfer" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__nrfx__spim.html?cp=4_0_1_6_9_0_19_0_25#gae4b5f522da698ed536ce915ede1216ac"&gt;nrfx_spim_xfer&lt;/a&gt;&amp;nbsp;(debug session). That way you can see if the SPIM peripheral is set up correctly, and what might be missing, like enabled interrupts, clk frequency, CPOL/CPHA config, RXD/TXD pointers, etc.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/146346?ContentTypeID=1</link><pubDate>Wed, 29 Aug 2018 14:01:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04a357fc-48e1-4f0a-920d-5727bc9ff61e</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;Hello again, sorry for the delay as I&amp;#39;ve had a week off.&lt;/p&gt;
&lt;p&gt;I have looked into using the SPIM peripheral and the examples. Specifically the SPI Master example as I have been using this from the start. It seems to me as if this uses the SPI peripheral making use of the older nrf driver. Is this correct?&lt;/p&gt;
&lt;p&gt;It seems to me as to use SPIM I should also make sure I use the nrfx driver. To ensure this I have been commenting the legacy layer SPI&amp;nbsp; configurations in sdk_config.h out. Is this the right way to go?&lt;/p&gt;
&lt;p&gt;Lastly, should I create the SPI instance as in the SPI master example (NRF_DRV_SPI_INSTANCE() macro) or the nrfx version? I guess this ties into my other questions.&lt;/p&gt;
&lt;p&gt;Is there anything I should specifically watch for to transition to SPIM?&lt;/p&gt;
&lt;p&gt;Edit: I think the best question would be: Can you link the api reference from the infocenter of the SPIM master driver I should be using (&lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__nrf__drv__gpiote.html&amp;amp;cp=4_0_1_6_9_0_5_0"&gt;e.g. this&lt;/a&gt;)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144916?ContentTypeID=1</link><pubDate>Mon, 20 Aug 2018 11:30:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3221485d-6d8e-4d4f-b3de-22925f02f4b8</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I suggest you use the&amp;nbsp;&lt;a title="SPI Master Example" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/spi_master_example.html?cp=4_0_0_4_5_36"&gt;SPI Master Example&lt;/a&gt;&amp;nbsp;or&amp;nbsp;&lt;a title="SPI Transaction Manager Example" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/nrf_spi_mngr_example.html?cp=4_0_0_4_5_39"&gt;SPI Transaction Manager Example&lt;/a&gt;, and use SPIM0-2 as the instance. SPIM3 is the Quad SPI peripheral.&amp;nbsp;&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 MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144749?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 14:05:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d64d0f2-101a-4db1-997e-d146558a6fc4</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;I have a question considering the SPIM peripheral. There are 2 examples, namely&amp;nbsp;&lt;code&gt;\examples\peripheral\spi&lt;/code&gt; and&amp;nbsp;&lt;code&gt;\examples\peripheral\nrfx_spim&lt;/code&gt;. According to the SDK &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fexamples.html&amp;amp;cp=4_0_0_4"&gt;documentation&lt;/a&gt; &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fexamples.html&amp;amp;cp=4_0_0_4"&gt;both&lt;/a&gt; (can) use SPIM, they are considerably different in their setup however. Can it be as easy as changing sdk_config.h to use NRFX_SPIM3_ENABLED instead of SPI0_ENABLED?&lt;/p&gt;
&lt;p&gt;Which should I be using, assuming I only want to transmit data without special interactions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144720?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 12:29:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f0bb58c-16b1-4e04-9f9d-2841ef589f34</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;I have been hesitant to do this since SPI seemed more straight forward without having to worry about easyDMA. I&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt; will try to change it to SPIM.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I am using a timer to start the SPI transfer, I also have 2 other timers running not related to SPI. I have not found anything indicating it, but could this potentially be of influence?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144714?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 12:10:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b99ea994-b015-49ba-bb82-5dce0222e6b1</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;You really should use the SPIM peripheral and not the SPI peripheral, as this will play a lot better with the SoftDevice and the rest of your application.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144679?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 10:14:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b40aa5f-7e02-42c6-abd0-555fcdbf79d6</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;I have tried finding what causes spi_event_handler not to get called in my project. I have set breakpoints at&lt;/p&gt;
&lt;p&gt;- nrf_drv_spi.c line 94&lt;/p&gt;
&lt;p&gt;- nrfx_spi.c line 234, 416 and 423&lt;/p&gt;
&lt;p&gt;None of these breakpoints are getting triggered in my own project when reading registers. They do however trigger when writing registers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144675?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 09:58:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c518b1c-ba6a-4d3d-b7c7-fcf3e84bbb08</guid><dc:creator>KevinL</dc:creator><description>&lt;p&gt;Thank you for your fast reply.&lt;/p&gt;
&lt;p&gt;The if-statement on the slave select pin indeed does nothing. I implemented it when I used a gpio for slave select and still have that code in case I am going to need it in future. That is also why I haven&amp;#39;t removed that condition yet. As I see it it should not cause any problems though.&lt;/p&gt;
&lt;p&gt;1. It has to be properly connected. This is proven by the debug terminal which outputs the 0x19 every time I write a configuration.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;info&amp;gt; app:&amp;nbsp; Received:&lt;br /&gt;&amp;lt;info&amp;gt; app:&amp;nbsp; 19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can also see the spi_xfer_done being toggled using a watch in the debugger.&lt;/p&gt;
&lt;p&gt;2.1. I have loaded the spim example (\examples\peripheral\spi\) onto the board and edited m_tx_buf to {136}.&amp;nbsp;&lt;span style="background-color:transparent;color:#000000;float:none;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;font-style:normal;font-weight:400;letter-spacing:normal;text-align:left;text-decoration:none;text-indent:0px;text-transform:none;white-space:normal;"&gt;Scope shows:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;MOSI [10001000, 11111111] &amp;nbsp;&amp;nbsp; (0x88, 0xFF)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;MISO [00011001, 00000000] &amp;nbsp;&amp;nbsp; (0x19, 0x00)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;The debug terminal doesn&amp;#39;t show anything, but I can see m_rx_buf containing [0x19, 0x00&lt;span style="background-color: transparent; color: #000000; display: inline !important; float: none; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;"&gt;, 0x00&lt;/span&gt;&lt;span style="background-color: transparent; color: #000000; display: inline !important; float: none; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;"&gt;, 0x00&lt;/span&gt;&lt;span style="background-color: transparent; color: #000000; display: inline !important; float: none; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;"&gt;, 0x00&lt;/span&gt;&lt;span style="background-color: transparent; color: #000000; display: inline !important; float: none; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;"&gt;, 0x00&lt;/span&gt;&lt;span style="background-color: transparent; color: #000000; display: inline !important; float: none; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;"&gt;, 0x00&lt;/span&gt;&lt;span style="background-color: transparent; color: #000000; display: inline !important; float: none; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; white-space: normal;"&gt;, 0x00&lt;/span&gt;]. The code also does not get stuck, opposed to my own project.&lt;/p&gt;
&lt;p&gt;2.2. I have copied peripheral.h and peripheral.c almost completely (excluding some irrelevant code) into main.c of the example. Added my configuration of the internal SPI peripheral and initialization of the external peripheral, and substituted the content of the while-loop to let it read a register (1000 ms delay). This is running correctly and I can see the m_rx_buf reflect the data.&lt;/p&gt;
&lt;p&gt;One thing I have noticed here is that it hits a certain breakpoint (nrf_drv_spi_transfer()) 4 times before it continues. On the third time it actually sends and receives as I can see on the scope and rx_buffer watch. I suspect this has something to do with timings. I have not observed this at any point before.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure what to conclude from this. To me it seems the only difference is the code being in 3 files or only main.c to get it to work&lt;/p&gt;
&lt;p&gt;Edit: Thinking about it, my projectis advertising as per examples\ble_peripheral\ble_app_template. I have merged these 2 examples. Maybe this could be of an influence?&lt;/p&gt;
&lt;p&gt;Edit2: To expand on my previous thought. I have added the read to trigger continuously in main() with a 500 ms delay instead of at the press of a button. This works for a few times until I get a &amp;quot;SOFTDEVICE: ASSERTION FAILED&amp;quot; error.&lt;/p&gt;
&lt;p&gt;The button I&amp;#39;m using triggers a timer to execute the reading a few times.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI MISO buffer doesn't fill</title><link>https://devzone.nordicsemi.com/thread/144647?ContentTypeID=1</link><pubDate>Fri, 17 Aug 2018 08:36:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a002bd2-07bb-454c-851b-bcf01ab1bfed</guid><dc:creator>haakonsh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;Is the MISO line connected?&lt;/li&gt;
&lt;li&gt;Does the read function work if you place everything in main.c of the SPIM example?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;quot;P.s.: I think there is a bug where I can&amp;#39;t upload, remove, then reupload a different image with the same name. It will then show the first image again in the editor.&amp;quot;&amp;nbsp;&lt;br /&gt;- yeah we know, I think it will use the new file once you submit the post though.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Also,&amp;nbsp;spi_config.ss_pin = SPI_SS_PIN != NRF_DRV_SPI_PIN_NOT_USED ? SPI_SS_PIN : NRF_DRV_SPI_PIN_NOT_USED; //this if statement does nothing, you might as well just use&amp;nbsp;spi_config.ss_pin = SPI_SS_PIN;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>