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: cannot make ADC0 SS3 work at interrupt mode

Part Number: TM4C123GH6PM

Hi,

I tried to configure TivaC to work with ADC in interrupt mode but it doesn't work

bit 3 in ADCIM for ADC0 is set, bit 2 in ADCSSCTL3 for ADC0 is set, bit 17 in EN0 is set.

also all required registers are set to make ADC0 work and i tested then by working polling based and i worked fine.

What should i do also to make it works ?

Thanks.

  • Your problem description is too vague for me to offer specific help. In general you must either register the interrupt service routine with the function IntRegister() or edit the startup_ccs.c file to make the ADC Sequence 3 vector (line107) to point to your interrupt routine instead of "IntDefaultHandler". You need to enable the master interrupts with a call to IntMasterEnable(), and you need to enable the ADC0 sequence 3 interrupt with a call to IntEnable(INT_ADC0SS3).
  • line 107 is // Timer 1 subtimer A did you mean line 103 (// ADC Sequence 3)?
    i didn't change IntDefaultHandler and i wait for the system to enter while(1) to make sure that is working then i will change it
    which header file include this function IntMasterEnable() ?
    and which one for this function IntEnable(INT_ADC0SS3) ?
  • Yes, sorry. I mean the line for ADC Sequence 3. The line numbers will change as you will also need to add  a function prototype for your interrupt routine line  like:

    extern void MyADC0Seq3IntRoutine(void);

    Add these two header files:

    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"
    

  • Bob Crosby said:
    #include "inc/hw_ints.h"
    #include "driverlib/interrupt.h"



    I am working code composer and these two header files cannot be found so should i download them or what ?
  • These header files are part of TivaWare. The default installation location of the latest version of TivaWare is:
    C:\ti\TivaWare_C_Series-2.1.4.178

  • I downloaded TivaWare, installed it and used this code from internet

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h""
    #include "inc/hw_types.h"
    #include "inc/tm4c123gh6pm.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/debug.h"
    #include "driverlib/gpio.h"
    #include "driverlib/adc.h"
    #include "driverlib/rom.h"
    #include "driverlib/timer.h"
    #include "driverlib/interrupt.h"
    
    const int sampleFreq = 8000;
    
    uint32_t ADC0Value[1];
    uint16_t samplePeriod;
    
    uint8_t x = 0;
    
    void systemSetup(void){
        // *** Clock
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    
        // *** Peripheral Enable
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    
        // *** ADC0
        ROM_ADCHardwareOversampleConfigure(ADC0_BASE,4);
        ROM_ADCReferenceSet(ADC0_BASE,ADC_REF_INT);
        ROM_ADCSequenceConfigure(ADC0_BASE,3,ADC_TRIGGER_TIMER,0);
        ROM_ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH7|ADC_CTL_IE|ADC_CTL_END);
        ROM_ADCSequenceEnable(ADC0_BASE,3);
    
        // *** Timer0
        ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_PERIODIC);
        samplePeriod = ROM_SysCtlClockGet()/sampleFreq;
        ROM_TimerLoadSet(TIMER0_BASE,TIMER_A,samplePeriod - 1);
        ROM_TimerControlTrigger(TIMER0_BASE,TIMER_A,true);
    
        // *** GPIO
        ROM_GPIOPinTypeADC(GPIO_PORTD_BASE,GPIO_PIN_0);
    
        // *** Interrupts
        ROM_IntEnable(INT_TIMER0A);
        ROM_TimerIntEnable(TIMER0_BASE,TIMER_TIMA_TIMEOUT);
        ROM_IntEnable(INT_ADC0SS3);
        ROM_ADCIntEnable(ADC0_BASE,3);
    
        ROM_IntMasterEnable();
        ROM_TimerEnable(TIMER0_BASE,TIMER_A);
    }
    
    int main(void)
    {
    
        systemSetup();
    
        while(1)
        {
    
        }
    
        return 0;
    }
    
    void Timer0IntHandler(void){
        ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
    
    }
    
    void ADC0SS3IntHandler(void){
        x++;
        ROM_ADCIntClear(ADC0_BASE,3);
    
        ROM_ADCSequenceDataGet(ADC0_BASE,3,ADC0Value); // Get Data from ADC and store it in ADC0Value
    }
    

    i expected while running the code x increase with time but it remains at 0 why?

    i added Timer0IntHandler at Timer 0 Subtimer A and ADC0SS3IntHandler at ADC Sequence 3

  • Hello Mohamed,

    You need to declare the variable 'x' as a volatile for it to be updated within your ISR. This can be done as follows:

    volatile uint8_t x = 0;

    Please see this E2E post for background as to why this is important when using a global variable within an ISR: e2e.ti.com/.../2550611

  • aha i forgot to do that but also after i made it volatile i expected to run the chip and by tracking x at the debug i should saw it increase by the rate of timer but x didn't change from 0 
    What is the problem ?

    Best Regards.

  • Thank you,
    That was the problem.
    Best Regards.