"identifier not found" in C

640 views Asked by At

I'm currently programming a microcontroller (TM4C123GH6PM from Texas Instruments) with Code Composer Studion in C. For testing the code, I want to read out the voltage over a resistance. I have written this code and also checked it with an example by TI (which is pretty close to what I want to do).

In both cases, it is no problem to compile the code. But when I want to watch the expression ui32ADC0Value, Code Composer Studio shows before starting the code ui32ADC0Value = 0 with ui32ADC0Value as type unsigned int, but after starting the code it says "identifier not found" and suddenly the type gets unknown.

I can't explain that to me, because as I already said, I tried something quite similar with the code officially published by TI and in both cases the error appeared.

This is my code:

#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_ints.h"
#include"inc/hw_memmap.h"
#include"inc/hw_types.h"
#include"driverlib/gpio.h"
#include"driverlib/sysctl.h"
#include"driverlib/timer.h"
#include"driverlib/interrupt.h"
#include<math.h>
#include<driverlib/adc.h>
#include<driverlib/timer.h>


void main(void)
{
    uint32_t ui32ADC0Value;

    // set system clock
    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

    // activate ADC
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    // assign ADC function to PIN PE2
    GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_2);

    // configure ADC
    ADCSequenceConfigure(ADC0_BASE,1,ADC_TRIGGER_PROCESSOR,0); // prozessor as trigger source
    ADCSequenceStepConfigure(ADC0_BASE,1,0,ADC_CTL_CH1|ADC_CTL_IE| ADC_CTL_END); // scan AI1 /generate interrupt at the end /last step
    ADCSequenceEnable(ADC0_BASE,1); // activate ADC Sequence 1

    while(1){
        ADCIntClear(ADC0_BASE,1); // delete maybe existing ADC Interrupts
        ADCProcessorTrigger(ADC0_BASE,1); // start convertion
        while(!ADCIntStatus(ADC0_BASE,1,false)){} // wait for end of convertion
        ADCSequenceDataGet(ADC0_BASE,1,&ui32ADC0Value); // read value
    }
}

Thank you for helping me in advance.

2

There are 2 answers

0
Markus On BEST ANSWER

When I define the variable outside of main, it works. Thank you all :)

2
Carl Norum On

Optimized code can make it difficult for the debugger to know how to track your variable value. Try debugging the function with optimizations disabled, or watch the disassembly while stepping to track the value at function call points, etc.