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.

RTOS/CC2640R2F: 4x4 matrix keypad interfacing using interrupt

Part Number: CC2640R2F


Tool/software: TI-RTOS

Hello,

I am trying to interface 4x4 keypad, I tried using while loop but with while loop bluetooth stops advertising, so can any one help me to solve this issue? one more thing can anyone tell me how to do with interrupt method?

I tried using interrupt method but in interrupt callback function there are two variables Handle and PinId,

what i want is when i call keypad function it should return pressed key,

but with this callback function i couldn't able to call this function without any identifiers like pinid so what to do?

regards,

jaydipsinh

  • I suppose you should use interrupt to triggle key pressed callback and use PIN_getInputValue to read which GPI pin is triggered.
  • Hello YKchen,

    I am doing same thing but here i have 16 keys and only 8gpio to determine which key is pressed,

    it's a 4x4 matrix keypad,

    I used callback function and PIN_getInputvalue to detect touch,

    but still not be able to detect,

    here for matrix keypad I have four column and four rows so to detect a touch on first key  first i need to set column1 as high and then i need to check whether a key is pressed or not by checking state of that pin,

    for first key column1 and row1 should be high at same time,

    here I would like to mention that column has to be ouput pin and rows as input pins.

    here with using interrupt I am not be able to detect which key is pressed and I am not getting any return values from the same.

    here for reference I am adding my keypad code.

    uint8_t KEYPAD_GetKey(void){
    
        //System_printf("\nInside keypad get key task \n");
       // System_flush();
        uint8_t i;
    while(1){
            PIN_setOutputValue(KeypadPinHandle,Board_column1, 1);
                   while(PIN_getInputValue(Board_column1)==1){
                       System_printf("\n Inside first while loop");
                       System_flush();
    
                       if(PIN_getInputValue(Board_row1) == 1){
    
                               if(count == 1){
                                   key = 1;
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row1) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                       }
    
    
                       else if(PIN_getInputValue(Board_row2) == 1){
                               count++;
                               if(count == 1){
                                   key = '2';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row2) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                       }
                       else if(PIN_getInputValue(Board_row3) == 1){
                               count++;
                               if(count == 1){
                                   key = '3';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row3) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                       }
                       else if(PIN_getInputValue(Board_row4) == 1){
                               count++;
                               if(count == 1){
                                   key = 'A';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row4) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                               PIN_setOutputValue(KeypadPinHandle,Board_column1,0);
                               //i++;
                       }
    
    
                   }
                   PIN_setOutputValue(KeypadPinHandle,Board_column2, 1);
                   while(PIN_getInputValue(Board_column2)==1){
                       System_printf("\n Inside second while loop");
                       System_flush();
    
                       if(PIN_getInputValue(Board_row1) == 1){
    
                               if(count == 1){
                                   key = '4';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row1) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                       }
    
    
                       else if(PIN_getInputValue(Board_row2) == 1){
                               count++;
                               if(count == 1){
                                   key = '5';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row2) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                       }
                       else if(PIN_getInputValue(Board_row3) == 1){
                               count++;
                               if(count == 1){
                                   key = '6';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row3) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                       }
                       else if(PIN_getInputValue(Board_row4) == 1){
                               count++;
                               if(count == 1){
                                   key = 'B';
                                   sec = '*';
                                   ssd1306_setTextSize(2);
                                   ssd1306_write(sec);
                                   ssd1306_display();
    
                                   System_printf("\n Key Pressed : %d \n", key);
                                   System_flush();
                                   return key;
                               }
                               else{
                                   while(1){
    
                                       if(PIN_getInputValue(Board_row4) == 0){
                                           count = 0;
                                           break;
                                       }
                                   }
                               }
                               PIN_setOutputValue(KeypadPinHandle,Board_column2,0);
                               //i++;
                       }
    
    
                   }
    
                   while(PIN_getInputValue(Board_column3)==1){
                       System_printf("\n Inside third while loop");
                       System_flush();
                          //PIN_setOutputValue(KeypadPinHandle,Board_column3, 1);
                          if(PIN_getInputValue(Board_row1) == 1){
    
                                  if(count == 1){
                                      key = '7';
                                      sec = '*';
                                      ssd1306_setTextSize(2);
                                      ssd1306_write(sec);
                                      ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row1) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                          }
    
    
                          else if(PIN_getInputValue(Board_row2) == 1){
                                  count++;
                                  if(count == 1){
                                      key = '8';
                                      sec = '*';
                                      ssd1306_setTextSize(2);
                                      ssd1306_write(sec);
                                      ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row2) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                          }
                          else if(PIN_getInputValue(Board_row3) == 1){
                                  count++;
                                  if(count == 1){
                                      key = '9';
                                      sec = '*';
                                      ssd1306_setTextSize(2);
                                      ssd1306_write(sec);
                                      ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row3) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                          }
                          else if(PIN_getInputValue(Board_row4) == 1){
                                  count++;
                                  if(count == 1){
                                      key = 'C';
                                      sec = '*';
                                      ssd1306_setTextSize(2);
                                      ssd1306_write(sec);
                                      ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row4) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                                  PIN_setOutputValue(KeypadPinHandle,Board_column3,0);
                                  //i++;
                          }
    
                      }
                   PIN_setOutputValue(KeypadPinHandle,Board_column4, 1);
                      while(PIN_getInputValue(Board_column4)==1){
                          System_printf("\n Inside fourth while loop");
                          System_flush();
    
                          if(PIN_getInputValue(Board_row1) == 1){
    
                                  if(count == 1){
                                      key = '*';
                                      //sec = '*';
                                      //ssd1306_setTextSize(2);
                                      //ssd1306_write(sec);
                                      //ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row1) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                          }
    
    
                          else if(PIN_getInputValue(Board_row2) == 1){
                                  count++;
                                  if(count == 1){
                                      key = '0';
                                      sec = '*';
                                      ssd1306_setTextSize(2);
                                      ssd1306_write(sec);
                                      ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row2) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                          }
                          else if(PIN_getInputValue(Board_row3) == 1){
                                  count++;
                                  if(count == 1){
                                      key = '#';
                                      //sec = '*';
                                      //ssd1306_setTextSize(2);
                                      //ssd1306_write(sec);
                                      //ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row3) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                          }
                          else if(PIN_getInputValue(Board_row4) == 1){
                                  count++;
                                  if(count == 1){
                                      key = 'D';
                                      sec = '*';
                                      ssd1306_setTextSize(2);
                                      ssd1306_write(sec);
                                      ssd1306_display();
    
                                      System_printf("\n Key Pressed : %d \n", key);
                                      System_flush();
                                      return key;
                                  }
                                  else{
                                      while(1){
    
                                          if(PIN_getInputValue(Board_row4) == 0){
                                              count = 0;
                                              break;
                                          }
                                      }
                                  }
                                  PIN_setOutputValue(KeypadPinHandle,Board_column4,0);
                                  //i=0;;
                          }
    
                      }
                   if((PIN_getInputValue(Board_row1)==0) || (PIN_getInputValue(Board_row2)==0) || (PIN_getInputValue(Board_row3)==0) || (PIN_getInputValue(Board_row4)==0) ){
                       return Default;
                   }
                   else{
                       return key;
                   }
    }
    }
    

    this is keypad function which will generate interrupt and last one is call back function for the same.

                /* Setup callback for button pins */
                if (PIN_registerIntCb(KeypadPinHandle, &KEYPAD_GetKey) != 0) {
                     //Error registering button callback function
                    while(1);
                }

    Here function is not giving any interrupt.

  • Without the same HW as yours, it’s not possible to help you further. I suggest you to trace and debug if KEYPAD_GetKey is triggered when you press any of 4x4 key first.
  • Hello,
    I've figured out what was problem, it was interrupt which was causing problem,
    Instead of pin interrupt I've used GPIO interrupt and it worked for me,
    thanks.
    regards,
    jaydipsinh