10 years ago.

FRDM-KL25Z keypad

Hello. I'm currently using a Freescale FRDM-KL25Z with a 4x4 matrix keypad and using the example code from http://mbed.org/cookbook/Keypad. But for some reason it isn't working properly. Nothing is outputting on the serial terminal. I've tried numerous ways to try to figure out the problem. I've tried Resistors on each pin, Resistor on the columns to ground and still no luck. Here's a snippet of my code.

KL25Z Keypad

#include "mbed.h"
#include "rtos.h"
 
#include "Keypad.h"
 
Serial        PC(USBTX, USBRX);
RtosTimer    *LedTimer;
DigitalOut    Led1(LED1);
DigitalOut    Led2(LED2);
 
// Define your own keypad values
char Keytable[] = { '1', '2', '3', 'C',   // r0
                    '4', '5', '6', 'D',   // r1
                    '7', '8', '9', 'E',   // r2
                    'V', '0', 'N', 'F'    // r3
                  };
                 // c0   c1   c2   c3
 
int32_t       Index = -1;
int           State;
 
uint32_t cbAfterInput(uint32_t index)
{
    Index = index;
    return 0;
}
 
void Blink(void const *arg) {
    if (State == 1)  {
        Led1 = 1;
        Led2 = 0;
        State = 2;
    }
    else if (State == 2)  {
        LedTimer->stop();
        Led1 = 0;
        Led2 = 1;
        LedTimer->start(2000); // longer timer alarm
        State = 1;
    }
}
 
int main()
{
    PC.printf("I am Demo Keypad\r\n");
    State = 1;
    LedTimer = new RtosTimer(&Blink, osTimerPeriodic, NULL);
    LedTimer->start(500); // short timer alarm    
    
    //             r0   r1   r2   r3   c0   c1   c2   c3
    Keypad keypad(PTA1, PTA2, PTD4, PTA12, PTA4, PTA5, PTD5, PTD0);
    keypad.attach(&cbAfterInput);
    keypad.start();  // energize the columns c0-c3 of the keypad
 
    while (1) {
        __wfi();
        if (Index > -1) {
            PC.printf("Interrupted");
            PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
            Index = -1;
        }
    }
}

Any assistance are appreciated.

3 Answers

10 years ago.

Problem one for sure is your use of pins, see: http://mbed.org/handbook/mbed-FRDM-KL25Z. PTA1 and PTA2 are the stdio pins: they are USBTX and USBRX.

Edit: I see you used the standard code. The standard code shouldn't be using the wfi command imo, but rather sleep(), or nothing at all. But that isn't your fault :).

Accepted Answer
9 years, 10 months ago.

I have a problem with Keypad, I was able to debug and I found that when the pins which I declared as rows are going to be declared as InterruptIn the "kl46z" stops and the red led begins to flash. please help me!!!

<code>

  1. include "mbed.h"
  2. include "TextLCD.h"
  3. include "Keypad.h"

DigitalOut Backlight(PTC8); TextLCD lcd(PTA1, PTA2, PTD3, PTA12, PTA4, PTA5); rs, e, d4-d7

Define your own keypad values char Keytable[] = {

'1', '2', '3', 'A',

'4', '5', '6', 'B',

'7', '8', '9', 'C',

'*', '0', '#', 'D' };

uint32_t Index;

uint32_t cbAfterInput(uint32_t index) { Index = index; return 0; }

int main() { Backlight = 1; lcd.printf("Keypad 4x4 test\n"); r0 r1 r2 r3 c0 c1 c2 c3 Keypad keypad(PTE30, PTB20, PTE23, PTE22, PTE21, PTE20, PTE2, PTE3);

lcd.printf("Keypad init\n");

keypad.attach(&cbAfterInput);

TextLCD cls();

lcd.printf("Index passed");

keypad.start(); energize the keypad via c0-c3

TextLCD cls();

lcd.printf("Ready to recive\nthe keypad input");

while (1) { wfi();

TextLCD cls();

lcd.printf("Interrupted\n");

lcd.printf("Index:%d => Key:%c", Index, Keytable[Index]); } }

/<code>

You need <<code>> and <</code>>

Anyway not all pins can be InterruptIn pins. For the KL46z it is port A, C and D. You also get that message on your serial terminal if you open it. (If you get that error state often it will tell on serial what is wrong).

posted by Erik - 27 Apr 2014

Hello Erik, First of all, thank you for your answer. Can you tell me where can i find that information?, because I'd read the "KL46 Sub-Family Reference Manua"l and it just says that all ports can be used to trigger external interrupts. "The external interrupt capability of the PORT module is available in all digital pin muxing modes provided the PORT module is enabled."

posted by Israel Pont 28 Apr 2014
Andy Lau
poster
10 years ago.

Woops! Newbie Mistake. After correcting the mistake I finally got it working. Though it's not as what I expected since It only displays the key pressed when I hold down the matrix button then reset the program. But it's a step in the right direction. Right now I'm only using the default program to see if it works before doing massive changes to the program :]

HiAndy Lau Have you found away to run the example without holding down the reset button. I'm not sure if the issue with the interrupts or with pins modes(pullup/pulldown).

posted by Yassin Jaffer 13 Mar 2014

Hello Yassin, I solved the problem it was a Pull down configuration. I used a 10k resistor in a pull down configuration.

posted by Andy Lau 17 Mar 2014