<?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>How to make Multiple Transmission and Single Receiver Using NRFx_SPIM Example for NRF52840-DK Board?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39721/how-to-make-multiple-transmission-and-single-receiver-using-nrfx_spim-example-for-nrf52840-dk-board</link><description>Hi, 
 I am Using NRF52840-DK Board. We are trying to transmit multiple data using NRFx_SPIM Example. for single reg read it is working fine. 
 
 please check below code is it correct or not?. 
 
 I am refer below code : 
 
 
 please help me for that.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 Nov 2018 16:27:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39721/how-to-make-multiple-transmission-and-single-receiver-using-nrfx_spim-example-for-nrf52840-dk-board" /><item><title>RE: How to make Multiple Transmission and Single Receiver Using NRFx_SPIM Example for NRF52840-DK Board?</title><link>https://devzone.nordicsemi.com/thread/159095?ContentTypeID=1</link><pubDate>Mon, 26 Nov 2018 16:27:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b037c7f0-413e-4a55-a224-75e9981b948d</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Your images have very low resolution. Can you please post full resolution images?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make Multiple Transmission and Single Receiver Using NRFx_SPIM Example for NRF52840-DK Board?</title><link>https://devzone.nordicsemi.com/thread/158639?ContentTypeID=1</link><pubDate>Thu, 22 Nov 2018 13:16:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d289ce0f-f464-4bf1-bbfa-a9b23c037320</guid><dc:creator>rohit</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for my&amp;nbsp;driver recovery. I have changed the code as per your suggestion. And Its work fine.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I get data in TX and RX buffer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I am a beginner on NRF52840. I am using Nrfx_spim example for interfacing sensor with NRF Board.&lt;/p&gt;
&lt;p&gt;I have done some driver about Reg_read and Reg_write. I tried to read the device ID of the sensor through SPI yielding improper results.&lt;/p&gt;
&lt;p&gt;Hence I probed on the SPI_SCK line and I found that the duty cycle of SPI_SCK is not proper and also set up and hold times are not proper.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In my requirement timing of the SPI should be as in the attached image below.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1542892515468v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To be more specific I need to meet the timing requirements as of detailed in the image below.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1542892515475v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Presently The waveform what I am observing on probing &lt;span&gt;MISO Channel 3 , CS channel 7, SCK&amp;nbsp;&lt;/span&gt;&lt;span&gt;Channel&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;9 and&amp;nbsp;&lt;/span&gt;&lt;span&gt;Channel&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;13 MOSI&lt;/span&gt;&amp;nbsp;is as below.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1542892636452v4.jpeg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am pretty sure that my SPI&amp;nbsp;configurations are not proper, please provide me a pointer where I can do the SPI configurations to meet the timing requirements detailed above.&lt;/p&gt;
&lt;p&gt;Please check my below code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;nrfx_spim.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;
#include &amp;quot;MAX30003.h&amp;quot;


#define NRFX_SPIM_SCK_PIN  3
#define NRFX_SPIM_MOSI_PIN 4
#define NRFX_SPIM_MISO_PIN 28
#define NRFX_SPIM_SS_PIN   29
#define NRFX_SPIM_DCX_PIN  30

#define SPI_INSTANCE  3                                           /**&amp;lt; SPI instance index. */
const nrfx_spim_t spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE);  /**&amp;lt; SPI instance. */

volatile bool spi_xfer_done;  /**&amp;lt; Flag used to indicate that SPI instance completed the transfer. */
uint8_t m_tx_buf[4]; //= {0xff,0x01,0x02}; // ={0x0F}; // 32 bit transfers
uint8_t       m_rx_buf[sizeof(m_tx_buf)];  /**&amp;lt; RX buffer. */
const uint8_t m_length = sizeof(m_tx_buf);        /**&amp;lt; Transfer length. */
nrfx_spim_xfer_desc_t xfer_desc=NRFX_SPIM_XFER_TRX(m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_tx_buf));


void spim_event_handler(nrfx_spim_evt_t const * p_event,
                       void *                  p_context)
{
	

    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));
    }
}
uint8_t MAX30003_Reg_Read(uint8_t Reg_address)
{
  nrfx_err_t err_code = 0;	
  uint32_t data;
  //Prepare the tx buffer
   memset(m_rx_buf, 0x00, sizeof(m_rx_buf)); // Erases the buffer
  m_tx_buf[0] = ((Reg_address &amp;lt;&amp;lt; 1) | 0x01); 
  //Create the transfer descriptor
 // nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_tx_buf));
  //Initiate the transfer
  spi_xfer_done = false;
  err_code = nrfx_spim_xfer(&amp;amp;spi, &amp;amp;xfer_desc, 0);
  APP_ERROR_CHECK(err_code);
  while (spi_xfer_done == false);
  data |= (m_rx_buf[1] &amp;lt;&amp;lt; 16);
  data |= (m_rx_buf[2] &amp;lt;&amp;lt; 8);
  data |= m_rx_buf[3];
  return data;
}

uint8_t MAX30003_Reg_Write(uint8_t Reg_address,  uint32_t data)
{
  nrfx_err_t err_code = 0;	
  //Prepare the tx buffer
  memset(m_rx_buf, 0x00, sizeof(m_rx_buf)); // Erases the buffer
  m_tx_buf[0] = ((Reg_address &amp;lt;&amp;lt; 1) | 0x01); 
//  //Create the transfer descriptor
//   nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_tx_buf));
//  //Initiate the transfer
  spi_xfer_done = false;
  err_code = nrfx_spim_xfer(&amp;amp;spi, &amp;amp;xfer_desc, 0);
  APP_ERROR_CHECK(err_code);
  while (spi_xfer_done == false);
  data |= (m_rx_buf[1] &amp;gt;&amp;gt; 16);
  data |= (m_rx_buf[2] &amp;gt;&amp;gt; 8);
  data |= m_rx_buf[3];
  return data;
}
void max30003_sw_reset(void)
{
    MAX30003_Reg_Write(SW_RST,0x000000);     
    nrf_delay_ms(100);
}

void max30003_synch(void)
{
    MAX30003_Reg_Write(SYNCH,0x000000);
}
void MAX30003_begin()
{    
    max30003_sw_reset();
    MAX30003_Reg_Write(CNFG_GEN, 0x081007);
    nrf_delay_ms(100);
    MAX30003_Reg_Write(CNFG_CAL, 0x720000);  // 0x700000  
    nrf_delay_ms(100);
    MAX30003_Reg_Write(CNFG_EMUX,0x0B0000);
    nrf_delay_ms(100);
    MAX30003_Reg_Write(CNFG_ECG, 0x805000);  // 
    nrf_delay_ms(100);
    MAX30003_Reg_Write(CNFG_RTOR1,0x3fc600);
    max30003_synch();
    nrf_delay_ms(100);
}

int main(void)
{
bsp_board_init(BSP_INIT_LEDS);
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
spi_config.frequency = SPIM_FREQUENCY_FREQUENCY_M1;
spi_config.ss_pin = NRFX_SPIM_SS_PIN;
spi_config.miso_pin = NRFX_SPIM_MISO_PIN;
spi_config.mosi_pin = NRFX_SPIM_MOSI_PIN;
spi_config.sck_pin = NRFX_SPIM_SCK_PIN;
spi_config.dcx_pin = NRFX_SPIM_DCX_PIN;
spi_config.use_hw_ss = true;
spi_config.ss_active_high = false;
spi_config.mode = NRF_SPIM_MODE_0; // SCK active high, sample on leading edge of clock, CPOL=0/CPHA=0
spi_config.bit_order=NRF_SPIM_BIT_ORDER_LSB_FIRST; 
//nrfx_spim_xfer_desc_t xfer_desc=NRFX_SPIM_XFER_TRX(m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_tx_buf));
	
APP_ERROR_CHECK(nrfx_spim_init(&amp;amp;spi, &amp;amp;spi_config, spim_event_handler, NULL));

	NRF_LOG_INFO(&amp;quot;NRFX SPIM example started.&amp;quot;);
while (1)
{
// Reset rx buffer and transfer done flag
memset(m_rx_buf, 0, m_length);
spi_xfer_done = false;
MAX30003_Reg_Read(INFO); //0x0F
APP_ERROR_CHECK(nrfx_spim_xfer_dcx(&amp;amp;spi, &amp;amp;xfer_desc, 0, 15)); 

while (!spi_xfer_done)
{
	
__WFE();
}
NRF_LOG_FLUSH();
bsp_board_led_invert(BSP_BOARD_LED_0);
nrf_delay_ms(200);
}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Expecting your kind help.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Rohit&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make Multiple Transmission and Single Receiver Using NRFx_SPIM Example for NRF52840-DK Board?</title><link>https://devzone.nordicsemi.com/thread/154264?ContentTypeID=1</link><pubDate>Wed, 24 Oct 2018 11:22:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4046ab9-a94a-4d71-8809-0826ebe602df</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;That depends on how you set&amp;nbsp;spi_xfer_done in the SPIM callback handler. Normally you should set it false before transfer, then set it true in the callback. You will then have to loop in the while as long as the flag is not set true. Now you will skip the loop as the flag is not set true (you set it to false right before&amp;nbsp;nrfx_spim_xfer).&lt;/p&gt;
&lt;p&gt;Regarding&amp;nbsp;SPI_TX_Buff, this will depend on how you have declared the variable. If it is declared as a on-byte array, you will have to do it like that. You should then also change declaration of&amp;nbsp;xfer_desc to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(SPI_TX_Buff, sizeof(SPI_TX_Buff), SPI_RX_Buff, sizeof(SPI_TX_Buff));&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make Multiple Transmission and Single Receiver Using NRFx_SPIM Example for NRF52840-DK Board?</title><link>https://devzone.nordicsemi.com/thread/154261?ContentTypeID=1</link><pubDate>Wed, 24 Oct 2018 11:15:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e02d154-cfc1-4f9e-84fb-4ee5b2d4516d</guid><dc:creator>rohit</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the suggestion,&lt;/p&gt;
&lt;p&gt;This is work when I make below changes:&lt;/p&gt;
&lt;p&gt;1) change condition from&amp;nbsp;&lt;span style="text-decoration:underline;"&gt;&lt;strong&gt; while (spi_xfer_done == false)&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/strong&gt;to&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style="text-decoration:underline;"&gt;&lt;strong&gt; while (spi_xfer_done == true);&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;2&lt;span style="text-decoration:underline;"&gt;)&lt;/span&gt;&amp;nbsp;SPI_TX_Buff = ((Reg_address &amp;lt;&amp;lt; 1) | 0x01);&amp;nbsp; to&amp;nbsp; &amp;nbsp;SPI_TX_Buff&lt;strong&gt;[0]&lt;/strong&gt; = ((Reg_address &amp;lt;&amp;lt; 1) | 0x01);&amp;nbsp;&lt;/p&gt;
&lt;p&gt;May I know is it correct?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;rohit&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint8_t MAX30003_Reg_Read(uint8_t Reg_address)
{
  nrfx_err_t err_code = 0;	
  uint32_t data;
  //Prepare the tx buffer
  memset(SPI_RX_Buff, 0x00, sizeof(SPI_RX_Buff)); // Erases the buffer
  SPI_TX_Buff[0] = ((Reg_address &amp;lt;&amp;lt; 1) | 0x01); 
  //Create the transfer descriptor
  nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(&amp;amp;SPI_TX_Buff, sizeof(SPI_TX_Buff), SPI_RX_Buff, sizeof(SPI_TX_Buff));
  //Initiate the transfer
  spi_xfer_done == false;
  err_code = nrfx_spim_xfer(&amp;amp;spi, &amp;amp;xfer_desc, 0);
  APP_ERROR_CHECK(err_code);
  while (spi_xfer_done == true);
  data |= (SPI_RX_Buff[1] &amp;lt;&amp;lt; 16);
  data |= (SPI_RX_Buff[2] &amp;lt;&amp;lt; 8);
  data |= SPI_RX_Buff[3];
  return data;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to make Multiple Transmission and Single Receiver Using NRFx_SPIM Example for NRF52840-DK Board?</title><link>https://devzone.nordicsemi.com/thread/154087?ContentTypeID=1</link><pubDate>Tue, 23 Oct 2018 12:16:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78300080-5d2e-421e-9cf4-ebffc4217c21</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You are over-complicating the transfer. Just create a large enough receive buffer and to the transfer and receive in a single operation.&lt;/p&gt;
&lt;p&gt;Something like this should work:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t SPI_TX_Buff;
uint8_t SPI_RX_Buff[4];

uint32_t MAX30003_Reg_Read(uint8_t Reg_address)
{
  nrfx_err_t err_code = 0;	
  uint32_t data = 0;

  //Prepare the tx buffer
  memset(SPI_RX_Buff, 0x00, sizeof(SPI_RX_Buff)); // Erases the buffer
  SPI_TX_Buff = ((Reg_address &amp;lt;&amp;lt; 1) | 0x01); 

  //Create the transfer descriptor
  nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(&amp;amp;SPI_TX_Buff, sizeof(SPI_TX_Buff), SPI_RX_Buff, sizeof(SPI_TX_Buff));

  //Initiate the transfer
  spi_xfer_done == false;
  err_code = nrfx_spim_xfer(&amp;amp;spi, &amp;amp;xfer_desc, 0);
  APP_ERROR_CHECK(err_code);
  
  while (spi_xfer_done == false);
  
  data |= (SPI_RX_Buff[1] &amp;lt;&amp;lt; 16);
  data |= (SPI_RX_Buff[2] &amp;lt;&amp;lt; 8);
  data |= SPI_RX_Buff[3];
  
  return data;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>