Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC ---> Memory uDMA tm4c123

Status
Not open for further replies.

SupItsChris

Newbie
Newbie level 3
Joined
Oct 4, 2020
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
Hey guys, I been stuck on this issue for a couple of days now. I am trying to read from an ADC with uDMA and send over UART.

Code

C:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "utils/uartstdio.h"
#include "driverlib/interrupt.h"
#include "driverlib/udma.h"
//********************

typedef struct{
    uint16_t adcBuffer[8];
    uint16_t AVG;
    uint16_t C;
    uint16_t F;
}Temp_t;


typedef struct{

    unsigned char input;

}UART_t;


void calculate_avg_temperature(Temp_t *temp_t);
//*******************


//********************

uint8_t DMAControlTable[1024];

//*******************
int main(void)
{

      //Config System Clock
     SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_XTAL_16MHZ | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN );

     Temp_t temp_t = {0};

     volatile UART_t uart_t;


     //Config UART
     SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

     GPIOPinConfigure(GPIO_PA1_U0TX);
     GPIOPinConfigure(GPIO_PA0_U0RX);
     GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1 | GPIO_PIN_0);
     UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600UL, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
     UARTStdioConfig(0, 9600, SysCtlClockGet());
     //

     //Config ADC
     SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

     ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
     ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_TS | ADC_CTL_END | ADC_CTL_IE);
     ADCSequenceEnable(ADC0_BASE, 0);
     ADCSequenceDMAEnable(ADC0_BASE, 0);


     //Config uDMA
     SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);

     uDMAEnable();
     uDMAControlBaseSet(DMAControlTable);

     uDMAChannelAttributeDisable(UDMA_CH14_ADC0_0, UDMA_ATTR_ALL);
     uDMAChannelAttributeDisable(UDMA_CH14_ADC0_0 | UDMA_ALT_SELECT, UDMA_ATTR_ALL);

     uDMAChannelAttributeEnable(UDMA_CH14_ADC0_0, UDMA_ATTR_USEBURST);

     uDMAChannelControlSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT, UDMA_SIZE_16 | UDMA_SRC_INC_NONE | UDMA_DST_INC_16 | UDMA_ARB_16);

     uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT, UDMA_MODE_AUTO, (void*)(ADC0_SSFIFO0_R), temp_t.adcBuffer, sizeof(temp_t.adcBuffer));

     uDMAChannelEnable(UDMA_CH14_ADC0_0);


    while(1)
    {
    calculate_avg_temperature(&temp_t);
        UARTprintf("C %3d\t", temp_t.C);
    }
}


//Calculate the average
void calculate_avg_temperature(Temp_t *temp_t){

    while(!(uDMAChannelModeGet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT) == UDMA_MODE_STOP)){
        ADCProcessorTrigger(ADC0_BASE, 0);
        while(!(ADCIntStatus(ADC0_BASE, 0, false))){};
        ADCIntClear(ADC0_BASE, 0);
    };


    temp_t->AVG = (temp_t->adcBuffer[0]);
    temp_t->C = (1475 - (2475 * temp_t->AVG) / 4096)/10;
    temp_t->F = ((temp_t->C * 9) + 160) / 5;

    uDMAChannelTransferSet(UDMA_CH14_ADC0_0 | UDMA_PRI_SELECT, UDMA_MODE_BASIC, (void*)(ADC0_SSFIFO0_R), temp_t->adcBuffer, sizeof(temp_t->adcBuffer));
    uDMAChannelEnable(UDMA_CH14_ADC0_0);

}


The error that I notice that happens is, once I trigger the ADC Sequence, the bus fault error immediately triggers. Idk what I am doing wrong, I've compared this with so many different other pieces of code. I can't figure out for the life of me why its won't work. Thank you for any advice or answers. Much appreciated.
 
Last edited:

I'm missing the declaration of pointer temp. Is it initialized?

Generally, think about ways to locate the memory access fault in debugging, either with simulator or in-circuit debugger.
 

I'm missing the declaration of pointer temp. Is it initialized?

Generally, think about ways to locate the memory access fault in debugging, either with simulator or in-circuit debugger.

I apologize, I was trying different codes and forgot to switch that back to temp_t which is the structure for temperature. It is now corrected. Thank you for the response. When I looked at the data sheet, all it said was it can be caused by bus or memory write error. It doesn't have any indication of what kind of bus error. I literally have no idea how to proceed. Because this code compared to others should work, and the only issue I am having is getting it to read from the ADC cause it gets stuck in that loop since the fault causes it to become infinite.
 

I don't See any "GPIOPinTypeADC" is being called. Select the analog ADC function for the pins which you are using, consult the datasheet to see which functions are allocated per pin for Example:

C:
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
 

I just tried that to make sure but it didn't work. I am using the ADC Temperature sensor, which worked without those setting, but I thought maybe the clock did have to be enabled for the uDMA. But like I said it didn't work. Thanks for the response though.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top