This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

The problem of SPI communication initiated by external interrupt using PPI

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 reading data. In this way, when polling to read data, it is bound to be interrupted by the Bluetooth protocol stack, resulting in the read sensor data is not continuous. It's just the continuous and complete data that customers need.

So,

1. Can I use PPI module to trigger SPI read / write task with gpiote interrupt event as trigger condition?

2. If you can, can you briefly describe the process or provide simple routines?

3. If PPI + gpiote is used to trigger SPI read-write, can it solve the problem of SPI read-write discontinuity?

4. If PPI + gpiote is used to trigger SPI read / write, will it affect the part that I didn't want to be triggered in this way?

I look forward to hearing from you soon.

Best regards!

June6

Parents
  • Can I use PPI module to trigger SPI read / write task with gpiote interrupt event as trigger condition?

     Yes. 

    If you can, can you briefly describe the process or provide simple routines?

     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 SPIM driver API has all that you need. 

    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. 
    Use nrfx_spim_start_task_get to get the address of the SPIM TASKS_START. 

    If PPI + gpiote is used to trigger SPI read-write, can it solve the problem of SPI read-write discontinuity?

    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. 

    If PPI + gpiote is used to trigger SPI read / write, will it affect the part that I didn't want to be triggered in this way?

     I don't know what you don't want to get triggered. You need to elaborate. 

  • Hi, haakonsh.

    Now I have added a part of the program as follows

    #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);

    In this way, when receiving the gpiote external interrupt, can we read the sensor's 0x0f register and save the read data to SPI0ArrayList[1].buffer?

Reply
  • Hi, haakonsh.

    Now I have added a part of the program as follows

    #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);

    In this way, when receiving the gpiote external interrupt, can we read the sensor's 0x0f register and save the read data to SPI0ArrayList[1].buffer?

Children
No Data
Related