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/SW-EK-TM4C1294XL: adc with udma transfer

Part Number: SW-EK-TM4C1294XL
Other Parts Discussed in Thread: EK-TM4C1294XL

Tool/software: Code Composer Studio

HI Friends,

Iam working tm4c1294xl evaluation kit i was working adc sample squencer 3 using udma transfer. My problem was i was unable to print the value sampled using adc. Iam attaching code with with this post can any help with this issue. 

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/udma.h"
#include "utils/cpu_usage.h"
#include "utils/uartstdio.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.c"
#include "driverlib/adc.h"
#include "inc/hw_adc.h"
static int i;

#define MEM_BUFFER_SIZE 1024

//#define UART_TXBUF_SIZE 256
//#define UART_RXBUF_SIZE 256

//static uint32_t g_ui8TxBuf[UART_TXBUF_SIZE];
static uint32_t g_ui8RxBufA[1];
static uint32_t g_ui8RxBufB[1];


static uint32_t g_ui32uDMAErrCount = 0;


static uint32_t g_ui32BadISR = 0;

static uint32_t g_ui32RxBufACount = 0;
static uint32_t g_ui32RxBufBCount = 0;

uint32_t g_ui32SysClock;



#if defined(ewarm)
#pragma data_alignment=1024
uint8_t pui8ControlTable[1024];
#elif defined(ccs)
#pragma DATA_ALIGN(pui8ControlTable, 1024)
uint8_t pui8ControlTable[1024];
#else
uint8_t pui8ControlTable[1024] __attribute__ ((aligned(1024)));
#endif


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif



void
uDMAErrorHandler(void)
{
	uint32_t ui32Status;


	ui32Status = uDMAErrorStatusGet();

	if(ui32Status)
	{
		uDMAErrorStatusClear();
		g_ui32uDMAErrCount++;
	}
}


void ADCseq0Handler()

{
	uint_fast16_t ui16Idx;
	uint32_t ui32Status;
	uint32_t ui32Mode;
	for(ui16Idx = 0; ui16Idx < 1; ui16Idx++)
	{
		UARTprintf("printing forom receiver side");
		UARTprintf("hello receiver %d \n ",g_ui8RxBufA[ui16Idx] );
	}

	ADCIntClearEx(ADC0_BASE, ADC_INT_DMA_SS0 | ADC_INT_SS0);

	if (uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT) == UDMA_MODE_STOP) {


		uDMAChannelTransferSet((UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT), UDMA_MODE_PINGPONG, (void *)(ADC0_BASE), g_ui8RxBufA, sizeof(g_ui8RxBufA));

	}

	if (uDMAChannelModeGet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT) == UDMA_MODE_STOP) {
		// found the full buffer

		// re-set up a DMA transfer to the buffer
		uDMAChannelTransferSet((UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT), UDMA_MODE_PINGPONG, (void *)(ADC0_BASE ), g_ui8RxBufB, sizeof(g_ui8RxBufB));
	}
}


void
InitUART1Transfer(void)
{
	uint32_t div;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ADC0);
	ADCClockConfigSet(ADC0_BASE,ADC_CLOCK_SRC_PLL,ADC_CLOCK_RATE_FULL);
	ADCSequenceConfigure(ADC0_BASE, 3 /*SS0*/, ADC_TRIGGER_ALWAYS, 0 /*priority*/); // SS0-SS3 priorities must always be different

	ADCSequenceStepConfigure(ADC0_BASE, 3 /*SS0*/, 0, ADC_CTL_CH0 | ADC_CTL_END | ADC_CTL_IE); // ADC_CTL_IE fires every 8 samples
	ADCSequenceEnable(ADC0_BASE, 3);
	ADCSequenceDMAEnable(ADC0_BASE, 3);
	uDMAChannelAttributeDisable(UDMA_CHANNEL_ADC0,
			UDMA_ATTR_ALTSELECT | UDMA_ATTR_USEBURST |
			UDMA_ATTR_HIGH_PRIORITY |
			UDMA_ATTR_REQMASK);
	uDMAChannelControlSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT,
			UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
			UDMA_ARB_4);

	uDMAChannelControlSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
			UDMA_SIZE_8 | UDMA_SRC_INC_NONE | UDMA_DST_INC_8 |
			UDMA_ARB_4);

	uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT,
			UDMA_MODE_PINGPONG,
			(void *)(ADC0_BASE),
			g_ui8RxBufA, sizeof(g_ui8RxBufA));
	uDMAChannelTransferSet(UDMA_CHANNEL_ADC0 | UDMA_ALT_SELECT,
			UDMA_MODE_PINGPONG,
			(void *)(ADC0_BASE ),
			g_ui8RxBufB, sizeof(g_ui8RxBufB));

	uDMAChannelEnable(UDMA_CHANNEL_ADC0);
	ADCIntEnableEx(ADC0_BASE, ADC_INT_DMA_SS3);
	IntEnable(INT_ADC0SS3);


}


void
ConfigureUART(void)
{

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);


	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);


	UARTStdioConfig(0, 115200, g_ui32SysClock);
}


int
main(void)
{

	static uint32_t ui32PrevUARTCount = 0;
	uint32_t ui32XfersCompleted;
	uint32_t ui32BytesTransferred;
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

	GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);

	g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
			SYSCTL_OSC_MAIN |
			SYSCTL_USE_PLL |
			SYSCTL_CFG_VCO_480), 120000000);


	SysCtlPeripheralClockGating(true);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);

	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);

	ConfigureUART();

	UARTprintf("Tiva C Series @ %u MHz\n\n", g_ui32SysClock / 1000000);

	UARTprintf("CPU\tRemaining\tMemory\t\t\t UART\n");
	UARTprintf("Usage\tTime\t\tTransfers\t\t Transfers\n");


	SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
	SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA);


	IntEnable(INT_UDMAERR);

	uDMAEnable();

	uDMAControlBaseSet(pui8ControlTable);

	InitUART1Transfer();

	SysCtlSleep();


	UARTprintf("\nStopped\n");

	IntDisable(INT_ADC0SS3);
	IntDisable(INT_UDMA);


}

Regards

Prudhvi

  • i tried with changing to

    uDMAChannelTransferSet((UDMA_CHANNEL_ADC0 | UDMA_PRI_SELECT), UDMA_MODE_PINGPONG, (void *)(ADC0_BASE + ADC_O_SSFIFO0), g_ui8RxBufA, sizeof(g_ui8RxBufA)); also nothing change
  • Hello Prudhvi,

    There are a few E2E post which covers this application I think will be helpful for you in adjusting your implementation.

    This post by another community member details a lot of what is needed for ADC w/ UDMA transfer and is a very insightful read: https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/647065/2379897#2379897

    And here is an example for a different TM4C MCU which handles ping pong ADC reads to load two buffers: https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/643173/2381981#2381981

    Please look through these resources, and if you have further specific questions about their implementation please do follow up here so I can help clarify.

  • Hi Ralph Jacobi ,

    first of all thanks for the reply ,now also iam unable to figure out what actually happening in my code .Can you please provide me any working code for tm4c1294xl udma code using adc so that it can useful for my further reference as iam new to working with this device

  • Hello Prudhvi,

    We don't have an example for UDMA+ADC to provide, only individual examples for the ADC peripheral and uDMA peripheral in TivaWare. If you are struggling with understanding what is going on, I would suggest referencing those examples though to gain more insight into each peripheral.

    The example code for ADC in the TivaWare examples is under [Install Path]\TivaWare_C_Series-2.1.4.178\examples\peripherals\adc

    The TivaWare examples for uDMA are in the various development board folders such as [Install Path]\TivaWare_C_Series-2.1.4.178\examples\boards\ek-tm4c1294xl\udma_demo