Application note Using the STMPE801 as a keypad controller Introduction STMPE801 is an 8-bit general purpose port expander device in the STMicroelectronics Port Expander Logic family. Its eight GPIOs (General Purpose Input Output) are connected to the host system using a standard I2C connection. This application note explains how to control an 8*8 (64-key) matrix keypad using the 8 internal GPIOs of a base-band processor and the 8 GPIOs of the STMPE801 port expander. The simplified schematic is shown below. Schematic for using STMPE801 as a keypad controller RST Baseband SDAT STMPE801 BB_GPIO SCLK INT 801_GPIO 8*8 Keypad November 2006 Rev 1 1/6 www.st.com
Contents AN2421 Contents 1 Design objectives........................................... 3 2 Keypad scanning operation................................... 3 3 Pseudo-Code of the KPC software............................. 4 4 Performance............................................... 5 5 Enhancements.............................................. 5 6 Revision history............................................ 5 2/6
Design objectives 1 Design objectives The keyboard controller presented in this application note complies with the following design objectives: Implementation of an 8*8 keypad controller using 8 GPIOs from the Baseband and 8 GPIOs from the STMPE801 Requires no external interrupts Minimum traffic on the I 2 C bus Ability to support hot-key (wake-up from suspend) features 2 Keypad scanning operation The rows (X-n) are used as inputs and are pulled up to V CC using a weak pull-up resistor (47kOhm). The columns (Y-n) are used as outputs and are normally driven to V CC. An X-Y matrix keypad works in the following sequence: 1. Y-0 is driven to GND. 2. KPC Software scans X-0 to X-n. A "LOW" indicates that key Y-0, X-n is pressed. 3. Y-0 is driven to V CC. Scanning of column 1 completes. 4. Proceed to scanning of column Y+1. To minimize I2C traffic between the baseband and the STMPE801, the GPIOs in baseband (BB_GPIO) are used as inputs and the STMPE801 GPIOs (801_GPIO) are used as outputs. This enables KPC Software to operate without causing the STMPE801 to return interrupts. There is no reading operation from the STMPE801. 3/6
Pseudo-Code of the KPC software AN2421 3 Pseudo-Code of the KPC software DEFINITIONS BB_GPIO_n 801_GPIO_n Max_X = 8 Max_Y=8 INITIALIZATION Set BB_GPIO as inputs Set 801_GPIO as outputs Set 801_GPIO to output 0xFF VARIABLES XCount=0 YCount=0 LOOP YCount=0 LOOP <I2C Transaction> Set 801_GPIO to output ( ~(YCount<<0x01) ) READ BB_GPIO (and interpret keypress) YCount++ END LOOP IF YCount = Max_Y END LOOP WRITE_KEYS_TO_BUFFER 4/6
Performance 4 Performance To ensure minimum I 2 C activity, with 20-ms scanning interval (50 scan cycles per second) for an 8*8 keypad matrix, 400 I 2 C transactions are required per second with each transaction writing to one single register in STMPE801 for driving the respective column low and reading the BB_GPIO status. Assuming the transaction length is approximately 40-bit time (I 2 C address with ACK, Register address with ACK, Register Data with ACK, inter-transaction time), the total bittime per second is: Equation 1 400 40= 16.000 bit time The I 2 C interface has a bandwidth of 400Kbit/s, so the keypad controller uses only 16/400 (4%) of the I 2 C bandwidth. There are no interrupts from STMPE801 to the Baseband. 5 Enhancements It is possible to further enhance keypad controller performance using the following recommendations: In Idle state, Baseband goes into hibernation STMPE801 GPIOs are configured to inputs with interrupt enabled If any keys are pressed, the STMPE801 sends an interrupt to wake up the Baseband and start the scanning operation (STMPE801 reverts to operating as output). This enables the system to enter Deep Hibernation mode and still detect key presses. This enhancement also further reduces I 2 C bandwidth requirements as a scanning operation occurs if and only if a key is pressed. 6 Revision history Table 1. Document revision history Date Revision Changes 20-Nov-2006 1 Initial release. 5/6
Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. 2006 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 6/6