Skip to main content
adnen_speder
Associate II
April 5, 2012
Question

keypad 4*4 with STM32* GPIOA

  • April 5, 2012
  • 11 replies
  • 2733 views
Posted on April 05, 2012 at 13:03

salut, 

svp jr veux interfacer une clavier 4*4 avec un stm32 par les GPIO.... comment!!

svp !!! 

NB : je met les 4 premier pins en 1 

   GPIO_SetBits(GPIOA,GPIO_Pin_0); 

          GPIO_SetBits(GPIOA,GPIO_Pin_1);

          GPIO_SetBits(GPIOA,GPIO_Pin_2);

          GPIO_SetBits(GPIOA,GPIO_Pin_3);

et j'esaye de faire le test sur les autres 4 pins !!!

#4x4-keypad
    This topic has been closed for replies.

    11 replies

    emalund
    Associate III
    April 5, 2012
    Posted on April 05, 2012 at 15:36

    hvis jeg forstod hvad du mente, kunne jeg sikkert hjelpe.

    Erik

    John F.
    Associate III
    April 7, 2012
    Posted on April 07, 2012 at 13:45

    Erik wrote, ''

    If I

    understood

    what

    you meant

    , I could

    certainly help

    .

    '' Google is your friend. Have a look at http://extremeelectronics.co.in/avr-tutorials/4x3-matrix-keypad-interface-avr-tutorial/ or google ''4 x 4 keypad interface''.

    Erik a écrit

    ,

    «

    Si j'ai bien compris

    ce que vous entendez

    ,

    je pourrais certainement

    vous aider.

    ''

    Google est votre ami

    .

    Jetez un oeil à

    http://extremeelectronics.co.in/avr-tutorials/4x3-matrix-keypad-interface-avr-tutorial/

    ou

    google

    ''4

    x interface

    clavier à 4

    ''

    .

    Tesla DeLorean
    Guru
    April 7, 2012
    Posted on April 07, 2012 at 14:17

    Perhaps you can provide more details about how you have this wired up, most simple implementations use 8 pins, 4 outputs, 4 inputs.

    For the output, one might typically use Open Collector/Drain mode and cycle/scan the ouputs to zero one at a time, while reading back the 4 inputs to divine which keys are depressed.

    ie

    1110

    1101

    1011

    0111

    https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Programming keypad 4x4 using encoder 16 key on STM32VL&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=77

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    adnen_speder
    Associate II
    April 7, 2012
    Posted on April 07, 2012 at 16:24 thank you clive .... je fais le test sur les inputs et les outputs mais seul le premeir ligne fonctionne et les autres lignes fonctionne comme le premier !!!! look at this ex: /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

    if ((GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)&&(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4))))
    {
    GPIO_SetBits(GPIOC,GPIO_Pin_8);
    Delay(0X1AAAA);
    }
    if ((GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)&&(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4))))
    {
    GPIO_SetBits(GPIOC,GPIO_Pin_9);
    Delay(0X1AAAA);
    }
    if ((GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2)&&(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4))))
    {
    GPIO_ResetBits(GPIOC,GPIO_Pin_8);
    Delay(0X1AAAA);
    }
    if ((GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_3)&&(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4))))
    {
    GPIO_ResetBits(GPIOC,GPIO_Pin_9);
    Delay(0X1AAAA);
    }

    and i doo this for all line ... but !! :'(
    Tesla DeLorean
    Guru
    April 8, 2012
    Posted on April 08, 2012 at 14:13

    Please also refer to diagram in ATMEL document in previously cited thread, or provide diagram of you own keypad connectivity.

    PA0..3 Outputs (Open Drain)
    PA4..7 Inputs (100K Pull-Ups)
    // Set outputs High (Open Drain GPIOs, ie undriven in high state)
    GPIO_SetBits(GPIOA,GPIO_Pin_0); 
    GPIO_SetBits(GPIOA,GPIO_Pin_1);
    GPIO_SetBits(GPIOA,GPIO_Pin_2);
    GPIO_SetBits(GPIOA,GPIO_Pin_3);
    ...
    // Bring each output scan line low, wait briefly, then read the LOW input states
    // to identify buttons depressed.
    GPIO_ResetBits(GPIOA,GPIO_Pin_0); // Drive LOW
    Delay(100);
    if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == RESET) // LOW indicates pressed/closed
    GPIO_SetBits(GPIOC,GPIO_Pin_8);
    if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == RESET)
    GPIO_SetBits(GPIOC,GPIO_Pin_9);
    if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == RESET)
    GPIO_ResetBits(GPIOC,GPIO_Pin_8);
    if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_7) == RESET)
    GPIO_ResetBits(GPIOC,GPIO_Pin_9);
    GPIO_SetBits(GPIOA,GPIO_Pin_0); // Release HIGH
    // Repeat for PA.1 .. PA.3

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    emalund
    Associate III
    April 9, 2012
    Posted on April 09, 2012 at 15:02

    // Set outputs High (Open Drain GPIOs, ie undriven in high state)

    having no (at leastvery limited) understanding of thefrench entries in this

    english language forum Ido not know if this is already mentioned. The above ''

    undriven in high state

    '' is not totally true. The outputs MUST bepulled highby (external) resistors for this to work. I recall two previous incidents (in other fora) where this was 'forgotten'. 'external' in paramthesis since the internal pullup probably is too weak for any significant cable length.

    Erik

    Tesla DeLorean
    Guru
    April 9, 2012
    Posted on April 09, 2012 at 16:11

    And thus the indirect reference to a specific document with a diagram, and specific comment that PA4..7 have 100K pull-ups. This while weak, should be quite adequate, absent some capacitance to slow the rise time. And I'm not talking about the wildly variable poly-silicon structures in the gate cell, but rather the 100K external resistance diagrammed. I would have pasted the ASCII art version, but the formatting was totally broken by Adobe and the clip-board.

    I did make a specific request for circuit details, and in there absence I defined my own conditions.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    adnen_speder
    Associate II
    April 11, 2012
    Posted on April 11, 2012 at 11:22

    Thank You Clive ...

    Work correctly 
    joerg23
    Associate
    June 12, 2013
    Posted on June 12, 2013 at 12:15

    He,

    is it possible that You share complete code for Keypad please.

    regards

    Joerg

    emalund
    Associate III
    June 12, 2013
    Posted on June 12, 2013 at 16:18

    And thus the indirect reference to a specific document with a diagram, and specific comment that PA4..7 have 100K pull-ups.

    Seems a bit high to me. Keypads are usually a bit distant from the chip, so, let's assume 100pF stray capacitance giving a risetime of

    100p * 100k  ~ 10uS which, with fast code can be problematic.