AnsweredAssumed Answered

KEA8 KBI & GPIO port Active

Question asked by Ahn Joseph on Jun 24, 2017
Latest reply on Jun 27, 2017 by Mark Butcher

I have tested success of  Functions KBI & GPIO with EVM KIT TRK-KEA8

I want to ports change

 

I had tried code to change of Initial port
But what cannot enter to KB0_IRQ Handler() and can't read port state..

 

Can you please advice below my code 

 

* Port changes 

----------------------------------------------------

 ** Input 

 KBI SW1 :  PORTC4 --> PORTB0

 KBI SW2 :  PORTC5 --> PORTB1

 

** Output 

PORTC0 --> PORTB5

PORTC1 --> PORTB6

PORTC2 --> PORTB7

 

 

Origin code 

void GPIO_Init()
{
CONFIG_PIN_AS_GPIO(PORT_C,16,OUTPUT); /* Configure LED 0 (PTC0) as an output */
CONFIG_PIN_AS_GPIO(PORT_C,17,OUTPUT); /* Configure LED 1 (PTC1) as an output */
CONFIG_PIN_AS_GPIO(PORT_C,18,OUTPUT); /* Configure LED 2 (PTC2) as an output */
CONFIG_PIN_AS_GPIO(PORT_C,19,OUTPUT); /* Configure LED 3 (PTC3) as an output */
CONFIG_PIN_AS_GPIO(PORT_A,6,OUTPUT);

CONFIG_PIN_AS_GPIO(PORT_C,20,INPUT); /* Configure SW1 (PTC4) as an input */
CONFIG_PIN_AS_GPIO(PORT_C,21,INPUT); /* Configure SW2 (PTC5) as an input */
ENABLE_INPUT(PORT_C,20); /* Enable input SW1*/
ENABLE_INPUT(PORT_C,21); /* Enable input SW2*/

}

 


void KBI_Init()
{
SIM_SCGC |= SIM_SCGC_KBI1_MASK; /* Enable bus clock on KBI1 */
KBI1_SC = 0; /* Clearing mechanism */
KBI1_ES |= KBI_ES_KBEDG(1);/* Polarity setting, falling edge low level ,SW1 */
KBI1_ES |= KBI_ES_KBEDG(2);/* Polarity setting, falling edge low level ,SW1 */
PORT_PUEL=0; /* No internal pullup*/
KBI1_PE |= KBI_PE_KBIPE(1); /* Enable KBI1 channel 0 , SW1 */
KBI1_PE |= KBI_PE_KBIPE(2); /* Enable KBI1 channel 1 , SW2 */
KBI1_SC = 0; /* Clearing flags and RSTKBSP bit */
KBI1_SC |= KBI_SC_KBIE_MASK; /* Enable KBI1 Interrupts */

 

 

//** Change to setup NEW port  


SIM_SCGC |= SIM_SCGC_KBI0_MASK; /* Enable bus clock on KBI1 */
KBI0_SC = 0; /* Clearing mechanism */
KBI0_ES |= KBI_ES_KBEDG(4);/* Polarity setting, falling edge low level ,SW1 */
KBI0_ES |= KBI_ES_KBEDG(5);/* Polarity setting, falling edge low level ,SW1 */
PORT_PUEL=0; /* No internal pullup*/
KBI0_PE |= KBI_PE_KBIPE(4); /* Enable KBI4 channel 4 , SW1 */
KBI0_PE |= KBI_PE_KBIPE(5); /* Enable KBI5 channel 5 , SW2 */
KBI0_SC = 0; /* Clearing flags and RSTKBSP bit */
KBI0_SC |= KBI_SC_KBIE_MASK; /* Enable KBI1 Interrupts */

}

 


void KBI1_IRQHandler()
{
KBI1_SC |= KBI_SC_KBACK_MASK; /*Clear flag*/
if((GPIOA_PDIR & GPIO_PDIR_PDI(0x100000))>>20) /* If SW1 has been pressed */
{

 

LED0_TOGGLE;
PIT_Config0.bTimerEn = TRUE;
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;


}
else if((GPIOA_PDIR & GPIO_PDIR_PDI(0x200000))>>21) /* If SW2 has been pressed *

 

{
__asm("nop");
Flag_sleep=1;
__asm("nop");

 

 

}
}

//** To setup NEW port  IRQ Handler 

void KBI0_IRQHandler()
{
KBI1_SC |= KBI_SC_KBACK_MASK; /*Clear flag*/
if((GPIOA_PDIR & GPIO_PDIR_PDI(0x100))>>8) /* If Folding_SW1(PTB0) has been pressed */
//if(GPIOA_PDIR == 0x101020) /* If SW1 has been pressed */
//0x101020
{
//GPIOA_PTOR |=1<<16; /* LED Toggle at port C0*/
LED0_TOGGLE;
PIT_Config0.bTimerEn = TRUE;
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;

//LED1_TOGGLE;
}
else if((GPIOA_PDIR & GPIO_PDIR_PDI(0x200))>>9) /* If Walk_IN_SW2(PTB1) has been pressed *
//else if(GPIOA_PDIR == 0x201020) /* If SW2 has been pressed */
{
//GPIOA_PTOR |=1<<16; /* LED Toggle at port C0*/
__asm("nop");
//LED1_TOGGLE;
Flag_sleep=1;
//__asm__("wfi");
__asm("nop");
//reset;

}
}

Outcomes