I'm attempting to move from block SPI transfers to DMA based, and I'm having some success, but seem to be struggling with the DMA SPI speed
I'm trying to run two separate SPI busses SPI0 and SPI2, I've started moving the SPI0 transfers as per the DMASPI read me and examples. The problem is that no matter what I do with SPISettings, the DMA always seems to be using a 4Mhz clock for the SPI Clock, which is, well, kind of useless for me.
The first SPI0 transfer works at 25Mhz (Yes I know it says 26Mhz, but for some reason if I set it to 25 in the SPI settings I get 20) anyway here's my code;
Could someone point me at how to set the SPI Clock speed for the DMA SPI transfer please?
It would also be nice to know how to get the default Chip Select pin (10) to be driven by the DMA as well.
many thanks in advance
Paula
I'm trying to run two separate SPI busses SPI0 and SPI2, I've started moving the SPI0 transfers as per the DMASPI read me and examples. The problem is that no matter what I do with SPISettings, the DMA always seems to be using a 4Mhz clock for the SPI Clock, which is, well, kind of useless for me.
The first SPI0 transfer works at 25Mhz (Yes I know it says 26Mhz, but for some reason if I set it to 25 in the SPI settings I get 20) anyway here's my code;
Code:
#include <Arduino.h>
#include <SPI.h>
#include <DmaSpi.h>
#define DMASIZE 100
uint8_t src[DMASIZE];
volatile uint8_t dest[DMASIZE];
volatile uint8_t dest1[DMASIZE];
void setSrc()
{
for (size_t i = 0; i < DMASIZE; i++)
{
src[i] = i;
}
}
void clrDest(uint8_t* dest_)
{
memset((void*)dest_, 0x00, DMASIZE);
}
// Initialise stuff
void initSPI(void)
{
Serial.print("init SPI0:");
SPISettings(26000000, MSBFIRST, SPI_MODE0);
SPI.begin();
SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // for some reason, I get 20Mhz when the rate is set to 25000000
// I do get 25Mhz, when the rate is set to 26000000... huh?
SPI2.begin();
SPI2.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0));
//************************ TESTING
delay(3000);
Serial.println("regular SPI transer test");
setSrc();
elapsedMicros us;
digitalWrite (ChipSelect, LOW);
for (size_t i = 0; i < DMASIZE; i++)
{
dest[i] = SPI.transfer(src[i]);
}
digitalWrite (ChipSelect, HIGH);
uint32_t t = us;
Serial.print("Time for non-DMA transfer: ");Serial.print(t);Serial.println("us");
SPI.endTransaction();
delay(500);
SPISettings(26000000, MSBFIRST, SPI_MODE0); // Seems to have no affect
DMASPI0.begin();
DMASPI0.start();
DmaSpi::Transfer trx(nullptr, 0, nullptr);
Serial.println("Testing src -> dest, single transfer");
Serial.println("--------------------------------------------------");
trx = DmaSpi::Transfer(src, DMASIZE, dest);
clrDest((uint8_t*)dest);
DMASPI0.registerTransfer(trx); // only seems to transfer at 4Mhz :(
while(trx.busy())
{
digitalWrite (ChipSelect, LOW);
}
digitalWrite (ChipSelect, HIGH);
Serial.println("Finished DMA transfer");
Serial.println("==================================================\n\n");
//************************ END OF TESTING
Serial.println(" done");
// need to add in Second SPI (SPI1) for osc DAC
}
Could someone point me at how to set the SPI Clock speed for the DMA SPI transfer please?
It would also be nice to know how to get the default Chip Select pin (10) to be driven by the DMA as well.
many thanks in advance
Paula
Last edited: