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.

High level trigered interrupt. Same port, two different pins.

Hy,

I'm trying to write a high level triggered ISR, for port F, pins 0 and 4.

What I would like to do is to have a certain code executed when PF0 is high, different code when PF4 and different when both of them are high.
At the moment if PF4 is high, PF0 can interrupt it and run the code for PF0 but not vice versa.
And also if bouth of them are high, only the PF0 code will run.

My initialization function is: 

void INT_Light_sensor_init(void)
{
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);																			//Enable clock on port F
	GPIO_PORTF_LOCK_R = 0x4C4F434B;  																									//Unlock PortF PF0  
  GPIO_PORTF_CR_R |= 0x1F;      																								    //Allow changes to PF4-0
	
	IntMasterDisable();																																//Global disable of interrupts
	IntDisable(INT_GPIOF);																														//GPIO Port F disable of interrupts
	GPIOIntDisable(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4);													//Disable GPIO pin interrupt
	
	GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4);										//Set PF0 and PF4 as GPIO Input
	GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_LOW_LEVEL);					//Set Low level interrupt type
	GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_DIR_MODE_IN);				//Set direction input for PF0 and PF4
	GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU); //Configure PUR for PF0 and PF4

	GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_0 | GPIO_INT_PIN_4);									//Enable GPIO pin interrupt
	
	IntPrioritySet(INT_GPIOF,0x40); 																									//Priority 2 = "010"0.0000
	IntEnable(INT_GPIOF);																															//GPIO Port F enable of interrupts
	IntMasterEnable();																																//Global enable of interrupts
}

And my ISR function is:

void GPIOPortF_Handler(void)
{
	unsigned long Light_sensor_status = 0;
	Light_sensor_status = GPIOIntStatus(GPIO_PORTF_BASE,false);
	GPIOIntClear(GPIO_PORTF_BASE,GPIO_INT_PIN_0 | GPIO_INT_PIN_4);
	if(Light_sensor_status & GPIO_INT_PIN_0)
	{
		//Go Left
		Motion_Go_Left();
	}
	else if(Light_sensor_status & GPIO_INT_PIN_4)
	{
		//Go Right
		Motion_Go_Right();
	}
	else if(Light_sensor_status & (GPIO_INT_PIN_0 | GPIO_INT_PIN_4))
	{
		//Go straight ahead
		Motion_Cruise();
	}
}

So, the question is: Is there a way to set sub priorities within the same port?
Can an ISR handle two interrupt sources at the same time (PF0 and PF4) ?

Regards,
Alex

  • Hi Gaal,
    GPIO discrete pin interrupts are available on some TM4 processors. The TM4C1294 supports GPIO port P and Q individual per pin vectors defined in (startup_ccs.c) . In that case PF0 and PF4 would be assigned there own interrupt vectors. In you code above you have to read the entire port F pins, & the IMS to determine the state if (status high or low) during the block interrupt GPIO port F.

    The reply to your question seems to be yes it can handle both sources at the same time if either one asserts an interrupt. That is of course after your code determines which pin asserted by comparing the Boolean state of the pin.
  • Can a pin - declared & defined as input - have anything (other) than a "Boolean" state? (if properly driven & terminated)

    What is the value of "Boolean" w/in your usage?    Is not pin's, "state" sufficient?

    Let's extend that, "bp convention"...Boolean High, Boolean Low, Boolean On, Boolean Off, Boolean 1, Boolean 0...ad infinitum.   Is this better/clearer?

  • Umm how and when the compared integer in the IF clause is determined Boolean state valid. From the codes point of view the Boolean test clause may never be true. Anyhow that seems to be the case poster reported.
  • Gaal Alexandru said:
    if both of them are high, only the PF0 code will run.

    Doesn't your first clause w/in your "if test" insure that?    "if(Light_sensor_status & GPIO_INT_PIN_0)"  

    Should that "if" be satisfied - neither of your "else if" clauses will execute - don't you agree?

    Instead - if you elevated your last "else if" to the first "if" position? ... "if(Light_sensor_status && (GPIO_INT_PIN_0 & GPIO_INT_PIN_4))" // tests for both PF0/4

    Now this code must execute first - and (past) offending PF0 is (unlikely) to hijack the operation.   Note the logical "and" (&&) between sensor status & GPIO).

  • Hello Gaal,

    Within the same port: No. But to handle two interrupt sources one important thing to note is the race condition due to timing of the 2 switch presses. Note that there would be a finite delay when doing it manually. So you would need to build a delay in the interrupt handlers befor reading the interrupt status so that few 10's of ms can be accommodated as delay.

    Regards
    Amit
  • Yes, you were right, thanks !!!

    If the first If condition was true, the rest wasn't checked anymore.

    I corrected this with:

    	if((Light_sensor_status&(GPIO_INT_PIN_0 | GPIO_INT_PIN_4)) == (GPIO_INT_PIN_0 | GPIO_INT_PIN_4))
    	{
    		//Go Straight Ahead
    		Motion_Cruise();
    	}
    	else if(Light_sensor_status & GPIO_INT_PIN_4)
    	{
    		//Go Right
    		Motion_Go_Right();
    	}
    	else if(Light_sensor_status & GPIO_INT_PIN_0)
    	{
    		//Go Left
    		Motion_Go_Left();
    	}

    The & I used rather to mask bits 0 and 4.

    PS: Sorry for this obvious mistakes, I'm quite new in this industry :)

  • Might you change "suggested" to "verified" as you confirm correctness? Merci et bon chance mon ami.
  • I will recommend again PC-Lint

    Robert
  • Robert Adsett said:
    I will recommend again PC-Lint 

    Dear Amazon,

    Would you be so good as to extend my order (beyond) "Robert's Bookshelf?"   Kindly add "Robert's Toolkit" and updated version of "PC-Lint."    Merci.

    And thanks to poster Gaal...   (wonder what the shipping will cost as we are not (yet) Prime qualified...)