<?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>NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123329/nrf5340-spim-turnaround-time</link><description>Hello, 
 I am trying to optimize performance of a series of SPIM transactions using the 5340. Each transaction is 3 bytes long: CSN goes low, clock out 3 bytes, CSN goes high. Only the 3 received bytes matter here, the transmitted bytes are ignored. I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 Sep 2025 18:34:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123329/nrf5340-spim-turnaround-time" /><item><title>RE: NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/thread/549225?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 18:34:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43975c64-fda3-457d-b9ef-c4ad7a32688b</guid><dc:creator>gwan0624</dc:creator><description>&lt;p&gt;Thank you for your time and assistance. I sincerely hope the issue you are dealing with will be resolved soon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/thread/549224?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 18:16:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fa12ad5-f612-4fe9-8bc8-2249483b803b</guid><dc:creator>sheindel-llt</dc:creator><description>&lt;p&gt;I&amp;#39;m not really able to help further dive into details, but you should start with the DPPI documentation in the product spec.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/thread/549221?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 17:36:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4264b445-a1ac-4974-a33a-ade9470628b7</guid><dc:creator>gwan0624</dc:creator><description>&lt;p&gt;Thank you.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve changed the code to use the Device Tree for control instead of GPIO, but the results haven&amp;#39;t improved significantly.&lt;/p&gt;
&lt;p&gt;It seems that manually controlling events using DPPI, rather than the SPI driver, is the correct approach.&lt;/p&gt;
&lt;p&gt;However, I&amp;#39;m not familiar with writing code using DPPI. I also use LLM to write the basic code, but it doesn&amp;#39;t works:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;

#include &amp;lt;zephyr/drivers/uart.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;

#include &amp;lt;nrfx_spim.h&amp;gt;


struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(bme280), SPI_WORD_SET(8) | SPI_TRANSFER_MSB, 0);

static const nrfx_spim_t spim_inst = NRFX_SPIM_INSTANCE(4);
static uint8_t rx_buf0[2];
static uint8_t rx_buf1[2];
static uint8_t tx_cmd_buf[2];
K_SEM_DEFINE(sem_data_ready, 0, 1);
static volatile uint8_t *latest_rx_data_ptr;


void spim_event_handler(nrfx_spim_evt_t const *p_event, void *p_context)
{
    if (p_event-&amp;gt;type == NRFX_SPIM_EVENT_DONE) {
        // 1. main() loop can process the completed buffer
        latest_rx_data_ptr = p_event-&amp;gt;xfer_desc.p_rx_buffer;
        k_sem_give(&amp;amp;sem_data_ready);

        // 2. Immediately start the next transfer (IRQ-based Ping-Pong).
        // The fix is to declare and initialize the struct in one step.
        if (latest_rx_data_ptr == rx_buf0) {
            nrfx_spim_xfer_desc_t next_xfer_desc = NRFX_SPIM_XFER_TRX(tx_cmd_buf, sizeof(tx_cmd_buf), rx_buf1, sizeof(rx_buf1));
            nrfx_spim_xfer(&amp;amp;spim_inst, &amp;amp;next_xfer_desc, 0);
        } else {
            nrfx_spim_xfer_desc_t next_xfer_desc = NRFX_SPIM_XFER_TRX(tx_cmd_buf, sizeof(tx_cmd_buf), rx_buf0, sizeof(rx_buf0));
            nrfx_spim_xfer(&amp;amp;spim_inst, &amp;amp;next_xfer_desc, 0);
        }
        // Note: The call to nrfx_spim_xfer is also moved inside the if/else blocks
        // to respect the scope of next_xfer_desc. We can no longer check its return
        // value easily here, but in an IRQ handler, this is often acceptable.
    }
}

static int rhd_nrfx_spi_transfer_blocking(uint16_t tx_command, uint8_t *rx_buffer)
{
    uint8_t tx_b[2];
    tx_b[0] = (uint8_t)(tx_command &amp;gt;&amp;gt; 8);
    tx_b[1] = (uint8_t)(tx_command &amp;amp; 0xFF);
    nrfx_spim_xfer_desc_t xfer = NRFX_SPIM_XFER_TRX(tx_b, sizeof(tx_b), rx_buffer, 2);
    nrfx_err_t result = nrfx_spim_xfer(&amp;amp;spim_inst, &amp;amp;xfer, 0);
    return (result == NRFX_SUCCESS) ? 0 : -EIO;
}




int main(void)
{
    int err;
    uint8_t rx_main_buffer[2];
    
    printk(&amp;quot;nRF5340 SPIM high-speed example started.\n&amp;quot;);
    
    
    nrfx_spim_config_t spim_config = {
        .sck_pin      = 47, // P1.15
        .mosi_pin     = 46, // P1.14
        .miso_pin     = 45, // P1.13
        .ss_pin       = 44, // P1.12
        .ss_active_high = false,
        .irq_priority = NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY,
        .orc          = 0xFF,
        .frequency    = 16000000UL,
        .mode         = NRF_SPIM_MODE_0,
        .bit_order    = NRF_SPIM_BIT_ORDER_MSB_FIRST,
        .use_hw_ss    = true, 
        .ss_duration  = 2, 
   
    };
    
    
    err = nrfx_spim_init(&amp;amp;spim_inst, &amp;amp;spim_config, spim_event_handler, NULL);
    //for blocking mode 
    
    uint16_t read_cmd = RHD_CMD_READ(0);
    tx_cmd_buf[0] = (uint8_t)(read_cmd &amp;gt;&amp;gt; 8);
    tx_cmd_buf[1] = (uint8_t)(read_cmd &amp;amp; 0xFF);

    nrf_spim_shorts_enable(spim_inst.p_reg, NRF_SPIM_SHORT_END_START_MASK);
    
    nrfx_spim_xfer_desc_t first_xfer_desc = NRFX_SPIM_XFER_TRX(tx_cmd_buf, sizeof(tx_cmd_buf), rx_buf0, sizeof(rx_buf0));

    err = nrfx_spim_xfer(&amp;amp;spim_inst, &amp;amp;first_xfer_desc, 0);
    
    
    
        while (1) {

        k_sem_take(&amp;amp;sem_data_ready, K_FOREVER);

    }
    
    return 0;
}



&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Could you please recommend any reference materials or websites for me?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;&lt;br /&gt;gwan0624&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/thread/549171?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 12:24:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f101fbde-eb06-46f6-9769-bec9c40ba09f</guid><dc:creator>sheindel-llt</dc:creator><description>&lt;p&gt;I would guess your delay is due to manually setting the CS line in the code. It&amp;#39;s probably just the time between the CPU executing the spi_tranceive() and gpio_pin_set_dt().&lt;/p&gt;
&lt;p&gt;To eliminate this you can tell the SPIM to control the CS line directly (I believe there&amp;#39;s some restrictions on which SPI peripherals support this). Look into how the nrfx driver takes the &amp;quot;use_hw_ss&amp;quot; field in one of the parameters to nrfx_spim_init() - I&amp;#39;m not sure if/how this would be done with Zephyr.&lt;/p&gt;
&lt;p&gt;Then, you can set up DPPI to trigger a SPIM START task when a SPIM END event occurs. There is a function&amp;nbsp;nrf_spim_shorts_enable() that handles this for you in the nrf driver, but it&amp;#39;s just setting the right bits in the SHORTS register.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/thread/549131?ContentTypeID=1</link><pubDate>Thu, 18 Sep 2025 08:34:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9587e5e-6a65-4e90-a75e-afcdb46cee1c</guid><dc:creator>gwan0624</dc:creator><description>&lt;p&gt;Dear sheindel-llt,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m also an nRF5340 user experiencing issues with improving SPI4 communication speed.&lt;/p&gt;
&lt;p&gt;However, in my case, I&amp;#39;m seeing a huge delay of about 12us between the CLK and CS signals. (I&amp;#39;ve already posted about this issue, but it hasn&amp;#39;t been resolved yet.)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/123440/nrf5340dk-high-frequency-spim-communication-failure-spi_transceive-delay-problem"&gt;NRF5340DK High frequency SPIM communication failure / spi_transceive() delay problem&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img height="285" src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/1323.pastedimage1754205746226v2.png" width="1137" alt=" " /&gt;&lt;br /&gt;&lt;br /&gt;I was wondering if you might be able to help me with this.&lt;/p&gt;
&lt;p&gt;You mentioned that you set the SPIM END/START short, and I&amp;#39;d like to ask how you implemented that. (In my case, the main code runs in a while loop, which seems to make the code very slow.)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;&lt;br /&gt;gwan0624&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF5340 SPIM turnaround time</title><link>https://devzone.nordicsemi.com/thread/547193?ContentTypeID=1</link><pubDate>Fri, 29 Aug 2025 12:15:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2db857f-7b5e-429b-b419-ba4576ba0b9a</guid><dc:creator>sheindel-llt</dc:creator><description>&lt;p&gt;Just wanted to say I&amp;#39;m still interested in any answers to these questions if anyone knows. I haven&amp;#39;t made any progress on this issue since I posted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>