Hello, Good day!
I am developing with microcontroller MKE04Z8M4 and I am trying to use interrupts that are generated by the keypad. These interrupts are related to the pins: PTA0, PTA1, PTA2, PTA3, PTB0, PTB1, PTB2 and PTB3. To perform my test I am using PTB0 pin.
However, I have difficulties using the resources of the KDS tool (Kinetis Design Studio). It doesn't provide a "Bean" for the keyboard interrupts.
I'm using the feature "Init_KBI", found in "Components Library / Categories / CPU Internal Peripherals / Peripheral Initialization / Init_KBI ". After creating that component, I configure its property "Component Inspector - KABI0" as follows:
Settings :
“Clock gate” : “Do not Initialize”
“Detection mode” : “edges only”
And in all Pin Sensitivity I leave as : “Falling edge or low level”
Pins/Signals
I enable this option only for pin 4
“Input pin 4” : “PTB0”
“Input pin 4 signal” : “KBI0_Pin_PTB0”
Interrupts
“Interrupt request” : TRUE
“Interrupt priority” = 0
“ISR name” = “Int_ISR”
“KBI_Interrupt” = TRUE
Initialization
“Call Init method” = TRUE;
After having set the component "Init_KBI", I use the feature "Generate Code Processor Expert" and get the following result:
Components
KBI0:Init_KBI
Init_ISR
Init
PDD(directory)
A module was created to initialize KDB0 like this:
void KBI0_Init(void)
{
/* KBI0_SC: ??=0,??=0,??=0,??=0,KBF=0,KBACK=0,KBIE=0,KBMOD=0 */
KBI0_SC = 0x00U;
/* KBI0_ES: KBEDG=0 */
KBI0_ES = KBI_ES_KBEDG(0x00);
/* KBI0_PE: KBIPE=0x10 */
KBI0_PE = KBI_PE_KBIPE(0x10);
/* KBI0_SC: KBACK=1 */
KBI0_SC |= KBI_SC_KBACK_MASK;
/* KBI0_SC: KBIE=1 */
KBI0_SC |= KBI_SC_KBIE_MASK;
}
And below this function, there is a commented code block referring to an ISR:
/*
** ###################################################################
**
** The interrupt service routine(s) must be implemented
** by user in one of the following user modules.
**
** If the "Generate ISR" option is enabled, Processor Expert generates
** ISR templates in the CPU event module.
**
** User modules:
** main.c
** Events.c
**
** ###################################################################
PE_ISR(Int_ISR)
{
// NOTE: The routine should include actions to clear the appropriate
// interrupt flags.
//
}
*/
And, obeying the comment, I'm putting that function in module "Events.c". After these procedures I build the project, start the debugger, boot up and execute the code Step by Step. As I enter the function "KBI0_Init" a Hard fault error happens. It seems the
compiler doesn't recognize my ISR, although it appears at the interrupt vectors table. I couldn't find the solution to this problem. Has someone managed to use keyboard interrupts for this chip using the KDS tool?
Hi Guilherme
I can't help with KDS tool but I have used the KBI on several KE parts (parts with 8 and 32 bit register sets, whereby yours has the 8 bit register set).
This version is in fact very simple (almost the same as the IRQ module but with multiple input possibilities) - I showed my code here which may help you find a difference between the tool generated code and the code that I have successfully used.
See https://community.freescale.com/message/465138#465138
Regards
Mark
P.S. It may be that your code is just forgetting to enable the KBI clock in SIM_SCGC and then you would have a hard fault when you try to write to any of its registers