I'm working on first ARM core, specifically the EK-TM4C123GXL board, which uses the the TM4C123GH6PMI controller. I'm trying to set up a simple program to poll the ADC and turn on some GPIO pins based on the value. I have not implemented the GPIO stuff yet as I'm trying to get the ADC working before going any further.
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
//#include "driverlib/rom.h"
/***************************************************************************/
#define ONE_LED 0x01
#define TWO_LED 0x03
#define THREE_LED 0x07
#define FOUR_LED 0x0F
/***************************************************************************/
int main(void)
{
uint32_t pui32ADC0Value[1];
//Configure clock
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//Enable Port E
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//Enable ADC0 using Port E/Pin 2, then enable the sequence
//and finally clear the interrupt flag
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 3);
ADCIntClear(ADC0_BASE, 3);
while(1)
{
//Trigger the read, wait for it to finish, clear the
//interrupt flag and finally read the data
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false)) {}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
// this is here simply for debugging purposes
pui32ADC0Value[0]++;
/* Add code to process later...
if (pui32ADC0Value[0] < 1000)
{
}
else if (pui32ADC0Value[0] >= 1000 && pui32ADC0Value[0] < 2000)
{
}
else if (pui32ADC0Value[0] >= 2000 && pui32ADC0Value[0] < 3000)
{
}
else
{
}
*/
SysCtlDelay(SysCtlClockGet() / 12);
}
}
My code is always stuck in the while(!ADCIntStatus(ADC0_BASE, 3, false)) {} loop and won't go from there. This is my first project on this processor so maybe I have a configuration issue in CCS? Also, I've seen some projects that use the ROM_ (function_name) Macro to accomplish tasks. What is the difference between that and simply calling the function itself (e.g. SysCtlPeripheralEnable vs ROM_SysCtlPeripheralEnable)? When I try and do this by including the ROM header file the code is "greyed out", as to indicate that it won't be compiled because none of the requested parameters are defined. I can post more info if needed, thanks for the help!