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.

setting GPIO port of MSP430 G2553 for 3x4 Keypad interfacing on MSP-EXP430G2 Launchpad.

I have been trying to interface a 3x4 keypad on the MSP-EXP430G2 Launchpad.

Somehow while scanning the keys for button press i have been facing the problem that P1IN bits are reversed.

I was wondering if i missed something while setting the port.

here is what i have done.

/*
* I am using 3x4 keypad. Lower nibbles  Pins 0 to 3 are Rows. Upper nibbles 4 to 6 are Columns. 7th nibble is not connected.
* Columns are INPUT (P1.4, P1.5, P1.6) and Rows are Outputs(P1.0, P1.1, P1.2, P1.3)
*/

	P1SEL=0x00;
	P1SEL2=0x00;
	P1DIR=0x0F;									//P1.0, P1.1, P1.2, P1.3 used as Outputs(Rows) and P1.4, P1.5, P1.6 used as Inputs(Columns).
												//While P1.7 is not used.i.e because we are using 3x4 keypad

	P1IE=P1IE|(BIT4+BIT5+BIT6);					//Interrupts on Columns (INPUTS) P1.4, 1.5, P1.6
	P1IES=P1IES|(BIT4+BIT5+BIT6);				// Interrupt Edge Select from Hi->Lo
	P1REN=P1REN|(BIT4+BIT5+BIT6+BIt7);			// Pull up Resistor on Columns (INPUT) P1.4, P1.5, P1.6 (also P1.7 to be safe.)
	P1OUT=0xF0;// I am not sure of this

}

//for scanning the keys once inside the ISR i have have written this

    char masked;
    P1OUT=0xFE;
    masked=P1OUT&0xF0;                            // This will mask of lower bits P1.0 to P1.3.


    switch(masked)
    {
    case 0xE0:    return('1');                    // if E0 then it will return 1
    case 0xD0:    return('2');                    // if D0 then it will return 2
    case 0xB0:    return('3');                    // if B0 then it will return 3
    default:    error=('X');                    // if anything else then it will return an error.
    }

/* Not sure if its a good idea to use P1IF register to scan for the button as i suspect it would change while in ISR*/

Would be grateful if anyone can spare some time and can point out the mistake here.

  • Scanning does not lend itself to be used with IRQ, it maybe could be used to wakeup on "any" key but you still need to scan.

    step1: put the 3 inputs with pull-down REN enabled.

    step2: Set OUT1 on, wait 1ms to stabilize, read inputs for around 10ms

    step3: set OUT1 off, set OUT2 on , wait 1ms to stabilize ,read inputs for around 10ms

    step4:.....

    Active-low could also be used where inputs is pull-up and key press actually sink it to ground.

  • Thanks Tony will try that.

    Cheers!
    -c1

**Attention** This is a public forum