Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4.0 DMA SPI Speed issues

Threaded View

  1. #1

    Teensy 4.0 DMA SPI Speed issues

    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;

    #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.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.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); 
      //************************ TESTING
      Serial.println("regular SPI transer test");
      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");
      SPISettings(26000000, MSBFIRST, SPI_MODE0);             // Seems to have no affect
      DmaSpi::Transfer trx(nullptr, 0, nullptr);
      Serial.println("Testing src -> dest, single transfer");
      trx = DmaSpi::Transfer(src, DMASIZE, dest);
      DMASPI0.registerTransfer(trx);                                                        // only seems to transfer at 4Mhz :(
        digitalWrite (ChipSelect, LOW);
      digitalWrite (ChipSelect, HIGH);
      Serial.println("Finished DMA transfer");
      //************************ 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
    Last edited by Paula; 01-18-2020 at 10:42 PM. Reason: additional question

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts