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

Single SPI transfer from PPI

I want to set up a SPI transfer so the transfer itself is triggered by PPI. The PPI is set up working, the chain of events is

  1. Timer CC0 -> Set CS low
  2. Timer CC1 -> Start SPI
  3. SPI end -> Set CS high

Now, I want to send a packet of 2 bytes for transmission on the next timer event (note this is TX only, no RX)

My SPI descriptor is

static uint8_t dac_buf[2];
nrfx_spim_xfer_desc_t const xfer_desc = NRFX_SPIM_SINGLE_XFER(dac_buf, 2, NULL, 0);

and I send the packet by

nrfx_spim_xfer(&spi_inst, &xfer_desc,NRFX_SPIM_FLAG_HOLD_XFER);

but I'm getting the same 2 bytes sent every timer event. Can I expect the single xfer to work like this, or do I need to be enabling/disabling the PPI channels to start/stop transmission?

Parents
  • Hi,

    I'm not sure I understand your question. Do you update the dac_buf somewhere, since you did not expect the same two bytes being sent every timer event?

    Best regards,
    Jørgen

  • Hi

    Sorry for not being clear. At the moment for testing no I'm not updating dac_buf, I'm just doing the one-off xfer as part of main().

    In the real world, I'll be feeding data into a ring buffer, and taking them out 2 bytes at a time based on the timer event. So I'll need the SPI to be transmitting when there is data and idle when the data has finished. Right now the SPI transmits all the time from the PPI.

    I could mess around with starting/stopping the timer or disabling the PPI event although I was hoping that the xfer would be a one-shot so I wouldn't have to.

    Hope that makes it clearer...

    Regards

    Nick

    Edit: I also added a spi event handler and included a couple of lines to disable the PPI channels but that didn't work 

        nrfx_ppi_channel_disable(ppi_cs_low);
        nrfx_ppi_channel_disable(ppi_spi_start);
        nrfx_ppi_channel_disable(ppi_cs_hi);

Reply
  • Hi

    Sorry for not being clear. At the moment for testing no I'm not updating dac_buf, I'm just doing the one-off xfer as part of main().

    In the real world, I'll be feeding data into a ring buffer, and taking them out 2 bytes at a time based on the timer event. So I'll need the SPI to be transmitting when there is data and idle when the data has finished. Right now the SPI transmits all the time from the PPI.

    I could mess around with starting/stopping the timer or disabling the PPI event although I was hoping that the xfer would be a one-shot so I wouldn't have to.

    Hope that makes it clearer...

    Regards

    Nick

    Edit: I also added a spi event handler and included a couple of lines to disable the PPI channels but that didn't work 

        nrfx_ppi_channel_disable(ppi_cs_low);
        nrfx_ppi_channel_disable(ppi_spi_start);
        nrfx_ppi_channel_disable(ppi_cs_hi);

Children
No Data
Related