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

Speed up SPI Burst Reads?

I'm running SPI master (spi_master_tx_rx) at 4MHz for multi byte burst reads. As seen in the attached screenshot there are 5.5µs delays between the bytes. The delays increase my CPU active time and therefore costing energy.

I've read about the double buffer feature of the SPI master module. And I wonder this can shorten the delays in any way?

spi_burst_read_scrn.png

Parents
  • Hi,

    Since the SPI master is double buffered, you can preload two bytes right after initing the SPI. In the interrupt, you can add a new byte into the buffer. This will cause the SPI to run back-to-back. Something like this:

    
    spim_init();
    NRF_SPI0->TXD = buf[0];
    NRF_SPI0->TXD = buf[1];
    ...
    
    void SPI0_TWI0_IRQHandler(void)
    {
      if (NRF_SPI0->EVENTS_READY)
      {
        NRF_SPI0->EVENTS_READY = 0;
        NRF_SPI0->TXD = some_data;
        uint8_t ret_data = NRF_SPI0->RXD;
      }
    }
    
    

    Best regards Håkon

Reply
  • Hi,

    Since the SPI master is double buffered, you can preload two bytes right after initing the SPI. In the interrupt, you can add a new byte into the buffer. This will cause the SPI to run back-to-back. Something like this:

    
    spim_init();
    NRF_SPI0->TXD = buf[0];
    NRF_SPI0->TXD = buf[1];
    ...
    
    void SPI0_TWI0_IRQHandler(void)
    {
      if (NRF_SPI0->EVENTS_READY)
      {
        NRF_SPI0->EVENTS_READY = 0;
        NRF_SPI0->TXD = some_data;
        uint8_t ret_data = NRF_SPI0->RXD;
      }
    }
    
    

    Best regards Håkon

Children
No Data
Related