<?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>The problem of SPI communication initiated by external interrupt using PPI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71342/the-problem-of-spi-communication-initiated-by-external-interrupt-using-ppi</link><description>Hi, Nordicsemi 
 At present, although SPI uses easy DMA when reading and sending data, in the actual use scenario, I still use gpiote to detect the interrupt pin of the sensor, and polling the flag bit of the interrupt signal in the main program to trigger</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 10 Feb 2021 06:28:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71342/the-problem-of-spi-communication-initiated-by-external-interrupt-using-ppi" /><item><title>RE: The problem of SPI communication initiated by external interrupt using PPI</title><link>https://devzone.nordicsemi.com/thread/293669?ContentTypeID=1</link><pubDate>Wed, 10 Feb 2021 06:28:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0076f65c-fa81-4116-872d-01ac28108200</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Thank you for your answer. I&amp;#39;ve solved it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The problem of SPI communication initiated by external interrupt using PPI</title><link>https://devzone.nordicsemi.com/thread/293585?ContentTypeID=1</link><pubDate>Tue, 09 Feb 2021 14:25:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b3c26d9-96bd-4798-921d-358e68c35ee4</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;Hi, haakonsh.&lt;/p&gt;
&lt;p&gt;Now I have added a part of the program as follows&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define BUFFER_SIZE  4

typedef struct ArrayList {
  uint8_t buffer[BUFFER_SIZE];
} ArrayList_type;

SPI0ArrayList[0].buffer[0] = 0x0F;
nrf_spim_tx_buffer_set(spi_0.u.spim.p_reg, SPI0ArrayList[0].buffer, 1);
nrf_spim_rx_buffer_set(spi_0.u.spim.p_reg, SPI0ArrayList[1].buffer, 2);
nrf_spim_event_clear(spi_0.u.spim.p_reg, NRF_SPIM_EVENT_END);
nrf_spim_tx_list_enable(spi_0.u.spim.p_reg);
nrf_spim_rx_list_enable(spi_0.u.spim.p_reg);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this way, when receiving the gpiote external interrupt, can we read the sensor&amp;#39;s 0x0f register and save the read data to SPI0ArrayList[1].buffer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The problem of SPI communication initiated by external interrupt using PPI</title><link>https://devzone.nordicsemi.com/thread/293190?ContentTypeID=1</link><pubDate>Sat, 06 Feb 2021 03:49:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:560be260-2d19-4c3e-8c11-4ceb043741be</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;At present, I have used PPI to associate gpiote event address with SPI task start address.&amp;nbsp;But I still have a little doubt.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The program code is as follows&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void in_pin_handler(nrf_drv_gpiote_pin_t pin,
                           nrf_gpiote_polarity_t action) {
  if (pin == MCU_GPIO_INT)
}

ret_code_t gpiote_init(ppi_addr_t *addr) {
  ret_code_t err_code;

  if (!nrf_drv_gpiote_is_init()) {
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
  }
  nrf_drv_gpiote_in_config_t in_config_0 = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
  in_config_0.pull = NRF_GPIO_PIN_PULLUP;

  /* When configuration conversion occurs, no callback is generated and PPI is
   * used instead */
  err_code = nrf_drv_gpiote_in_init(MCU_GPIO_INT, &amp;amp;in_config_0, in_pin_handler);
  APP_ERROR_CHECK(err_code);

  nrf_drv_gpiote_in_event_enable(MCU_GPIO_INT, true);
  addr-&amp;gt;gpiote_evt_addr = nrf_drv_gpiote_in_event_addr_get(MCU_GPIO_INT);

  return NRF_SUCCESS;
}

static void spi_event_handler(nrf_drv_spi_evt_t const *p_event,
                                     void *p_context) {
  spi_xfer_done = true;
}

uint32_t spi_init(ppi_addr_t *addr) {
  if (!spi_init_flag) {
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin = SPI_CS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin = SPI_SCK_PIN;

    APP_ERROR_CHECK(
        nrf_drv_spi_init(&amp;amp;spi_0, &amp;amp;spi_config, spi_event_handler, NULL));

    x = addr-&amp;gt;spi_task_addr = nrf_drv_spi_start_task_get(&amp;amp;spi_0);

    spi_init_flag = true;

    return 0;
  } else {
    // TODO Define return value
    return 1;
  }
}

uint32_t ppi_init(ppi_addr_t *addr) {
  uint32_t err_code;
  uint32_t evt_addr, task_addr;
  nrf_ppi_channel_t ppi_channel;

  err_code = nrf_drv_ppi_init();
  APP_ERROR_CHECK(err_code);

  evt_addr = addr-&amp;gt;gpiote_evt_addr;
  task_addr = addr-&amp;gt;spi_task_addr;

  err_code = nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_ppi_channel_assign(ppi_channel, evt_addr, task_addr);
  APP_ERROR_CHECK(err_code);

  // Enable configured PPI channel
  err_code = nrf_drv_ppi_channel_enable(ppi_channel);
  APP_ERROR_CHECK(err_code);

  return NRF_SUCCESS;
}

int main(void) {
  APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
  NRF_LOG_DEFAULT_BACKENDS_INIT();
  lfclk_init();
  timers_init();
  UNUSED_VARIABLE(nrf_mem_init());
  spi_init(&amp;amp;ppi_addr);
  gpiote_init(&amp;amp;ppi_addr);
  ppi_init(&amp;amp;ppi_addr);
  NRF_LOG_INFO(&amp;quot;SPI example started.&amp;quot;);

  while (1) {
    loop_operation();
    NRF_LOG_FLUSH();
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I found that as long as there is an external interrupt signal, SPI will generate an event handler. Can this indicate that the association has been successful?&lt;/p&gt;
&lt;p&gt;Next, when there is an external interrupt signal, how to let the hardware read data by SPI without the participation of MCU?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The problem of SPI communication initiated by external interrupt using PPI</title><link>https://devzone.nordicsemi.com/thread/293067?ContentTypeID=1</link><pubDate>Fri, 05 Feb 2021 11:18:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d9ab20d-ea7f-4741-b8e9-522f92940edd</guid><dc:creator>June6</dc:creator><description>&lt;p&gt;When there is an external interrupt signal, I only need to perform the operation of reading one register of the external sensor, and I do not want to affect the other parts.&amp;nbsp;Does this mean I need to turn off PPI and clear all event and task addresses when I don&amp;#39;t want to do this？&lt;/p&gt;
&lt;p&gt;And, is the module used by the SPI in the peripheral routine a SPIM module?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: The problem of SPI communication initiated by external interrupt using PPI</title><link>https://devzone.nordicsemi.com/thread/293060?ContentTypeID=1</link><pubDate>Fri, 05 Feb 2021 10:53:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e9f874d-6e5a-4ee1-a384-60b85abfd27a</guid><dc:creator>haakonsh</dc:creator><description>[quote user=""]Can I use PPI module to trigger SPI read / write task with gpiote interrupt event as trigger condition?[/quote]
&lt;p&gt;&amp;nbsp;Yes.&amp;nbsp;&lt;/p&gt;
[quote user=""]If you can, can you briefly describe the process or provide simple routines?[/quote]
&lt;p&gt;&amp;nbsp;You must first initialize the SPIM peripheral driver and configure the proper settings for your transfer, ie. frequency , pointer to rx/tx buffers, length of buffers, SPI polarity, etc. The standard &lt;a title="SPIM driver" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__spim.html?cp=7_1_6_8_0_32_0"&gt;SPIM driver&lt;/a&gt;&amp;nbsp;API has all that you need.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Then you connect the GPIOTE IN_EVENT to the SPIM TASKS_START. Use the PPI example as a reference for how to connect an event to a task.&amp;nbsp;&lt;br /&gt;Use&amp;nbsp;&lt;a title="nrfx_spim_start_task_get" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__spim.html?cp=7_1_6_8_0_32_0_23#gadb5b212e351bd65958c6be78a957ac65"&gt;nrfx_spim_start_task_get&lt;/a&gt;&amp;nbsp;to get the address of the SPIM TASKS_START.&amp;nbsp;&lt;/p&gt;
[quote user=""] If PPI + gpiote is used to trigger SPI read-write, can it solve the problem of SPI read-write discontinuity?[/quote]
&lt;p&gt;Yes, but you need to process the buffers at some point. The SPIM is double-buffered so that you can prepare the next buffer immediately after the STARTED event has fired.&amp;nbsp;&lt;/p&gt;
[quote user=""]If PPI + gpiote is used to trigger SPI read / write, will it affect the part that I didn&amp;#39;t want to be triggered in this way?[/quote]
&lt;p&gt;&amp;nbsp;I don&amp;#39;t know what you don&amp;#39;t want to get triggered. You need to elaborate.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>