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

Thread: T4: Triggering DMA SPI transfer from within interrupt

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    5

    T4: Triggering DMA SPI transfer from within interrupt

    Hi all

    I have an application where I need to undertake a short SPI read every 60us or so. I am interfacing a T4 with an ADS131M differential ADC.

    The ADS131M has a dataready signal that asserts (strangely enough) when data is ready to be read and I was thinking of using attachInterrupt to trigger a DMA SPI read. Like this (code extract only):

    Code:
    EventResponder ADCspiEvent;
    
    void adcSetup(void){
    	[... IC setup ...]
    	ADCspiEvent.attachImmediate(&adcCallbackSPI);
    	attachInterrupt(digitalPinToInterrupt(ADCDREADYPIN), adcPullData, FALLING);
    }
    
    void adcPullData(void){
        spiAdcReadBuffer[0] = ADS131M_NULL >> 8;
        spiAdcReadBuffer[1] = ADS131M_NULL;
        SPI.beginTransaction(SPISettings(ADCSPISPEED, MSBFIRST, SPI_MODE1));
        digitalWriteFast(ADCSLAVESELECT, LOW);
        SPI.transfer((uint8_t*)spiAdcReadBuffer,(uint8_t*)spiAdcReadBuffer,ADCFULLFRAME,ADCspiEvent);
    }
    
    void adcCallbackSPI(EventResponderRef event_responder){
        SPI.endTransaction();
        digitalWrite(ADCSLAVESELECT, HIGH);
        grabberData.adcDataReady = true;
    
    	[... save off data in buffer for later processing ...]
    
    }
    What I see is that DMA version of SPI.transfer (i.e. the one with the EventResponder argument) does not appear to work when it is triggered in an interrupt context. The Teensy appears to lock up (although I have not investigated whether this is a true lockup).

    If I do the whole SPI read within the interrupt routine, the thing works but obviously the Teensy is spending about 30% of its time in the interrupt doing the IO, so not a solution. Use of DMA SPI triggered outside an interrupt also works but polling the dataready line is not really an option.

    So, does anyone have any thoughts/experiences about triggering a SPI DMA transaction inside an interrupt?

    BBUK

  2. #2
    Junior Member
    Join Date
    Oct 2019
    Posts
    5
    Please ignore this for the moment. Looking at EventResponder.h I saw EventResponder::attachInterrupt and that appears to be working fabulously but I'll report back if I am still having problems.

    Sorry for the noise.

    BBUK

Posting Permissions

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