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.

TMS320F28069: Interfacing with 4x4 matrix Keypad

Part Number: TMS320F28069

I tried to interface the TMS320F28069 with 4x4 matrix keypad, i was able to detect columns but not rows, so when I press some key in the keypad it detects random one from that column. I checked the voltage with a multi-meter across column pin it is reaching 0 from 3.3 when pressed and then I make row pin high to detect high voltage from zero at that column, but the high signal is not generating to detect row. Please look into the code and ask for anything you didn't understand. Please help to solve the issue.

#include "DSP28x_Project.h"

void update(unsigned char);
unsigned char val = 0;

/*extern Uint16 RamfuncsLoadStart;
extern Uint16 RamfuncsLoadEnd;
extern Uint16 RamfuncsRunStart;
extern Uint16 RamfuncsLoadSize;*/

void main(void) {

   // memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (Uint32) &RamfuncsLoadSize);

    // Initialize PLL, Watchdog, enable peripheral clocks
    InitSysCtrl();

    EALLOW;
    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //rows as output
    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;
    GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO4 = 1;
    GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 1;
    GpioCtrlRegs.GPAMUX1.bit.GPIO6 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO6 = 0; //columns as input
    GpioCtrlRegs.GPAMUX1.bit.GPIO7 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO7 = 0;
    GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO8 = 0;
    GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO9 = 0;

    GpioCtrlRegs.GPAQSEL1.all = 0x0000;   // GPIO0-GPIO15 Synch to SYSCLKOUT
    GpioCtrlRegs.GPAPUD.all = 0x003C;      // Pullup's enabled GPIO0-GPIO31
    EDIS;

    DINT;                                   // disable interrupts

    // Initialize PIE control registers
    InitPieCtrl();

    IER = 0x0000;
    IFR = 0x0000;


    // Initialize PIE vector table to default ISR
    InitPieVectTable();
    // InitFlash();

    while (1)
    {
        GpioDataRegs.GPACLEAR.bit.GPIO2 = 1;
        GpioDataRegs.GPACLEAR.bit.GPIO3 = 1;
        GpioDataRegs.GPACLEAR.bit.GPIO4 = 1;
        GpioDataRegs.GPACLEAR.bit.GPIO5 = 1;

       if (GpioDataRegs.GPADAT.bit.GPIO6 == 0){
           GpioDataRegs.GPASET.bit.GPIO2 == 1;
           if (GpioDataRegs.GPADAT.bit.GPIO6 == 1)
               update('1');
           else {
                GpioDataRegs.GPASET.bit.GPIO3 == 1;
                if (GpioDataRegs.GPADAT.bit.GPIO6 == 1)
                    update('4');
                else {
                     GpioDataRegs.GPASET.bit.GPIO4 == 1;
                     if (GpioDataRegs.GPADAT.bit.GPIO6 == 1)
                         update('7');
                     else {
                          GpioDataRegs.GPASET.bit.GPIO5 == 1;
                          if (GpioDataRegs.GPADAT.bit.GPIO6 == 1)
                              update('*');
                     }
                }
           }
       }
       if (GpioDataRegs.GPADAT.bit.GPIO7 == 0){
           GpioDataRegs.GPASET.bit.GPIO2 == 1;
           if (GpioDataRegs.GPADAT.bit.GPIO7 == 1)
               update('2');
           else {
                GpioDataRegs.GPASET.bit.GPIO3 == 1;
                if (GpioDataRegs.GPADAT.bit.GPIO7 == 1)
                    update('5');
                else {
                     GpioDataRegs.GPASET.bit.GPIO4 == 1;
                     if (GpioDataRegs.GPADAT.bit.GPIO7 == 1)
                         update('8');
                     else {
                         GpioDataRegs.GPASET.bit.GPIO5 == 1;
                         if (GpioDataRegs.GPADAT.bit.GPIO7 == 1)
                             update('0');
                     }
                }
           }
       }
       if (GpioDataRegs.GPADAT.bit.GPIO8 == 0){
           GpioDataRegs.GPASET.bit.GPIO2 == 1;
           if (GpioDataRegs.GPADAT.bit.GPIO8 == 1)
               update('3');
           else {
                GpioDataRegs.GPASET.bit.GPIO3 == 1;
                if (GpioDataRegs.GPADAT.bit.GPIO8 == 1)
                    update('6');
                else {
                     GpioDataRegs.GPASET.bit.GPIO4 == 1;
                     if (GpioDataRegs.GPADAT.bit.GPIO8 == 1)
                         update('9');
                     else {
                         GpioDataRegs.GPASET.bit.GPIO5 == 1;
                         if (GpioDataRegs.GPADAT.bit.GPIO8 == 1)
                             update('#');
                     }
                }
           }
       }
       if (GpioDataRegs.GPADAT.bit.GPIO9 == 0){
           GpioDataRegs.GPASET.bit.GPIO2 == 1;
           if (GpioDataRegs.GPADAT.bit.GPIO9 == 1)
               update('A');
           else {
                GpioDataRegs.GPASET.bit.GPIO3 == 1;
                if (GpioDataRegs.GPADAT.bit.GPIO9 == 1)
                    update('B');
                else {
                     GpioDataRegs.GPASET.bit.GPIO4 == 1;
                     if (GpioDataRegs.GPADAT.bit.GPIO9 == 1)
                         update('C');
                     else {
                         GpioDataRegs.GPASET.bit.GPIO5 == 1;
                         if (GpioDataRegs.GPADAT.bit.GPIO9 == 1)
                             update('D');
                     }
                }
           }
       }
    }
}

void update(unsigned char data)
{
    val = data;
}



  • Hi Rahul,

    What do you mean by "I make row pin high to detect high voltage from zero at that column, but the high signal is not generating to detect row."

    So, you use column value internally to make the row pin high?

    Did you try just by toggling the GPIO pins to check if the rows are working as expected.
    Please refer to GPIO examples to check it.

    Thanks,
    Katta
  • I am making 4 pins of rows as output and 4 pins of columns as input. The column pins are configured as pull up internally. So, there will be 3.3V initially and I am give low i.e, 0V to rows as output. Now, when I press a button it gets shorted and the 3.3V of respective column becomes 0V, by that I am detecting which column the key is pressed. Now, to detect row i am sending high voltage in each row pin and checking for column pin going high. If this happens I can detect row also and exact position is detected.

    But the problem, everything is working fine till I detect column and then I will send high voltage in each row pin, which is not happening. So, in code I am setting those pins but when I check with multi-meter there is no voltage, due to which I cant detect row.

    You can see the nested IF loops in code, where this is happening.

  • Hi Rahul,

    Can you share an image of the layout you are using of this 4x4 matrix? I dont' understand when you say "Now, to detect row i am sending high voltage in each row pin".

    Row pin is an output pin. You are not expected to give a high volatage to the output pin.

    Excluding your code, did you check if the same pin is reading a high voltage when it is set from the code?

    Thanks,
    Katta
  • https://embedjournal.com/interface-4x4-matrix-keypad-with-microcontroller/

    Please refer to above link, this is the logic based on which I coded.

    Yes, when I am writing high voltage to the output row pin, it is not reading a high voltage, due to which the part of code which detects row is not working.

    Thanks.

  • Rahul,

    I think you may have a timing issue. Even though electricity is fast, due to capacitive loading the GPIO transitions are not "zero time".  I think you code may be executing faster than the GPIO is able to transition between logic levels.

    I hope it helps.

    Regards,
    Cody 

  • Since this thread hasn't received a reply for some time I am going to close it. Feel free to comment back if your question hasn't been answered, or start a new thread if you have other questions.

    Regards,
    Cody