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.

CCS/EK-TM4C123GXL: Reading analog sensor.

Part Number: EK-TM4C123GXL

Tool/software: Code Composer Studio

Hi all,

I am trying to read analog sensor using tm4c123gxl.But the problem i am having using following code is that when i try to see value of variable to which value of ADC is supposed to be stored,it say "identifier not found" in Expression window, but if put break point anywhere between while loop, the value of variable changes to zero.

#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 "inc/hw_types.h"
#include "driverlib/rom_map.h"
#include "driverlib/rom.h"
#include "inc/tm4c123gh6pm.h"
#include "driverlib/debug.h"

int main(void)
{
    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 | ADC_CTL_IE |
                             ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 3);

    volatile  uint32_t ui32ADC0Value;

while(1)
{
    ADCProcessorTrigger(ADC0_BASE, 3);
   while(!ADCIntStatus(ADC0_BASE, 3, false))
   {
   }
     ADCIntClear(ADC0_BASE, 3);

    //
    // Read ADC Value.
    //
    ADCSequenceDataGet(ADC0_BASE, 3, ui32ADC0Value);

    SysCtlDelay(SysCtlClockGet() / 12);
}
}



  • i am absolute newbie and i put together this code using the examples, but i am not sure that how to tell ADC to read which pin.
  • Hi Awais,

    If you want to constantly see the ui32ADC0Value variable then you will need to make the variable global. When the local variable is declared inside the main() the value will only show when you are in the context of main. This is the reason if you put a break you will see the value. If you simply just stop the program then you might be stopping inside a function call. For example, the code may be executing the ADCSequenceDataGet when the debugger stops the execution. In this case, the ui32ADC0Value is only local to the main() and not ADCSequenceDataGet .
    I will suggest you start with the TivaWare example if you are new to TM4C. Please go to <TivaWare_Installation>/examples/peripherals/adc and will will find several adc examples. In your code you are currently configuring channel 0 for ADC conversion in your call to ADCSequenceStepConfigure.
  • thnx Charles i tried what you suggested but even in TivaWare examples Variable is declared in main(),but non the less when i make it global it solves the 'identifier not found" problem,but variable value remains constant at 0. I am not sure why but if i declare variable as an array like ui32ADC0Value[] it works fine.
  • but there is another problem with Tivaware example code,its related to UART,when i upload the example code i get  following error.

  • HI Awais,
    Did you either link or copy the file uartstdio.c to your project folder? The uartstdio.c is located at <TivaWare_Installation>\utils\uartstdio.c Please do so and recompile again.
  • thnx Charles, issue was resolved after i copied the uartstdio.c and uartstdio.h to my project folder.
  • Glad your problem is solved.
  • Hi Charles,

    To clarify - poster's original code is (almost) an exact copy of that provided @ "examples/peripherals/adc/single-ended.c." (I checked - and so noted) W/in those example programs they (rarely) define a "main" (I did not see it) and poster "assumed" that he could "drop the adc result variable - w/in main." Thus - your analysis - proved "Spot On." (beating moi to the punch...)

    It should be noted that the same example "avoids mention of the uartstdio.c - as well - leading our poster to the cliff..."