cancel
Showing results for 
Search instead for 
Did you mean: 

keypad 3x4 rs 130404

joesoftware
Associate II
Posted on March 02, 2013 at 23:19

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 

3 REPLIES 3
Posted on March 03, 2013 at 01:36

So how in this scenario do you see an OD output attaining a high state?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
joesoftware
Associate II
Posted on March 03, 2013 at 11:04

true, something is bad in my connection.

How to fix it?

can I  change ground in 3.3V? or change output OD in output PP.

What is a better solution?

Sorry for my mistake but this is my first project with keypad.

Posted on March 03, 2013 at 11:56

Don't be sorry, I was just skimming the post and threw out the internal inconsistency in the logic.

The problem with using PP would be the potential to short High & Low with certain key press combinations.

A better solution would be to use pull-ups, and reverse the logic so you only drove one pin low, and then decoded low states as key presses.

If you are pin constrained, and have an ADC input to spare you could use resistor combinations to build a divider chain on a single analogue pin.

http://www.duinomite.com/duinomite-4x3-keypad-on-1-analog-pin/

although I could see doing this using purely resistors by measuring the voltage at the base of a 1K pull-up to 3V, and the resistor matrix attached to the keypad representing the to-ground leg of the divider.

The part# was a bit cryptic, but it's an RS Components (UK) catalogue part.

http://documents.rs-components.com/techlib://itc_doclist_GB.htm?stockno=0130404

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..