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.

TM4C123GH6PM: Help in Code

Part Number: TM4C123GH6PM


I am trying to read configure ADC module in TM4C123GH6PM Evaluation board. I want to read voltage at pin PE3. But my code is not working. Please help as I am new to embedded. I am following TM4C123GH6PM workshop.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"

int main(void)
{
uint32_t result[1];
volatile uint32_t x;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH0);
ADCSequenceEnable(ADC0_BASE, 3);
while(1)
{
ADCIntClear(ADC0_BASE, 3);
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 3, result);
x = result[0];
}
}

  • Hi Jatin,

    I think the problem is with the call to ADCSequenceStepConfigure. You need to tell that the step 0 is also the last channel in the conversion by adding the ADC_CTL_END flag like:

    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

    There is a ready to use TivaWare ADC example using PE3 pin that you can reference. Please go to <TivaWare_Installation>/examples/peripherals/adc/single_ended.c.