AnsweredAssumed Answered

keypad 3x4 rs 130404

Question asked by Zuzzuz on Mar 2, 2013
Latest reply on Mar 3, 2013 by Clive One
Hi, i try to use a keypad with my stm32vldiscovery but it doesn't work can u help me?
i connect first 4 pin to stm32vldiscovery in PA0-PA1-PA2-PA3 in output open drain, and last 3 pin to PA4-PA5-PA6 as analog input.
i have this connection
Keypad - PA4 - R100k - Ground
Keypad - PA5 - R100k - Ground
Keypad - PA6 - R100k - Ground


This is my code

#include "stm32f10x.h"
#include "STM32vldiscovery.h"
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void Delay(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/
  
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
         
  /* System clocks configuration ---------------------------------------------*/
  RCC_Configuration();
  
  /* GPIO configuration ------------------------------------------------------*/
  GPIO_Configuration();
  
  
  while (1)
  {
    
   
   GPIO_ResetBits(GPIOA,GPIO_Pin_0); 
   GPIO_ResetBits(GPIOA,GPIO_Pin_1);
   GPIO_ResetBits(GPIOA,GPIO_Pin_2);
   GPIO_ResetBits(GPIOA,GPIO_Pin_3);
   
   
   GPIO_SetBits(GPIOA,GPIO_Pin_0); 
   
            Delay(100);
  
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == SET)
          STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == SET)
           STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == SET)
            STM32vldiscovery_LEDToggle(LED3);
  
   
   GPIO_ResetBits(GPIOA,GPIO_Pin_0);
      GPIO_SetBits(GPIOA,GPIO_Pin_1);
            Delay(100);
   
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == SET)
          STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == SET)
           STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == SET)
           STM32vldiscovery_LEDToggle(LED3);
  
   
   GPIO_ResetBits(GPIOA,GPIO_Pin_1);
      GPIO_SetBits(GPIOA,GPIO_Pin_2);
            Delay(100);
   
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == SET)
           STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == SET)
            STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == SET)
            STM32vldiscovery_LEDToggle(LED3);
  
   
   GPIO_ResetBits(GPIOA,GPIO_Pin_2);
      GPIO_SetBits(GPIOA,GPIO_Pin_3);
            Delay(100);
   
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_4) == SET)
            STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_5) == SET)
            STM32vldiscovery_LEDToggle(LED3);
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_6) == SET)
            STM32vldiscovery_LEDToggle(LED3);
  
   
   GPIO_ResetBits(GPIOA,GPIO_Pin_3);
  }
}
  
/**
  * @brief  Configures the different system clocks.
  * @param  None
  * @retval None
  */
void RCC_Configuration(void)
{
  
  /* Enable ADC1 and GPIOC clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
}
  
/**
  * @brief  Configures the different GPIO ports.
  * @param  None
  * @retval None
  */
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO1_InitStructure;
  GPIO1_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
  GPIO1_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  GPIO_Init(GPIOA, &GPIO1_InitStructure);
    
    GPIO_InitTypeDef GPIO2_InitStructure;
  GPIO2_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
  GPIO2_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO2_InitStructure);
}
void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}
#ifdef  USE_FULL_ASSERT
  
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  
  /* Infinite loop */
  while (1)
  {
  }
}
  
#endif

Outcomes