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.

CCS/TMS320F28379D: How to interface alphanumeric keypad?

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

I tried interfacing 4x4 alphanumeric keypad with F28379D microcontroller kit but it was of no use. I know out of eight pins 4 correspond to row and 4 other correspond to columns. I think that on pressing a key, two pins get short circuited. How can I proceed further? Please help

  • I think we need more details, but if what you are saying is correct, you need to dedicate 4 digital outputs and 4 digital inputs.

    And the logic goes like this:

    keypressed = false;

    Foreach output pin 0 - 3: OP

        Foreach input pin 0 - 3: IP

                If IP is high

                     { return OP and IP ; keypressed = true; break }

       next IP

    Next OP

    if keypressed == true

       // figure out what key was pressed based on OP and IP

    else

      // no key pressed

    endif

  • Hi Adarsh,

    As Keith stated, we'll need additional information to determine the issue.  I think you'll want to summarize:

    • Diagram of how the keypad functions / makes connections
    • Your strategy of how you intend to interface with the keypad and how you expect to detect the key presses
    • The results you actually got vs. your expectation

  • This is the keypad I am using

  • I have added the image of keypad in a separate reply.

    I think logic given by Keith would solve the issue. However, I have just started using the microcontroller kit and want to know how to dedicate a particular pin as input or a output pin

    Thanks in advance.

  • Hi Adarsh,

    Have a read through the GPIO example code in c2000ware here:

    \driverlib\f2837xd\examples\cpu1\gpio

    In particular, some examples of making a pin a GPIO as input or output:

        //
        // Make GPIO34 an input on GPIO34
        //
        GPIO_setPadConfig(34, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO34
        GPIO_setPinConfig(GPIO_34_GPIO34);               // GPIO34 = GPIO34
        GPIO_setDirectionMode(34, GPIO_DIR_MODE_IN);     // GPIO34 = input

    And

        //
        // Enable an GPIO output on GPIO6
        //
        GPIO_setPadConfig(6, GPIO_PIN_TYPE_PULLUP);   // Enable pullup on GPIO6
        GPIO_writePin(6, 1);                          // Load output latch
        GPIO_setPinConfig(GPIO_6_GPIO6);              // GPIO6 = GPIO6
        GPIO_setDirectionMode(6, GPIO_DIR_MODE_OUT);  // GPIO6 = output

    Note that the output state for an output is controlled by

    GPIO_writePin(6, 1);                          // Load output latch

    You'll also probably want to take a look at the driverlib GPIO module documentation in c2000ware in:

    /device_support/f2837xd/docs/html/driverlib_html/group__gpio__api.html

    And the "General-Purpose Input/Output (GPIO)" chapter in the TRM (http://www.ti.com/lit/ug/spruhm8i/spruhm8i.pdf

     

  • This is the code I wrote after importing gpio_setup from C2000ware and based on keith's logic:

    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include <stdio.h>
    
    #define EXAMPLE1 1  // Basic pinout configuration example
    #define EXAMPLE2 0  // Communication pinout example
    
    //
    // Function Prototypes
    //
    void setup1GPIO(void);
    
    //
    // Main
    //
    void main(void)
    {
        //
        // Initializes system control, device clock, and peripherals
        //
        Device_init();
    
        //
        // Initializes PIE and clear PIE registers. Disables CPU interrupts.
        // and clear all CPU interrupt flags.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
    #if EXAMPLE1
    
        //
        // This example is a basic pinout
        //
        setup1GPIO();
    
    #endif  // - EXAMPLE1
    
    
    }
    
    void setup1GPIO(void){
        GPIO_setPadConfig(6, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO6
        GPIO_writePin(6, 1);
        GPIO_setPinConfig(GPIO_6_GPIO6);                // GPIO6 = GPIO6
        GPIO_setDirectionMode(6, GPIO_DIR_MODE_OUT);    // GPIO6 = output
    
        GPIO_setPadConfig(7, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO7
        GPIO_writePin(7, 1);
        GPIO_setPinConfig(GPIO_7_GPIO7);                // GPIO7 = GPIO7
        GPIO_setDirectionMode(7, GPIO_DIR_MODE_OUT);    // GPIO7 = output
    
        GPIO_setPadConfig(8, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO8
        GPIO_writePin(8, 1);
        GPIO_setPinConfig(GPIO_8_GPIO8);                // GPIO8 = GPIO8
        GPIO_setDirectionMode(8, GPIO_DIR_MODE_OUT);    // GPIO8 = output
    
        GPIO_setPadConfig(9, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO9
        GPIO_writePin(9, 1);
        GPIO_setPinConfig(GPIO_9_GPIO9);                // GPIO9 = GPIO9
        GPIO_setDirectionMode(9, GPIO_DIR_MODE_OUT);    // GPIO9 = output
    
        //Input Pins
    
        GPIO_setPadConfig(10, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO10
        GPIO_setPinConfig(GPIO_10_GPIO10);               // GPIO10 = GPIO10
        GPIO_setDirectionMode(10, GPIO_DIR_MODE_IN);     // GPIO10 = input
    
        GPIO_setPadConfig(11, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO11
        GPIO_setPinConfig(GPIO_11_GPIO11);               // GPIO11 = GPIO11
        GPIO_setDirectionMode(11, GPIO_DIR_MODE_IN);     // GPIO11 = input
    
        GPIO_setPadConfig(14, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO14
        GPIO_setPinConfig(GPIO_14_GPIO14);               // GPIO14 = GPIO14
        GPIO_setDirectionMode(14, GPIO_DIR_MODE_IN);     // GPIO14 = input
    
        GPIO_setPadConfig(15, GPIO_PIN_TYPE_PULLUP);     // Enable pullup on GPIO15
        GPIO_setPinConfig(GPIO_15_GPIO15);               // GPIO15 = GPIO15
        GPIO_setDirectionMode(15, GPIO_DIR_MODE_IN);     // GPIO15 = input
    
        int op = 0, ip = 0;
        int input_pin[4] = {10, 11, 14, 15};
        int output_pin[4] = {6, 7, 8, 9};
    
        int keypad[4][4] = { {1, 2, 3, 10},
                           {4, 5, 6, 11},
                           {7, 8, 9, 12},
                           {13, 14, 15, 16} };
    
        while(true){
            bool flag = 0;
            for(op = 0; op <= 3 && !flag; op++){
                GPIO_writePin(output_pin[op], 0);
                for(ip = 0; ip <= 3 && !flag; ip++){
                    bool res = GPIO_readPin(input_pin[ip]);
                    if(!res) flag = 1;
                }
            }
            if(flag)
                break;
        }
        int key_pressed = keypad[op][ip];
    }
    

    However, whatever key I press, 'res' remains 1. Any suggestions?

  • Hi Adarsh,

    I think if you directly connect one or more of the outputs to one or more of the inputs you can take the keypad out of the debug and just focus on the SW / GPIO setup portion of the debug?  

    Alternately or in addition, you might try using a DMM or scope to confirm that the pin logic levels are as expected when the keys are pressed or not?  

  • GPIO_writePin(output_pin[op], 0);

    I think this should be '1', not 0.

    In any case you need to make sure that only one output is on at a time, i.e., you need to make sure all the outputs are 0 to start and that you turn off the previous one before you turn on the current one.

    Also, since you do not have any breaks, op and ip will simply contain the last value from the for loop.