Other Parts Discussed in Thread: EK-TM4C123GXL
Tool/software: Code Composer Studio
Hey all! I am trying to figure out the ADC for the Tiva, but I am new to using TivaWare (I am really only familiar with the MSP430).
Anyway, right now my program is getting stuck in the while-loop that waits for the ADC conversion to complete (i.e. while(!ADCIntStatus(ADC0_BASE, 0, false)) {}). It definitely gets stuck there because I have the blue LED toggling before and after the ADC operation, but it never actually toggles the second time.
Also, if you have time please check out the UART part of the code as well. That's priority #2, but it's also not working.
Thanks so much!!!
Please take a look at my code below to see what I'm overlooking:
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include "driverlib/adc.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "inc/hw_adc.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "utils/uartstdio.h"
#include "driverlib/rom.h"
//*****************************************************************************
//
// Configure the ADC and its pins.
//
//*****************************************************************************
void
ConfigureADC(void)
{
//-----------ADC Setup----------------
//------------------------------------
//
// Enable peripheral ADC0 and reset to apply
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
//
// Disable ADC0 sequencer 0 and reconfigure ADC0 sequencer
//
ADCSequenceDisable(ADC0_BASE,0);
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_TS /*AIN0*/ | ADC_CTL_IE | ADC_CTL_END);
//
// Enable GPIO Port E and set Pin 3 to ADC Type
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
//
// Enable interrupt for ADC0 SS0
//
ADCIntEnable(ADC0_BASE, 0);
}
//*****************************************************************************
//
// Configure the UART and its pins. This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
//-----------UART Setup---------------
//------------------------------------
//
// Enable GPIO and UART 1 Peripherals
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlDelay(3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlDelay(3);
//
// Configure GPIO Pins for UART Mode
//
GPIOPinConfigure(GPIO_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
//
// Initialize UART (port, baud rate, clock source)
//
UARTStdioConfig(0, 9600, 16000000);
}
int main(void) {
uint32_t result;
volatile char voltage;
//
// Clock Setup to 40 MHz
//
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
ConfigureADC();
ConfigureUART();
IntMasterEnable();
UARTprintf("Hello, world!\n");
while(1)
{
//
// Turn on the BLUE LED.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
//
// Delay for a bit.
//
SysCtlDelay(SysCtlClockGet() / 10 / 3);
//---------------ADC-----------------
//
// request ADC conversion
//
ADCProcessorTrigger(ADC0_BASE, 0);
//
// Clear interrupt flag for ADC0 sequencer 3
//
ADCIntClear(ADC0_BASE, 0);
//
// Wait until the conversion is finished
//
while(!ADCIntStatus(ADC0_BASE, 0, false)) {} // THIS IS WHERE THE PROGRAM FREEZES!!!
//----------Process the Data---------------
//
// Read in the data and convert
//
ADCSequenceDataGet(ADC0_BASE, 0, &result);
voltage = result*0.000805664;
//
// Turn off the BLUE LED.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
//
// Delay for a bit.
//
SysCtlDelay(SysCtlClockGet() / 10 / 3);
}
}