<?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 speed and consistency issues using nRF52840 with ADS131M04EVM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/123017/spi-speed-and-consistency-issues-using-nrf52840-with-ads131m04evm</link><description>Howdy! 
 
 I am attempting to develop a system using an nRF52840 and an ADS131M04EVM (ADC). Our application requires us to collect data at a high sampling rate (&amp;gt;= 16k SPS). According to the ADS131M04 datasheet, this should be well within its possible</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 02 Nov 2025 13:44:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/123017/spi-speed-and-consistency-issues-using-nrf52840-with-ads131m04evm" /><item><title>RE: SPI speed and consistency issues using nRF52840 with ADS131M04EVM</title><link>https://devzone.nordicsemi.com/thread/553094?ContentTypeID=1</link><pubDate>Sun, 02 Nov 2025 13:44:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e89d0000-4eb5-4564-a25a-98309de5dc19</guid><dc:creator>gwan0624</dc:creator><description>&lt;p&gt;I think there is a huge delay using spi_transceive function, which based zephyr ROTS.&lt;br /&gt;&lt;br /&gt;Did you try nrfx spi driver based spi communication? (using nrfx_spim_xfer)&lt;br /&gt;&lt;br /&gt;I also attach some example code:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&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;




/* =================================================================== */

static const nrfx_spim_t spim_inst = NRFX_SPIM_INSTANCE(4);


static uint8_t rx_buf1;
static uint8_t tx_cmd_buf;
K_SEM_DEFINE(sem_data_ready, 0, 1);



static int rhd_nrfx_spi_transfer_blocking(uint16_t tx_command, uint8_t *rx_buffer)
{
    uint8_t tx_b[2]; // for 16 bit communication
    tx_b[0] = (tx_command &amp;gt;&amp;gt; 8) &amp;amp; 0xFF; // MSB
    tx_b[1] = tx_command &amp;amp; 0xFF;        // LSB
    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;
   

    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, NULL, NULL);
	if (err != NRFX_SUCCESS) {
        printk(&amp;quot;NRFx SPIM blocking init failed: %d\n&amp;quot;, err);
        return 0;
    }


    uint8_t rx_main_buffer[2];

    while (1) {

         err = rhd_nrfx_spi_transfer_blocking(0xFF, rx_main_buffer);

    }
    return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI speed and consistency issues using nRF52840 with ADS131M04EVM</title><link>https://devzone.nordicsemi.com/thread/543080?ContentTypeID=1</link><pubDate>Mon, 21 Jul 2025 22:34:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ea27f5c-1971-4b20-9c30-542a89bd2226</guid><dc:creator>BenD</dc:creator><description>&lt;p&gt;Thanks for the suggestions!&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I believe the static buffer suggestion will help with some of the performance, but I have been having some trouble implementing some of your recommended changes and was hoping you could provide some clarification.&lt;br /&gt;&lt;br /&gt;1) As long as I redefine the pins in&amp;nbsp;my overlay file (CS, MISO, MOSI, DRDY, etc.), should I not be able to use any GPIO pins without affecting performance? The PCB we eventually hope to run our code on does not use the standard configuration of the DK for SPI.&lt;br /&gt;&lt;br /&gt;2) For changing the delay of the chip select pin, is this not done by the third argument of SPI_DT_SPEC_GET automatically?&lt;br /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1753136648060v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;3) I tried to set up my code to follow your example as best as I can tell, but there seems to be some discrepancies between your example and the Zephyr documentation. In addition, according to the .yaml file for the ADS131 provided by TI, they want the chip select pin to be in the parent node of the ads131m02 (At one point, I did make a custom .yaml for storing the cs as you did, but that did not seem to be the root problem). The project builds, flashes, and begins running successfully on the board, but it seems to break whenever I try to call spi_transeive() for the first time. I have attached my overlay file and my new main.c file where I have been testing things. Any further guidance you could provide would be greatly appreciated.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1753136965915v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ti_2C00_ads1013.yaml"&gt;devzone.nordicsemi.com/.../ti_2C00_ads1013.yaml&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/84487.main.c"&gt;devzone.nordicsemi.com/.../84487.main.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5554.nrf52840dk_5F00_nrf52840.overlay"&gt;devzone.nordicsemi.com/.../5554.nrf52840dk_5F00_nrf52840.overlay&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI speed and consistency issues using nRF52840 with ADS131M04EVM</title><link>https://devzone.nordicsemi.com/thread/542959?ContentTypeID=1</link><pubDate>Mon, 21 Jul 2025 07:39:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3479f90-28a6-4e9a-b7c5-770e4c418c22</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Benjamin,&lt;/p&gt;
&lt;p&gt;I will try to suggest some changes relevant to PCA10056 (nRF52840 DK). On PCA10056, the&amp;nbsp;ADS131M04EVM’s CS actually sits on P0.28 and the data-ready pin on P0.11 (not P0.15/17). Also change a bit of the code to&amp;nbsp;switch to zero-delay CS toggling and reuse static SPI buffers so we shave a few microseconds each transfer. You dts should have something similar to below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi3 {
    status = &amp;quot;okay&amp;quot;;

    #address-cells = &amp;lt;1&amp;gt;;
    #size-cells    = &amp;lt;0&amp;gt;;

    /* ADS131M04 on SPI3 CS line 0 */
    ads131m02: spidev@0 {
        compatible           = &amp;quot;ti,ads131m04&amp;quot;;
        reg                  = &amp;lt;0&amp;gt;;                     /* CS = SPI3-CS0 */
        spi-max-frequency    = &amp;lt;20000000&amp;gt;;              /* 20 MHz SCLK, reliable under 25 MHz limit */
        cs-gpios             = &amp;lt;&amp;amp;gpio0 28 GPIO_ACTIVE_LOW&amp;gt;;  /* P0.28 wired to ADS131nCS */
        drdy-gpios           = &amp;lt;&amp;amp;gpio0 11 GPIO_ACTIVE_HIGH&amp;gt;; /* P0.11 wired to ADS131nDRDY */
        status               = &amp;quot;okay&amp;quot;;
    };
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Spi setup in your main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#define ADS_NODE   DT_NODELABEL(ads131m02)


static const struct gpio_dt_spec     cs_gpio  = GPIO_DT_SPEC_GET(ADS_NODE, cs_gpios);
static const struct spi_cs_control   cs_ctrl  = {
    .gpio       = CS_GPIO_DEV(&amp;amp;cs_gpio),
    .pin        = CS_GPIO_PIN(&amp;amp;cs_gpio),
    .delay      = 0,   /* no pre-clock delay */
    .hold_delay = 0,   /* release CS immediately after bits */
};

/* Single, static buffers to eliminate per-loop stack setup */
static uint8_t     tx_buf[15];
static uint8_t     rx_buf[15];
static struct spi_buf     tx_buf_desc = { .buf = tx_buf, .len = sizeof(tx_buf) };
static struct spi_buf     rx_buf_desc = { .buf = rx_buf, .len = sizeof(rx_buf) };
static struct spi_buf_set tx = { .buffers = &amp;amp;tx_buf_desc, .count = 1 };
static struct spi_buf_set rx = { .buffers = &amp;amp;rx_buf_desc, .count = 1 };

static const struct spi_dt_spec spi = SPI_DT_SPEC_GET(ADS_NODE,
    SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPHA, 0);

static const struct spi_config spi_cfg = {
    .frequency = DT_PROP(ADS_NODE, spi_max_frequency),
    .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPHA,
    .slave     = DT_REG_ADDR(ADS_NODE),
    .cs        = &amp;amp;cs_ctrl,
};

void sample_loop(void)
{
    size_t   samples = 0;
    bool     ready;

    /* wait for first DRDY to go high */
    while (!gpio_pin_get_dt(&amp;amp;GPIO_DT_SPEC_GET(ADS_NODE, drdy_gpios))) {
        k_busy_wait(5);
    }

    while (samples &amp;lt; NUM_SAMPLES) {

        if (atomic_cas(&amp;amp;ready, true, false)) {
            /* issue 15-byte frame in &amp;lt;8 &amp;#181;s @20 MHz */
            memset(tx_buf, 0, sizeof(tx_buf));
            spi_transceive(spi.bus, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);
            // …decode rx_buf[3..14] into your channel words…
            samples++;
        }
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>