<?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>NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94189/nrf52832---send-and-receive-up-to-300-bytes-via-spi</link><description>Hello, 
 I have 2x PCA10040 dev kits connected via SPI. 
 Device #1 is talking to a custom board MCU by UART 
 Device #2 is connected by BT to my android app 
 The task is to relay communication between the android app and the custom board. Communication</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Dec 2022 14:57:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94189/nrf52832---send-and-receive-up-to-300-bytes-via-spi" /><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/398590?ContentTypeID=1</link><pubDate>Thu, 01 Dec 2022 14:57:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3a9562d-19b0-4766-bdf2-45058caa741f</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The first step would have to be to&amp;nbsp;change your current SPI read/write functions to be non blocking rather than blocking, so that you are able to process button presses and prepare the next SPI packet while the current packet is being transmitted.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The normal way to do this is to implement some kind of state machine, and remove all the steps in your code where you are running a while loop to wait for some event to occur, like the line below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;while (!radio_spi_transfer_finished) // wait for finish&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then you can process and prepare a new buffer while the&amp;nbsp;current&amp;nbsp;one is being transmitted, and as soon as the ongoing transaction is complete you can immediately proceed with the next.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/398270?ContentTypeID=1</link><pubDate>Wed, 30 Nov 2022 09:27:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf74c7a9-8830-4cba-88e0-f03c339978ce</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;How would I go about implementing this buffered communication?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/398269?ContentTypeID=1</link><pubDate>Wed, 30 Nov 2022 09:25:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:178d9ed2-6a0e-4100-8a65-269c5d7f886a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You mean to say you are never able to get bi-directional communication, it will only send in one direction at a time?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It might be for the simple reason that both sides are too responsive. Since the button press on each side is unlikely to be processed at exactly the same time one side will start a transaction before the other one has a new packet ready?&lt;/p&gt;
&lt;p&gt;Alternatively the problem could be that you are not able to prepare a new transaction while the current one is ongoing. If&amp;nbsp;you try to send a new packet on either side while it is currently in the middle of a transaction then the new packet should be buffered, so that as soon as the current transaction is complete you will immediately send the next one. Then you should be able to schedule the communication more efficiently.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/398201?ContentTypeID=1</link><pubDate>Tue, 29 Nov 2022 20:05:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c4595a0-53c1-4b0c-877a-619c72239fe0</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;Ok, the problem was that I forgot the call the&amp;nbsp;nrf_drv_spis_buffers_set at the end of the spi_tx in the slave. Now both sides send and receive OK. The question is how to make it more performant?&lt;br /&gt;I noticed that when i keep pressed both buttons only one of them sends, I would have expected that they both send intermittently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/398087?ContentTypeID=1</link><pubDate>Tue, 29 Nov 2022 12:01:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:298f7189-c4ed-498d-bd2c-82782b09f5a3</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;Thank you for that.&lt;/p&gt;
&lt;p&gt;Meanwhile, I have put together some code,&amp;nbsp;and I would like to know how it can be optimized.&lt;/p&gt;
&lt;p&gt;Master sends to slave.&lt;/p&gt;
&lt;p&gt;Slave sends to master&lt;/p&gt;
&lt;p&gt;but after slave sends to master, master cannot send to slave anymore...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;SPI Slave Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint16_t total_data_length = 0;
/**
 * @brief SPIS user event handler.
 *
 * @param event
 */
void spis_event_handler(nrf_drv_spis_event_t event) {
  if (event.evt_type == NRF_DRV_SPIS_XFER_DONE) {
  uint16_t real_len;
    
  if (!spis_tx_mode)
    {
			
			if(!data_read_pending)		//if this is first/single transaction, 
			{
				total_data_length = bytes_to_u16(m_spi_rx_dma_buf[0],m_spi_rx_dma_buf[1]);		//get the payload size from the first 2 bytes
			}
			if(total_data_length &amp;gt; 250)		//payload size is greater then 250 
			{
				if(!data_read_pending)		//is this the first transaction?
				{
					//this is first transaction
					memcpy(rx_data1, m_spi_rx_dma_buf, 252);
					rx_data_len = total_data_length;
					data_read_pending = true;
				}
				else
				{
					//this is the second transaction
					uint16_t bytes_left = total_data_length - 250;
					memcpy(rx_data1+252, m_spi_rx_dma_buf, bytes_left);
					rx_data_len = total_data_length;
                                        data_read_pending = false;
                                        NRF_LOG_INFO(&amp;quot;cnt: %d, received: %d, one: %X, last %X\n&amp;quot;, rcv_cnt,rx_data_len, rx_data1[0], rx_data1[299]);
                                        rcv_cnt = rcv_cnt+1;
                                        //send_data_ble(rx_data); //here we need to ship this data by bluetooth (complete frame)
				    total_data_length = 0;
				}
			}
			else //payload size less than 250, this is a single transaction
			{
				
				if(!data_read_pending) //we should never have this flag set to true, since this is a single transaction
				{
					memcpy(rx_data1+252, m_spi_rx_dma_buf, total_data_length);
					rx_data_len = total_data_length;
                                        NRF_LOG_INFO(&amp;quot;cnt: %d, received: %d, one: %X, last %X\n&amp;quot;, rcv_cnt,rx_data_len, rx_data1[0], rx_data1[299]);
                                        rcv_cnt = rcv_cnt+1;
                                        //send_data_ble(rx_data); //here we need to ship this data by bluetooth (complete mini-frame)
				    total_data_length = 0;
				}
				else
				{
                                        NRF_LOG_INFO(&amp;quot;CRITICAL FAILURE&amp;quot;); //data_read_pending should never be true for less than 250 bytes frames
					
				}
			}			
			
			nrf_drv_spis_buffers_set(&amp;amp;spis, NULL, 0, m_spi_rx_dma_buf, sizeof m_spi_rx_dma_buf - 1); // problem here
    }

    spis_xfer_done = true;
    
  }
}

/**
 * @brief SPIS TX function.
 *
 * @param event
 */
uint32_t spi_tx(uint8_t *data, uint32_t len) {
  uint32_t err_code;
  int i = 0;
  spis_tx_mode = 1;
  // check how many packets need to be sent if we send only 1 packet at a time with max size of 250 bytes
  uint8_t total_packets = 0; // total packets to send
  uint8_t packet_len = 0;
  if (len &amp;gt; 250) {
    total_packets = 2;
    packet_len = 250;
  } else {
    total_packets = 1;
    packet_len = len;
  }

  while (i &amp;lt; total_packets) {
    // split each packet and send
    uint8_t a = 0;
    uint8_t packet_to_send[255];
    if (i == 0) {
      // add the headers
      for (a = 0; a &amp;lt; packet_len; a++) {
        // keep space for headers in the first transaction
        packet_to_send[a + 2] = data[(i * 250) + a];
      }
    } else {
      for (a = 0; a &amp;lt; packet_len; a++) {
        // do not add any headers
        packet_to_send[a] = data[(i * 250) + a];
      }
    }
    i++;
    if (i != total_packets) {
      // add packet length in the first 2 bytes
      packet_to_send[0] = len &amp;gt;&amp;gt; 8;
      packet_to_send[1] = len;
    }
    // send the packet
    spis_xfer_done = false;
    if (i != total_packets) {
      // if its the first transaction, add 2 bytes count in the packet length
      err_code = nrf_drv_spis_buffers_set(&amp;amp;spis, packet_to_send, packet_len + 2, NULL, 0); // length byte + data
      VERIFY_SUCCESS(err_code);
    } else {
      err_code = nrf_drv_spis_buffers_set(&amp;amp;spis, packet_to_send, packet_len, NULL, 0); // length byte + data
      VERIFY_SUCCESS(err_code);
    }
    // NRF_LOG_INFO(&amp;quot;Prepared %i bytes&amp;quot;, packet_len);
    if (i == 1) {
      nrf_gpio_pin_set(CUSTOM_SPI_IRQ_PIN);
      nrf_delay_us(100);
      nrf_gpio_pin_clear(CUSTOM_SPI_IRQ_PIN);
    }
    while (!spis_xfer_done) {
      __WFE();
    }
    int d = 0;
    // calculate next data length
    if (i == total_packets) {
      // all data is sent
    } else if ((total_packets - i) == 1) {
      // only one packet left
      packet_len = len - 250;
    }
  }
  spis_tx_mode = 0;

  return NRF_SUCCESS;
}

/**
 * @brief Send data via bluetooth.
 *
 * @param payload
 */

void send_data_ble(uint8_t *payload, uint8_t size) {
  uint32_t err_code;
  do {
    uint16_t length = size;
    uint32_t err_code = ble_nus_data_send(&amp;amp;m_nus, payload, &amp;amp;length, m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
        (err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
        (err_code != NRF_ERROR_NOT_FOUND)) {
      APP_ERROR_CHECK(err_code);
    }
  } while (err_code == NRF_ERROR_RESOURCES);
}

/**@brief Application main function.
 */
int main(void) {

  nrf_gpio_pin_dir_set(CUSTOM_SPI_IRQ_PIN, NRF_GPIO_PIN_DIR_OUTPUT);
  nrf_gpio_pin_clear(CUSTOM_SPI_IRQ_PIN);

  // Initialize.
  log_init();
  timers_init();
  power_management_init();
  ble_stack_init();
  gap_params_init();
  gatt_init();
  services_init();
  advertising_init();
  conn_params_init();
  // nrf_gpio_cfg_output(8);

  // Enable the constant latency sub power mode to minimize the time it takes
  // for the SPIS peripheral to become active after the CSN line is asserted
  // (when the CPU is in sleep mode).
  // NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1;

  nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
  spis_config.csn_pin = APP_SPIS_CS_PIN;
  spis_config.miso_pin = APP_SPIS_MISO_PIN;
  spis_config.mosi_pin = APP_SPIS_MOSI_PIN;
  spis_config.sck_pin = APP_SPIS_SCK_PIN;
  spis_config.orc = 0x55; // this one
  spis_config.bit_order = 1;
  uint32_t err_code;
  APP_ERROR_CHECK(nrf_drv_spis_init(&amp;amp;spis, &amp;amp;spis_config, spis_event_handler));
  err_code = nrf_drv_spis_buffers_set(&amp;amp;spis, NULL, 0, m_spi_rx_dma_buf, sizeof m_spi_rx_dma_buf - 1); // problem here
  VERIFY_SUCCESS(err_code);

  advertising_start();

  err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, 4); // increase power to maximum
  APP_ERROR_CHECK(err_code);
  uint8_t spi_test_payload[] = {0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
      0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
      0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77,
      0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
      0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
      0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44};

  // Enter main loop.
  uint8_t small_payload[14] = {0x2f, 0x38, 0xEF, 0xAB, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11};

  NRF_LOG_INFO(&amp;quot;Slave SPI Started!&amp;quot;);
  while (1) {

         if(!nrf_gpio_pin_read(BUTTON_1))
       {
            nrf_delay_ms(150);
            if(!nrf_gpio_pin_read(BUTTON_1))
            {
               spi_tx(spi_test_payload, 300);
            }
       }

  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;SPI Master Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static volatile uint8_t radio_spi_transfer_finished = 0;
static void radio_spi_handler(nrfx_spi_evt_t const *p_event, void *p_context) {
  radio_spi_transfer_finished = 1;
}

uint32_t radio_is_ready_to_read() {
  nrf_gpio_cfg(SPIRADIO_IO1,
      NRF_GPIO_PIN_DIR_INPUT,
      NRF_GPIO_PIN_INPUT_CONNECT,
      NRF_GPIO_PIN_PULLDOWN,
      NRF_GPIO_PIN_S0S1,
      NRF_GPIO_PIN_NOSENSE);

  return nrf_gpio_pin_read(SPIRADIO_IO1);
}

uint32_t radio_spi_read(uint8_t *dst, uint32_t dstlen) {
  uint16_t rx_data_len = 0;
  memset(dst, 0xFF, dstlen); // sanitize the buffer



  /***********************FIRST READ*************************************/
  nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_RX(dst, 252);

  flash_spi_transfer_finished = 0;
  if (NRFX_SUCCESS != nrfx_spim_xfer(&amp;amp;radio_spi, &amp;amp;xfer_desc, 0)) {
    NRF_LOG_INFO(&amp;quot;SPI READ FAILED!&amp;quot;);
    return 0;
  }

  while (!radio_spi_transfer_finished)
    ;
  /*********************************************************************/

  nrf_delay_us(500);
  uint16_t total_data_length = bytes_to_u16(dst[0], dst[1]);
  if (total_data_length &amp;gt; 250) // need to read more data in case its more then 250 bytes?
  {
    uint16_t bytes_left = total_data_length - 250;
    nrf_delay_ms(1); // give some delay so that slave can easily prepare the next packet
  /***********************SECOND READ (OPTIONAL)*************************************/
  nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_RX(dst+252, total_data_length-252);

  flash_spi_transfer_finished = 0;
  if (NRFX_SUCCESS != nrfx_spim_xfer(&amp;amp;radio_spi, &amp;amp;xfer_desc, 0)) {
    NRF_LOG_INFO(&amp;quot;SPI READ FAILED!&amp;quot;);
    return 0;
  }

  while (!radio_spi_transfer_finished)
    ;
  /************************************************************************************/
    nrf_delay_us(500);
    rx_data_len = total_data_length;
  } else {
    rx_data_len = total_data_length;
  }

  NRF_LOG_INFO(&amp;quot;received: %d, one: %X, last %X\n&amp;quot;, rcv_cnt, rx_data_len, dst[0], dst[299]);

  return dstlen;
}




/***************************************  FUNCTION TO WRITE SPI DATA ******************************************/
uint32_t radio_spi_write(uint8_t *data, uint32_t len) {
  uint32_t err_code;
  int i = 0;
  // check how many packets need to be sent if we send only 1 packet at a time with max size of 250 bytes
  uint8_t total_packets = 0; // total packets to send
  uint8_t packet_len = 0;
  if (len &amp;gt; 250) {
    total_packets = 2;
    packet_len = 250;
  } else {
    total_packets = 1;
    packet_len = len;
  }

  while (i &amp;lt; total_packets) {
    // split each packet and send
    uint8_t a = 0;
    uint8_t packet_to_send[255];
    if (i == 0) {
      // add the headers
      for (a = 0; a &amp;lt; packet_len; a++) {
        // keep space for headers in the first transaction
        packet_to_send[a + 2] = data[(i * 250) + a];
      }
    } else {
      for (a = 0; a &amp;lt; packet_len; a++) {
        // do not add any headers
        packet_to_send[a] = data[(i * 250) + a];
      }
    }
    i++;
    if (i != total_packets) {
      // add packet length in the first 2 bytes
      packet_to_send[0] = len &amp;gt;&amp;gt; 8;
      packet_to_send[1] = len;
    }
    // send the packet
    radio_spi_transfer_finished = false;
    if (i != total_packets) {
      // if its the first transaction, add 2 bytes count in the packet length
      nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(packet_to_send, packet_len + 2, NULL, 0);

      if (NRFX_SUCCESS != nrfx_spim_xfer(&amp;amp;radio_spi, &amp;amp;xfer_desc, 0)) {
        NRF_LOG_INFO(&amp;quot;SPI WRITE FAILED!&amp;quot;);
        return 1;
      }
    } else {
      nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(packet_to_send, packet_len, NULL, 0);

      if (NRFX_SUCCESS != nrfx_spim_xfer(&amp;amp;radio_spi, &amp;amp;xfer_desc, 0)) {
        NRF_LOG_INFO(&amp;quot;SPI WRITE FAILED!&amp;quot;);
        return 1;
      }
    }

    while (!radio_spi_transfer_finished) // wait for finish
      ;
    nrf_delay_ms(3);

    int d = 0;
    // calculate next data length
    if (i == total_packets) {
      // all data is sent
    } else if ((total_packets - i) == 1) {
      // only one packet left
      packet_len = len - 250;
    }
  }

  return NRF_SUCCESS;
}

//****************************************************************************************************//

void radio_spi_init() {
  nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
  spi_config.frequency = NRF_SPIM_FREQ_4M;
  spi_config.ss_pin = SPIRADIO_CS;
  spi_config.miso_pin = SPIRADIO_MISO;
  spi_config.mosi_pin = SPIRADIO_MOSI;
  spi_config.sck_pin = SPIRADIO_SCK;
  spi_config.bit_order = NRF_SPI_BIT_ORDER_LSB_FIRST;
  spi_config.ss_active_high = false;
  spi_config.orc = 0x5A;
  APP_ERROR_CHECK(nrfx_spim_init(&amp;amp;radio_spi, &amp;amp;spi_config, radio_spi_handler, NULL));
}




  //////////////////MAIN LOOP/////////////////
  memset(spi_buffer, 0, sizeof(spi_buffer));
  nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP);   //for devboard testing
  while(1){

       if(!nrf_gpio_pin_read(BUTTON_1))
       {
            nrf_delay_ms(150);
            if(!nrf_gpio_pin_read(BUTTON_1))
            {
               radio_spi_write(spi_test_payload, sizeof spi_test_payload); 
            }
       }

                
if(radio_is_ready_to_read() == 1) 
		{
                    uint8_t rx_data1[320];
                    radio_spi_read(rx_data1, 320);
		}


  }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Looking forward to your reply.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397894?ContentTypeID=1</link><pubDate>Mon, 28 Nov 2022 13:56:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbcfc864-c2b1-4ca6-a42a-b74a6374af17</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;This code shouldn&amp;#39;t have to be much more complicated than the code you&amp;#39;ve already written, but I don&amp;#39;t mind writing a small example for it, Christmas or not &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f609.svg" title="Wink"&gt;&amp;#x1f609;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll try to have it done by the end of the week.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397730?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2022 20:18:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67a8d91f-58e5-40f5-8acf-d68c148f7661</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;Ok, this is way above my coding capabilities. Is there any way someone your team can write some some sample code for this? I am sure it will benefit many users who want to use SPI on any device other than nrf52840.&lt;/p&gt;
&lt;p&gt;Time to get into the Christmas spirit and give the gift of code to the community.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397681?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2022 14:41:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc3a7ad6-e342-4346-8314-508fa819ddda</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That is a bit less straight forward. It is the master that decides how many bytes to clock out, which the slave would have to tell it somehow.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is another argument for including the packet length as the first bytes of the message.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then you could have a basic approach like this:&lt;/p&gt;
&lt;p&gt;1) IRQ pin is asserted by the slave&lt;/p&gt;
&lt;p&gt;2) The master sets the chip select pin low and starts a 2 byte transaction to read the length&lt;/p&gt;
&lt;p&gt;3) Based on the length the master sets up the second transaction, to pick up the data (for the slave this looks like a continuation of the first transaction, since chip select was kept low)&lt;/p&gt;
&lt;p&gt;4) The master sets the chip select pin high&lt;/p&gt;
&lt;p&gt;5) If the data length was &amp;gt; 253 bytes, the spi master sends another command to pick up the remaining bytes&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397577?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2022 09:31:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39fab8fa-a58f-480e-ae74-7076ee6f721c</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;will this work for bi-directional transfers? master send to slave and slave send to master (using irq pin)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397569?ContentTypeID=1</link><pubDate>Fri, 25 Nov 2022 09:21:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2c1f61e-1bd2-4578-ac14-a19bc58cb4c4</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That was more or less my original idea, but I think I might have come up with a better one:&lt;/p&gt;
&lt;p&gt;Rather than adding header bytes or similar to your data it is possible to simply use the length of the packet as an indication whether or not there is another packet coming.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Essentially if you receive a packet that is 255 bytes long then you assume that the real message is longer, and that the next packet will have to be appended to the first.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The advantage of this method is that you&amp;nbsp;don&amp;#39;t need to manually append the data from the two packets, since you can just set the EasyDMA pointer of the SPI slave to the right place in the buffer for the second transaction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The only special case here is if you ever need to send a packet that is exactly 255 bytes long, since that would cause the SPI slave to assume another transaction was coming.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;To solve this issue you either need to send a 1 byte dummy packet after the 255 byte transaction, to wrap it up, or you need to include a length field or something at the start of the first packet so the SPI slave can tell whether or not the second packet is needed (similar to the first suggestion, but if you only include the header on the first packet you can still append the two packets seamlessly without requiring a memcpy).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397498?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2022 16:09:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bd8d16a-1131-494b-b0d5-5e7822956f94</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;So basically creating a global 300 bytes buffer and a bool called &amp;quot;complex_transaction&amp;quot;.&lt;br /&gt;When IRQ triggers, if first byte of the payload is 254, complex_transaction will be set to true and the next transaction will be automatically appended to the buffer after the first one.&lt;br /&gt;&lt;br /&gt;Does that sound right to you? How do you see it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397496?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2022 16:03:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:241db684-c259-4a27-aa80-573a8a365708</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry about that, I read PCA10040 and thought of the 52840 for some reason...&lt;/p&gt;
&lt;p&gt;Unfortunately that trick won&amp;#39;t really work with the nRF52832, since both the SPIM and SPIS interfaces are limited to 255 bytes maximum.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think you need to split the update into two separate transactions, and possibly use a header byte or similar at the start of the transaction to signify whether or not there are more transactions coming which should be appended to the first.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then&amp;nbsp;you need to compile the two transaction into a single message on the receiving end, before passing it along to other parts of the system.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think we have any examples showing this exact procedure, but&amp;nbsp;you basically just need to send two transactions in succession whenever the payload in question is larger than 255 bytes (or larger than 254, if you use 1 byte for the header).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397487?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2022 15:30:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:051809b8-8748-4150-9920-aa1ac39ac520</guid><dc:creator>nordicfreak</dc:creator><description>&lt;p&gt;Thank you for the reply.&lt;/p&gt;
&lt;p&gt;Yes, as stated in the subject of my question, I am using nrf52832.&lt;/p&gt;
&lt;p&gt;So the trick with keeping the line low will work for the 52832 also?&lt;/p&gt;
&lt;p&gt;If not, what are my alternatives? Any example code?&lt;/p&gt;
&lt;p&gt;Please note, the communication must be bi-directional, and it can happen in either direction at any arbitrary time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52832 - Send and receive up to 300 bytes via SPI</title><link>https://devzone.nordicsemi.com/thread/397486?ContentTypeID=1</link><pubDate>Thu, 24 Nov 2022 15:28:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abdbb76a-afd1-4f94-a367-9e9794d66c89</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When it comes to SPI the chip select line is used to signal the start and end of a transaction, so as long as you don&amp;#39;t pull the chip select low for each transaction, but pull it low for the duration of both transactions, the slave should read it as one transaction.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With that being said, there is no 256 byte limit on the SPIM or SPIS interfaces in the nRF52840.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you take a look at the TXD or RXD MAXCNT registers (like &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/spim.html?cp=4_0_0_5_24_5_24#register.TXD.MAXCNT"&gt;this one&lt;/a&gt;) you will see that they can be as large as 0xFFFF, or 65535 bytes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Most likely you are thinking of the nRF52832, which was the first device in the nRF52 series, and was a bit more limited in terms of how large EasyDMA buffers you could use.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>