Other Parts Discussed in Thread: EVM430-FR6047
Hi
I'm using EVM430-FR6047 and tried below code for key detection, both edge as well as level detection of keys. Once detected, LEDs are toggled or stopped. Let me know what is going wrong here
Find code below.
// Stop watchdog timer
WDT_A_hold(WDT_A_BASE);
// Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
PMM_unlockLPM5();
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN6); // S1 P5.6: PxDIR, PxOUT and PxREN registers
GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN6,GPIO_HIGH_TO_LOW_TRANSITION); // S1 P5.6: PxIES register
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN5); // S2 P5.5: PxDIR, PxOUT and PxREN registers
GPIO_selectInterruptEdge(GPIO_PORT_P2, GPIO_PIN5,GPIO_HIGH_TO_LOW_TRANSITION); // S2 P5.5: PxIES register
SW1 = GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN6);
SW2 = GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN5);
//SW1_state = SW1 & 0x08;
// Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
//PMM_unlockLPM5();
// Set all P5IFG to zero
P2IFG = 0x00;
GPIO_enableInterrupt(GPIO_PORT_P2, GPIO_PIN6);
GPIO_enableInterrupt(GPIO_PORT_P2, GPIO_PIN5);
__bis_SR_register(GIE); // Enable all interrupts
GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN6);
GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN5);
SW1_interrupt_pre= GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN6);
SW2_interrupt_pre= GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN5);
while(1)
{
if (SW1_interrupt_pre != GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN6))
{
if (SW1_interrupt == 1)
{
SW1_interrupt = 0 ;
}
else
{
SW1_interrupt = 1 ;
}
//GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN6);
}
if (SW2_interrupt_pre != GPIO_getInterruptStatus(GPIO_PORT_P2, GPIO_PIN5))
{
if (SW2_interrupt == 1)
{
SW2_interrupt = 0 ;
}
else
{
SW2_interrupt = 1 ;
}
//GPIO_clearInterrupt(GPIO_PORT_P2, GPIO_PIN5);
}
SW1 = GPIO_getInputPinValue(GPIO_PORT_P2,
GPIO_PIN6);
SW2 = GPIO_getInputPinValue(GPIO_PORT_P2,
GPIO_PIN5);
//if (GPIO_getInputPinValue(GPIO_PORT_P5,GPIO_PIN6) == GPIO_INPUT_PIN_HIGH)
if (SW2_state == 1)
{
if (flag1 == 0)
{
flag1 = 10;
GPIO_toggleOutputOnPin( GPIO_PORT_P1,GPIO_PIN1);
}
else
{
flag1 = flag1--;
}
}
if (GPIO_getInputPinValue(GPIO_PORT_P2,GPIO_PIN6) == GPIO_INPUT_PIN_HIGH)
{
if (flag2 == 0)
{
flag2 = 4;
GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN0);
}
else
{
flag2 = flag2--;
}
}
// Delay
for(i=100000; i>0; i--);
delay = 0xFFFFFFF;
}
//return 0;
}
#pragma vector=PORT2_VECTOR //0xFFC6
__interrupt void Port_2(void)
{
//P5.5 = toggle
switch (P2IFG)
{
case 0b01000000: // S1 P5.6 = 64: toggle red LED
{
//P1OUT ^= BIT0; // Toggle P1.0
//P5IFG &= ~BIT6; // P5.6 clear interrupt flag
GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN6);
if (SW1_state == 1)
{
SW1_state = 0;
}
else
{
SW1_state = 1;
}
}
break;
case 0b00100000: // S2 P5.5 = 32: toggle green LED
{
//P1OUT ^= BIT1; // Toggle P1.1
//P5IFG &= ~BIT5; // P5.5 clear interrupt flag
GPIO_clearInterrupt(GPIO_PORT_P2,GPIO_PIN5);
if (SW2_state == 1)
{
SW2_state = 0;
}
else
{
SW2_state = 1;
}
}
break;
default: // should not be here!
{
//printf("Put an error message here. \n");
}
break;
}
}
SW1_state, and SW2_state are not toggling. Schematic of EVM attached.
Kindly review.

