SupItsChris
Newbie
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
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.
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: