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

Is it possible to do back to back SPI transfers or read only during RX time?

I need to write received data from SPI to address pointed by a parameter. When doing a transfer, spi drivers also read the data sent by slave during TX. I know this is normal since SPI is full-duplex protocol. However, I have strict time constraints so I can't copy read data between buffers (I've done this and it worked but the performance wasn't great). Also, I can't use pointer arithmetics since buffer is elsewhere. I thought that if I could make TX - RX transfer back to back seperately, I can solve this problem. Is there a way to do this or do I have an alternate solution?

Parents
  •  Let me give you a small example

    void example_function(const uint8_t *p_tx, uint32_t tx_count, uint8_t *p_rx, uint32_t rx_count)
    {
    /* I need to write tx_count bytes from p_tx
    * Then I need to read rx_count bytes to p_rx
    * If I set up nrf_drv_spi_transfer or nrfx_spim_xfer to write tx_count bytes and read rx_count bytes, I only see (rx_count - tx_count) bytes in p_rx.
    * If I change it to write tx_count bytes and receive (tx_count + rx_count) bytes, I have the data that I want in my buffer but with extra tx_count bytes from tx time.
    * If I copy received data to a local buffer, then memcpy only the data that I want, it works but performance is not great. */
    }

    Why do you need a separate buffer for the two RX bytes?

    It was an example, it's not always 2 bytes.

Reply
  •  Let me give you a small example

    void example_function(const uint8_t *p_tx, uint32_t tx_count, uint8_t *p_rx, uint32_t rx_count)
    {
    /* I need to write tx_count bytes from p_tx
    * Then I need to read rx_count bytes to p_rx
    * If I set up nrf_drv_spi_transfer or nrfx_spim_xfer to write tx_count bytes and read rx_count bytes, I only see (rx_count - tx_count) bytes in p_rx.
    * If I change it to write tx_count bytes and receive (tx_count + rx_count) bytes, I have the data that I want in my buffer but with extra tx_count bytes from tx time.
    * If I copy received data to a local buffer, then memcpy only the data that I want, it works but performance is not great. */
    }

    Why do you need a separate buffer for the two RX bytes?

    It was an example, it's not always 2 bytes.

Children
Related