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

Uninterrupted SPI-clock during DMA?

Hi,

Edited, should have pointed out that I'm using the nrf52.

I'm using a simple setup with a MEMS-microphone, and tries to read data from it. I have setup the DMA to use list-mode, 4Mhz sample rate, and an data-array of 100 blocks, each with 250 bytes.

Looking at the SPI-clock, I see that the clock pauses for 6 cycles every 500 us (250 bytes * 8 bits / 4 MHz = 500 us), i.e. it pauses after every transfer of one block of data.

In short, the code looks like this:

#define BUF_SIZE 250
#define NO_OF_BUF 100

typedef struct ArrayList {
    uint8_t buffer[BUF_SIZE];
} ArrayList_type;

static ArrayList_type samples_array[NO_OF_BUF];

NRF_SPIM0->FREQUENCY = (SPIM_FREQUENCY_FREQUENCY_M4 << SPIM_FREQUENCY_FREQUENCY_Pos);
NRF_SPIM0->ENABLE = (SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos);

// Setup start of buffer ...
counter = 0;
NRF_SPIM0->RXD.PTR = (uint32_t) &samples_array[counter];
NRF_SPIM0->RXD.MAXCNT = BUF_SIZE;
NRF_SPIM0->RXD.LIST = 1;  // List mode - autoincrement

// Enable shorts ...
nrf_spim_shorts_enable(NRF_SPIM0,SPIM_SHORTS_END_START_Msk);

NRF_SPIM0->EVENTS_ENDRX = 0;
NRF_SPIM0->EVENTS_ENDTX = 0;
NRF_SPIM0->EVENTS_END = 0;
NRF_SPIM0->EVENTS_STARTED = 0;
NRF_SPIM0->EVENTS_STOPPED = 0;
NRF_SPIM0->TASKS_START = 1;

while (NRF_SPIM0->EVENTS_STARTED == 0) {}

// Short mode - start automatically after EVENTS_END
// List mode - auto increment RXD.PTR with RXD.MAXCNT
while (counter < NO_OF_BUF) {
    while (NRF_SPIM0->EVENTS_END == 0) {}
    NRF_SPIM0->EVENTS_END = 0;
    counter++;
}
nrf_spim_shorts_disable(NRF_SPIM0,SPIM_SHORTS_END_START_Msk);

This works, i.e. I get the expected amount of data, but looking at the samples I see that some samples are skipped due to the missing clock cycles.

Am I missing something?

Is there anyway to setup the transfer to go on uninterrupted, i.e. I want to transfer all 250 * 100 * 8 bits consecutive from the device, without any interrupt on the SPI clock?

Best regards, Thomas

Related