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.

Interfacing 3X4 keypad matrix with MSP430F5x series

Other Parts Discussed in Thread: MSP430F5635

 Hi

I have to interface a 3x4 keypad matrix to MSP430F5635.

It has 3 colums and 4 rows.

The three column lines are tied to ground and the four row lines are connected via a resistor of 10 kΩ.

I need some idea on this / any sample C code .

what happens when a key is pressed ?

what is debounce logic ? Should that be implemented as well ?

The ti samples does not contain this .

Thanks in advance .

Jenitta

 

 

  • Jenitta Rex said:
    I have to interface a 3x4 keypad matrix to MSP430F5635.

    Before considering the specific details of the MSP430,you need to understand the general principles involved in scanning a switch matrix - which will be independent of what microcontroller you use.

    People have been interfacing switch matrices to microcontrollers for many decades - so there is no shortage of information to be found in textbooks, magazines, on the interweb, etc,...

    http://www.lmgtfy.com?q=Microcontroller+switch+matrix

    http://www.lmgtfy.com?q=Microcontroller+keypad+matrix

    The three column lines are tied to ground

    That won't work!

  • Jenitta Rex said:

    ... The three column lines are tied to ground ...

    This will not work. They can be individually driven to ground by three different output pins under software control.

    The software to handle this is not unique to MSP430F5635. Debounce logic may or may not be needed depending on the application.

  • Hi,

    I have a 3x4 keypad matrix board .

    i have connected the column pins to pins 2.0 , 2.3 and 2.6 of the MSP430F5 series experimeter board.

    I have connected the row pins to pins 4.0 , 4.4 , 4.5 , 4.7 .

    i want to make the column pins interrupting , so that from my ISR vector , i will know which pin of port 2 interrupted and thereby the column number .

    How do i initialize the column pins and row pins for this purpose ?


    see my code below .. that is not working .

    I HAVE CONFIGURED columns as input with Interrupt enabled and pull up resistor enabled .

     P2IE   |= BIT0 + BIT3 + BIT6;        // Enable interrupt for P2.0 , P2.3 , P2.6
     P2REN  |= BIT0 + BIT3 + BIT6;      // Resistor enable
     P2OUT  |= BIT0 + BIT3 + BIT6;      // pull up

    Rows are configured as output and set to high
     P4DIR |= BIT0 + BIT4 + BIT5 + BIT7;  // Configure P4.3 to P4.6 as output
     P4OUT |= BIT0 + BIT4 + BIT5 + BIT7;

    then enabled interrupts
     __bis_SR_register(GIE);

    After this initialization , if i press any key , i am not getting interrupt .

    Please help

    Thanks in advance

    Jenitta

  • hI

    one more thing .

    After i find the column that interrupted , how do i get the row number ?

    Every tutorial on this topic has a different explanation / procedure .

    i am confused.

    the key pad i use is a normal one that has 12 switches (3x4 keypad matrix )and the row pins are set as output and driven 1.

    column pins are set as input and pull up resistor enabled.

    thanks in advance .

    Jenitta

  • A matrix keyboard cannot be accessed through passive waiting for a keypress. This only works if there is exactly one button connected to one port pin.

    Ona matry, you must scan it. This is done by e.g. connecting the columns to (pulled-up) input pins and the rows to output pins.

    Then you pull one row low, and if any of the column inputs go low at the same time, you know that  the corresponding button on this row has been pressed. Then you release the row (not pull it high! Switch from output to input instead) and pull the next row low and check again. Two simultaneous button presses can be detected this way (which would cause a shortcut if you pull the rows high and press two buttons in the same column). If you press three of which are two in the same row and two in the same column, a fourth 'alias' button press is detected too that is on the fourth 'corner' of this rectangle. There's no way around this except if you place diodes in your buttons.

    You can combine the two methods (individual button detection by interrupt and matrix scanning), By pulling all rows low and go to sleep. When any of the buttons is pressed, you'll get a port interrupt on the inputs and then you have to make a scanning run to identify the button.

  • 1.  what do you mean by pull one row low ?

    Setting that pin to 0 ?

    eg. row 1 is connected to P1.0 . its configured as output .

    By pull row 1 low , do you mean P1OUT |= BIT0;  ???

    2. What is meant by release the row ?

    Setting that pin to input , instead of output ?

    3.  how to find if a "column input go low " ?

    is it by checking the PxIN value ?

    4. When the key pressed is found , should the rows be configured as output again ?

    5. what should be initial condition of the row pins ? output and HIGH  or output and LOW ?

    Thanks a lot .

    Jenitta

     

  • Jenitta Rex said:

    ... How do i initialize the column pins and row pins for this purpose ? ...

    Some small changes:

    columns as input with negative edge Interrupt enabled and pull up resistor enabled

     P2IES |= BIT0 + BIT3 + BIT4;

     P2IE   |= BIT0 + BIT3 + BIT6;        // Enable interrupt for P2.0 , P2.3 , P2.6
     P2REN  |= BIT0 + BIT3 + BIT6;      // Resistor enable
     P2OUT  |= BIT0 + BIT3 + BIT6;      // pull up

    Rows are configured as output and set to high low
     P4DIR |= BIT0 + BIT4 + BIT5 + BIT7;  // Configure P4.3 to P4.6 as output
     P4OUT |= BIT0 + BIT4 + BIT5 + BIT7;

     P4OUT &= ~(BIT0 + BIT4 + BIT5 +BIT7);

    then enabled interrupts after IFGs are cleared

      P2IFG = 0;

      __bis_SR_register(GIE);

  • Jenitta Rex said:

    ... After i find the column that interrupted , how do i get the row number ? ...

    After the ISR, you select one of the row pins as output low and change the other two row pins to input. If the column pin remains low, the selected row is the row that causes the interrupt. If not, you select a different row and read column pin again until you find the correct row.

    Note that contact bouncing and multiple key press are not handled in this simplified scheme.


  •  

    Thanks a lot !

    The keypad driver works .

    Thanks again !

**Attention** This is a public forum