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

Repeat SPI transfers with SS line faster

I am trying to read data from a chip over SPI. 

The implementation of the SPI comms is not ideal as they require a new CS/SS line toggle on every byte.  I cannot do a bulk SPI read.

I am seeing a 10uS delay between each SPI XFER.  Is there a way to speed this up?  This is greatly increasing the read time.

Here is my SPI setup.  I am using SPI3 to allow for hardware SS line control.

void fpga_spi_init()
{

    nrfx_spim_config_t spi_config = NRFX_SPIM_DEFAULT_CONFIG;
    spi_config.irq_priority = APP_IRQ_PRIORITY_HIGH;
    spi_config.frequency = NRF_SPIM_FREQ_8M; // NRF_SPIM_FREQ_8M NRF_SPIM_FREQ_16M NRF_SPIM_FREQ_16M
    spi_config.mode = NRF_SPIM_MODE_0;
    spi_config.ss_pin = FPGA_SPI_CS;
    spi_config.miso_pin = FPGA_SPI_MISO;
    spi_config.mosi_pin = FPGA_SPI_MOSI;
    spi_config.sck_pin = FPGA_SPI_SCK;
    spi_config.dcx_pin = NRFX_SPIM_PIN_NOT_USED;
    spi_config.use_hw_ss = true;
    spi_config.ss_active_high = false;
    // spi_config.ss_duration = 20; // 45; //45; // 36;
    // spi_config.ss_duration = 0;
    // spi_config.rx_delay = 0;

    APP_ERROR_CHECK(nrfx_spim_init(&fpga_spi, &spi_config, NULL, NULL));
    // APP_ERROR_CHECK(nrfx_spim_init(&fpga_spi, &spi_config, spim_event_handler, NULL));

    is_fpag_spi_init = true;
}

Here is my read loop, I have to read each byte out individually.

  • Hi,

     

    You could setup and trigger the SPIM manually, which will omit all the pointer checks and so forth:

    nrf_spim_tx_buffer_set(spi.p_reg, &reg, 1);
    nrf_spim_rx_buffer_set(spi.p_reg, &rx, 1);
    nrf_spim_event_clear(spi.p_reg, NRF_SPIM_EVENT_END);
    nrf_spim_task_trigger(spi.p_reg, NRF_SPIM_TASK_START);
    while (!nrf_spim_event_check(spi.p_reg, NRF_SPIM_EVENT_END));

    This should speed things up.

     

    Kind regards,

    Håkon 

Related