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.

How to assign the interrupt priority?

Hai,I have been facing a problem with interrupt priority......

OBJECTIVE:

I need to trigger the ADC for every 2 sec and the same time UART interrupt should be rise for this i tried with interrupt priority but no use.Here i am not getting triggering the UART interrupt. The control is always stays in TIMER handler.What is the problem with this?

Please give me a valuable suggestions.

This is my code what i written:

ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);

IntPrioritySet(INT_TIMER0A,0x00);
IntPrioritySet(INT_ADC0SS0,0x02);
IntPrioritySet(INT_UART0,0x04);

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
// SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
// GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_6);
// GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_7);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
ROM_UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
ROM_UARTFIFOEnable(UART0_BASE);
ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
ROM_UARTTxIntModeSet(UART0_BASE, UART_TXINT_MODE_FIFO);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
ROM_IntEnable(INT_UART0);

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
ROM_IntMasterEnable();
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ROM_SysCtlClockGet());
// ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, 3*(SysCtlDelay(SysCtlClockGet() / 12)));
ROM_IntEnable(INT_TIMER0A);
ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerEnable(TIMER0_BASE, TIMER_A);


GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1); //for ADC0.3 and ADC0.2 //PE0 & PE1
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3); //for ADC0.1 and ADC0.0 //PE2 & PE3
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_4); //for ADC0.4 and ADC0.5 //PD6 & PD7
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_5 );


ROM_SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
ADCSequenceDisable(ADC0_BASE, 0); //for ADC0
// ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, 0,0,ADC_CTL_CH0); //channel 0 for vlotage
ADCSequenceStepConfigure(ADC0_BASE, 0,1,ADC_CTL_CH1); //chnnael 1
ADCSequenceStepConfigure(ADC0_BASE, 0,2,ADC_CTL_CH2); //channel 2
ADCSequenceStepConfigure(ADC0_BASE, 0,3,ADC_CTL_CH3); //channel 3
ADCSequenceStepConfigure(ADC0_BASE, 0,4,ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 0,5,ADC_CTL_CH5);
ADCSequenceStepConfigure(ADC0_BASE, 0,6,ADC_CTL_CH6 | ADC_CTL_IE | ADC_CTL_END); //channel 5
ADCSequenceEnable(ADC0_BASE, 0);
ADCIntEnable(ADC0_BASE, 0);
IntEnable(INT_ADC0SS0);
SysCtlDelay(SysCtlClockGet() / 12);
SysCtlDelay(SysCtlClockGet() / 12);

while(1)
{

data12();
SysCtlDelay(SysCtlClockGet() / 12);
SysCtlDelay(SysCtlClockGet() / 12);
//SysCtlDelay(SysCtlClockGet() / 12);
//SysCtlDelay(SysCtlClockGet() / 12);
//SysCtlDelay(SysCtlClockGet() / 12);

}
}

void
ADCHandler(void)
{

++adc_handler;
SysCtlDelay(SysCtlClockGet() / 12);
flag=1;

ADCIntClear(ADC0_BASE, 0);

// ROM_IntMasterDisable();
// ROM_IntMasterEnable();


}

void
UARTIntHandler(void)
{

++count44;
SysCtlDelay(10000);
uint32_t ui32Status;

// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART0_BASE, true);

//
// Clear the asserted interrupts.
//
UARTIntClear(UART0_BASE, ui32Status);

//
// Loop while there are characters in the receive FIFO.
//
while(UARTCharsAvail(UART0_BASE))
{

m[count]=UARTCharGetNonBlocking(UART0_BASE);

// UARTCharPutNonBlocking(UART0_BASE,m[count]);

count++;

if(count>=70)
{
//clearbuff();
// if(count==100)
count=0;
// clearbuff((unsigned char *)m);
}

}
// IntDisable(INT_ADC0SS0);
// IntDisable(INT_TIMER0A);
// ROM_IntMasterEnable();
ROM_IntMasterDisable();
ROM_IntMasterEnable();

// count10=0;
}

void
Timer0IntHandler(void)
{
//
// Clear the timer interrupt.
//
++counta;


ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

ROM_TimerControlTrigger(TIMER0_BASE,TIMER_A,1);

// ROM_IntEnable(INT_TIMER0A);

if(flag==1)
{
ADC_fun();
}

//ROM_IntDisable(INT_TIMER0A);

// IntDisable(INT_UART0);


SysCtlDelay(SysCtlClockGet() / 12);
//
// Update the interrupt status on the display.
//
check_intrpt=ROM_IntIsEnabled(INT_UART0);
ROM_IntEnable(INT_UART0);


ROM_IntMasterDisable();
ROM_IntMasterEnable();

}

  • Hi,

    Priority has nothing to do with triggering an interrupt - it has to do with concurrency - which interrupt is taken when two or more triggers the same time, since execution is done by a single CPU core (bunch of working registers).

    To trigger an interrupt, you may use this: IntPendSet(uint32_t ui32Interrupt) in your ADC interrupt if you want to send data after ADC completion/processing. Do not forget to un-pend it before exit of UART interrupt. An small example is in Tiva/driverlib/interrupt.c file.

     

  • Thank's for your reply.Is it possible both timer and UART trigger at once?
    Actually what i thought is the ADC always triggers in TIMER then how the problem is happens to the UART handler?Is both are independently work?if it is not how can i make it is independent(TIMER and UART).

    I tried with IntPendSet() &Clear but i didn't achieve.
  • Hi,
    Please note that on my first response i did not read your code. Now i read it and I can see a lot of problems:
    a) It is quite possible that you may have fault interrupts - if really the code is as you wrote it - InPrioritySet(..) functions must be called after all initializations, not before enabling peripherals.
    b) Your code for ADC handler does almost nothing useful, except clearing interrupts. It may be useful to get the ADC results there. Nothing said about your results - what to do with them - if needs to be sent, either you may insert in this routine the UART pending, either you just can prepare a buffer with all results and send first data to UART(the interrupt will take care of the rest). For that to work, you must have the UART handler onfigured for TX interrupts and inside Tx interrupt to send next data until the last byte. This way you don't need to care about additional timing - usual only that for ADC sampling will be enough. Please also remove all timing delays from all interrupts - they are not needed.
    c) Your UART handler is configured (it knows only) to receive some characters and nothing to be sent. See previous point.
    d) Your timer interrupt handler - should not contain TimerControlTrigger - this one should be written only once in configuration area (timer) - no need to call it every time. Also do not play with IntMasterDisable/IntMasterEnable - no need to do that - just enable once and never disable.
    Make a plan, work in small steps and for each line written try to figure out what is their purpose (please read Kernigham and Ritchie and adopt top-down programming).

  • Hai petrei, Now i got both TIMER and UART tigger simultaneously thank you for u r kindly information.