This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C1294XL: ADC DMA for circular buffer

Part Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

Hi,

I try to build a circular buffer for my ADC data. I read 8 ADC channels and the result is supposed to written into array uint32_t pui32ADC0Value[8]; by my DMA. This is supposed to happen continuously.

My problem is that with my DMA configuration I can only achieve one <TransferSize> (TransferSize is the last argument in uDMAChannelTransferSet()-call) full of ADC values. After <TransferSize> transfers the DMA stops and no further data are transfered. I checked the ADC FIFO and could observe new values arriving. But for some reason the DMA seems to not be triggered anymore.

How can I make the DMA transfers continuous?

Best regards,
Max

Here is my Code:

/*
 * Copyright (c) 2015, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== empty_min.c ========
 */
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/Log.h>
#include <xdc/runtime/System.h>
#include <xdc/runtime/Timestamp.h>
#include <xdc/cfg/global.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Swi.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Semaphore.h>

/* TI-RTOS Header files */
// #include <ti/drivers/EMAC.h>
#include <ti/drivers/GPIO.h>
// #include <ti/drivers/I2C.h>
// #include <ti/drivers/SDSPI.h>
// #include <ti/drivers/SPI.h>
// #include <ti/drivers/UART.h>
// #include <ti/drivers/USBMSCHFatFs.h>
// #include <ti/drivers/Watchdog.h>
// #include <ti/drivers/WiFi.h>



/* Board Header file */
#include "Board.h"
#include <stdbool.h>
#include <driverlib/timer.h>
#include <driverlib/sysctl.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_adc.h"

#include <driverlib/interrupt.h>
#include <driverlib/adc.h>
#include <driverlib/gpio.h>
#include <driverlib/udma.h>
#include <driverlib/pin_map.h>

#define TASKSTACKSIZE   512

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];

uint32_t start, stop, result;

uint32_t pui32ADC0Value[8];

void ledToggle(UArg arg0){
    start = Timestamp_get32();
    GPIO_toggle(Board_LED1);
    //for (i = 0; i < 999999; i++){}
    //Log_info1("Toggled LED %d ", i);
    stop = Timestamp_get32();
    result = stop - start;
    return;

}


/*void timerInterrupt(UArg arg0){
    TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
    Swi_post(swi0);
    return;
}*/

/*
 *  ======== heartBeatFxn ========
 *  Toggle the Board_LED0. The Task_sleep is determined by arg0 which
 *  is configured for the heartBeat Task instance.
 */

Void heartBeatFxn(UArg arg0, UArg arg1)
{
    while (1) {
        Task_sleep((unsigned int)arg0);
        GPIO_toggle(Board_LED0);
    }
}

/*
 *  ======== configure_ADC ========
 */
void configure_ADC(){
    //enable peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1);

    //set pin function
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);    //AIN0
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);    //AIN1
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);    //AIN2
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);    //AIN3
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_7);    //AIN4
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_6);    //AIN5
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_5);    //AIN6
    GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_4);    //AIN7

    /*GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);    //AIN8
    GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);    //AIN9
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);    //AIN10
    GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_5);    //AIN11*/

    //enable sample sequence 3
    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 1);

    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH4);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH5);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH6);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH7 | ADC_CTL_END);


    ADCSequenceEnable(ADC0_BASE, 0);

    ADCIntClear(ADC0_BASE, 0);


    return;
}

void configure_DMA(){
    //ADC DMA
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);

    #pragma DATA_ALIGN(DMAcontroltable, 1024)
    uint8_t DMAcontroltable[1024];


    SysCtlDelay(10);

    uDMAEnable();

    uDMAControlBaseSet(DMAcontroltable);

    uDMAChannelAssign(UDMA_CHANNEL_ADC0);


    //SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    //uDMAEnable();
    uDMAChannelControlSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT, UDMA_SIZE_32 | UDMA_SRC_INC_NONE | UDMA_DST_INC_32 | UDMA_ARB_4);
    uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void *)(ADC0_BASE + ADC_O_SSFIFO0), pui32ADC0Value, 8);
    //uDMAChannelAttributeEnable(UDMA_CHANNEL_ADC0, UDMA_ATTR_USEBURST);

    uDMAChannelEnable(UDMA_CHANNEL_ADC0);

    return;
}
/*
 *  ======== main ========
 */
int main(void)
{
    Task_Params taskParams;

    /* Call board init functions */
    Board_initGeneral();
    // Board_initEMAC();
    Board_initGPIO();
    // Board_initI2C();
    // Board_initSDSPI();
    // Board_initSPI();
    // Board_initUART();
    // Board_initUSB(Board_USBDEVICE);
    // Board_initUSBMSCHFatFs();
    // Board_initWatchdog();
    // Board_initWiFi();

    /* Construct heartBeat Task  thread */
    Task_Params_init(&taskParams);
    taskParams.arg0 = 1000;
    taskParams.stackSize = TASKSTACKSIZE;
    taskParams.stack = &task0Stack;
    Task_construct(&task0Struct, (Task_FuncPtr)heartBeatFxn, &taskParams, NULL);

    configure_ADC();
    ADCSequenceDMAEnable(ADC0_BASE, 0);

    configure_DMA();
    /*SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);

    //
    // Configure the Timer0B interrupt for timer timeout.
    //
    TimerConfigure(TIMER2_BASE, TIMER_CFG_A_PERIODIC);

    TimerLoadSet(TIMER2_BASE, TIMER_A, 12000000);

    TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT);

    //IntEnable(INT_TIMER2A);
    TimerEnable(TIMER2_BASE, TIMER_A);
*/
    /* Turn on user LED  */
    GPIO_write(Board_LED0, Board_LED_ON);
    GPIO_write(Board_LED1, Board_LED_ON);

    //ADCIntEnable(ADC0_BASE, 0 );
    //ADCSequenceDMAEnable(ADC0_BASE, 1);

    //ADCProcessorTrigger(ADC0_BASE, 0);
    //ADCProcessorTrigger(ADC0_BASE, 1);

    /* Start BIOS */
    //BIOS_start();
    while(1);
    return (0);
}