{"id":2093,"date":"2023-11-12T14:22:41","date_gmt":"2023-11-12T14:22:41","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2093"},"modified":"2023-11-12T14:22:45","modified_gmt":"2023-11-12T14:22:45","slug":"working-with-stm32f429-discovery-display-part-3-2-stmpe811-touch-controller-display-touch-location","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2093","title":{"rendered":"Working with STM32F429-discovery Display Part 3.2: STMPE811 Touch Controller, Display Touch location"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"672\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1.jpeg\" alt=\"\" class=\"wp-image-2095\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1-300x197.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1-768x504.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1-750x492.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1-400x263.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/F9093660-01-1-250x164.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=2085\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2085\" target=\"_blank\">here<\/a>), we took a look at the touch controller and its features, initialize the I2C peripheral and external interrupt. In second part of the touch controller on STM32F429 discovery, we shall initialize the controller and display the results on the display itself.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Developing the header file.<\/li><li>Developing the source file.<\/li><li>Main.c code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Developing the header file:<\/h2>\n\n\n\n<p>We start off by creating new header file with name of STMPE811.h.<\/p>\n\n\n\n<p>Within the header file, include the header guard as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef STMPE811_H_\n#define STMPE811_H_\n\n\n\n#endif \/* STMPE811_H_ *\/<\/pre><\/div>\n\n\n\n<p>Within the header guard, include the standard integer library as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stdint.h&quot;<\/pre><\/div>\n\n\n\n<p>Define the address of the STMPE811 which is mentioned in the schematic as 0x41:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define deviceAddress 0x41<\/pre><\/div>\n\n\n\n<p>Declare enum to handle the touch \/ no touch events:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">typedef enum TouchDetect\n{\n\ttouched =1,\n\tno_touch=0\n\n}TouchDetect_t;<\/pre><\/div>\n\n\n\n<p>Define the required registers to initialize and read the touch screen values:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define STMPE811_REG_SYS_CTRL2 \t\t\t0x04 \/*Clock control*\/\n#define STMPE811_REG_SYS_CTRL1 \t\t\t0x03 \/*Reset control*\/\n#define STMPE811_REG_IO_AF              0x17 \/*Alternate function register*\/\n#define STMPE811_REG_ADC_CTRL1          0x20 \/*ADC control*\/\n#define STMPE811_REG_ADC_CTRL2          0x21 \/*ADC control*\/\n#define STMPE811_REG_TSC_CFG            0x41 \/*Touch Configuration*\/\n#define STMPE811_REG_FIFO_TH            0x4A \/*FIFO threshold*\/\n#define STMPE811_REG_FIFO_STA           0x4B \/*FIFO status*\/\n#define STMPE811_REG_TSC_FRACT_XYZ      0x56 \/*Touchscreen controller FRACTION_Z*\/\n#define STMPE811_REG_TSC_I_DRIVE        0x58 \/*Touchscreen controller drive*\/\n#define STMPE811_REG_TSC_CTRL           0x40 \/*touchscreen controller control register*\/\n#define STMPE811_REG_INT_CTRL\t\t\t0x09 \/*Interrupt control register*\/\n#define STMPE811_REG_INT_EN\t\t\t\t0x0A \/*Interrupt enable register*\/\n#define STMPE811_REG_INT_STA            0x0B \/*Interrupt status register*\/\n#define STMPE811_REG_TSC_DATA_INC       0x57 \/*Touchscreen controller DATA Incremental*\/\n#define STMPE811_REG_TSC_DATA_NON_INC   0xD7 \/*Touchscreen controller DATA Non-Incremental*\/\n#define STMPE811_REG_FIFO_SIZE          0x4C \/*FIFO size*\/<\/pre><\/div>\n\n\n\n<p>Necessary facilities:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/*IO expander facilities*\/\n#define STMPE811_ADC_FCT                0x01\n#define STMPE811_TS_FCT                 0x02\n#define STMPE811_IO_FCT                 0x04\n#define STMPE811_TEMPSENS_FCT           0x08\n<\/pre><\/div>\n\n\n\n<p>Touch screen pins:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\/* Touch Screen Pins definition *\/\n#define STMPE811_TOUCH_YD               STMPE811_PIN_7\n#define STMPE811_TOUCH_XD               STMPE811_PIN_6\n#define STMPE811_TOUCH_YU               STMPE811_PIN_5\n#define STMPE811_TOUCH_XU               STMPE811_PIN_4\n#define STMPE811_TOUCH_IO_ALL           0x00<\/pre><\/div>\n\n\n\n<p>Control status and enable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define STMPE811_TS_CTRL_ENABLE         0x01\n#define STMPE811_TS_CTRL_STATUS         0x80<\/pre><\/div>\n\n\n\n<p>Required functions:<\/p>\n\n\n\n<p>STMPE811 Initialization function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void STMPE811_Touch_Enable(void);<\/pre><\/div>\n\n\n\n<p>It takes no arguments and return nothing.<\/p>\n\n\n\n<p>Is touch:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">TouchDetect_t isToched(void);<\/pre><\/div>\n\n\n\n<p>It takes no argument and return the if the screen is touched or not.<\/p>\n\n\n\n<p>Get touch:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void getTouchValue(uint16_t *X, uint16_t *Y);<\/pre><\/div>\n\n\n\n<p>It takes two arguments:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Pointer to store the X values.<\/li><li>Pointer to store the Y values.<\/li><\/ul>\n\n\n\n<p>And returns nothing.<\/p>\n\n\n\n<p>Get ID function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint16_t getID(void);<\/pre><\/div>\n\n\n\n<p>It takes no argument and returns the ID value (Should always be 0x0811).<\/p>\n\n\n\n<p>Hence the entire header file:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef STMPE811_H_\n#define STMPE811_H_\n\n#include &quot;stdint.h&quot;\n\n#define deviceAddress 0x41\n\n\ntypedef enum TouchDetect\n{\n\ttouched =1,\n\tno_touch=0\n\n}TouchDetect_t;\n\n\n\n#define STMPE811_REG_SYS_CTRL2 \t\t\t0x04 \/*Clock control*\/\n#define STMPE811_REG_SYS_CTRL1 \t\t\t0x03 \/*Reset control*\/\n#define STMPE811_REG_IO_AF              0x17 \/*Alternate function register*\/\n#define STMPE811_REG_ADC_CTRL1          0x20 \/*ADC control*\/\n#define STMPE811_REG_ADC_CTRL2          0x21 \/*ADC control*\/\n#define STMPE811_REG_TSC_CFG            0x41 \/*Touch Configuration*\/\n#define STMPE811_REG_FIFO_TH            0x4A \/*FIFO threshold*\/\n#define STMPE811_REG_FIFO_STA           0x4B \/*FIFO status*\/\n#define STMPE811_REG_TSC_FRACT_XYZ      0x56 \/*Touchscreen controller FRACTION_Z*\/\n#define STMPE811_REG_TSC_I_DRIVE        0x58 \/*Touchscreen controller drive*\/\n#define STMPE811_REG_TSC_CTRL           0x40 \/*touchscreen controller control register*\/\n#define STMPE811_REG_INT_CTRL\t\t\t0x09 \/*Interrupt control register*\/\n#define STMPE811_REG_INT_EN\t\t\t\t0x0A \/*Interrupt enable register*\/\n#define STMPE811_REG_INT_STA            0x0B \/*Interrupt status register*\/\n#define STMPE811_REG_TSC_DATA_INC       0x57 \/*Touchscreen controller DATA Incremental*\/\n#define STMPE811_REG_TSC_DATA_NON_INC   0xD7 \/*Touchscreen controller DATA Non-Incremental*\/\n#define STMPE811_REG_FIFO_SIZE          0x4C \/*FIFO size*\/\n\n\/*IO expander facilities*\/\n#define STMPE811_ADC_FCT                0x01\n#define STMPE811_TS_FCT                 0x02\n#define STMPE811_IO_FCT                 0x04\n#define STMPE811_TEMPSENS_FCT           0x08\n\n\n\n\/* Touch Screen Pins definition *\/\n#define STMPE811_TOUCH_YD               STMPE811_PIN_7\n#define STMPE811_TOUCH_XD               STMPE811_PIN_6\n#define STMPE811_TOUCH_YU               STMPE811_PIN_5\n#define STMPE811_TOUCH_XU               STMPE811_PIN_4\n#define STMPE811_TOUCH_IO_ALL           0x00\n\n\/* IO Pins definition *\/\n#define STMPE811_PIN_0                  0x01\n#define STMPE811_PIN_1                  0x02\n#define STMPE811_PIN_2                  0x04\n#define STMPE811_PIN_3                  0x08\n#define STMPE811_PIN_4                  0x10\n#define STMPE811_PIN_5                  0x20\n#define STMPE811_PIN_6                  0x40\n#define STMPE811_PIN_7                  0x80\n#define STMPE811_PIN_ALL                0xFF\n\n#define STMPE811_TS_CTRL_ENABLE         0x01\n#define STMPE811_TS_CTRL_STATUS         0x80\n\n\n\nvoid STMPE811_Touch_Enable(void);\nTouchDetect_t isToched(void);\nvoid getTouchValue(uint16_t *X, uint16_t *Y);\nuint16_t getID(void);\n\n\n#endif \/* STMPE811_H_ *\/\n<\/pre><\/div>\n\n\n\n<p>Thats all for the header file.<\/p>\n\n\n\n<p>Next the source file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Developing the Source File:<\/h2>\n\n\n\n<p>Create new source file with name of STMPE811.c<\/p>\n\n\n\n<p>With the source file, include the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;i2c3.h&quot;\n#include &quot;STMPE811.h&quot;\n#include &quot;delay.h&quot;\n#include &quot;STM32F4xx.h&quot;<\/pre><\/div>\n\n\n\n<p>Now, we shall populate the function:<\/p>\n\n\n\n<p>We start with the initialization function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void STMPE811_Touch_Enable(void)<\/pre><\/div>\n\n\n\n<p>Within the function:<\/p>\n\n\n\n<p>Declare local variable to hold some temporary values:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint8_t mode;<\/pre><\/div>\n\n\n\n<p>The soft reset the controller as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Soft reset the controller.<\/li><li>Delay for 10ms to ensure the reset is done.<\/li><li>Get out of soft reset.<\/li><li>Delay for 2ms.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"450\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-1024x450.png\" alt=\"\" class=\"wp-image-2097\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-1024x450.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-300x132.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-768x338.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-1536x675.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-2048x900.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-1150x506.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-750x330.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-400x176.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.40.08\u202fPM-250x110.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Power Down the stmpe811 *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL1, 2);\n\n\t\/* Wait for a delay to ensure registers erasing *\/\n\tdelay(10);\n\n\t\/* Power On the Codec after the power off =&gt; all registers are reinitialized *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL1, 0);\n\n\t\/* Wait for a delay to ensure registers erasing *\/\n\tdelay(2);<\/pre><\/div>\n\n\n\n<p>Disable clock access to the GPIO by reading the Clock control register, set the GPIO clock to zero then write the new value:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"450\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-1024x450.png\" alt=\"\" class=\"wp-image-2098\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-1024x450.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-300x132.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-768x338.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-1536x675.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-2048x900.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-1150x506.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-750x330.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-400x176.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.42.35\u202fPM-250x110.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Disable clock access to GPIO*\/\n\t\n\ti2c3_readByte(deviceAddress, STMPE811_REG_SYS_CTRL2, &amp;mode);\n\n\tmode &amp;= ~(STMPE811_IO_FCT);\n\n\t\/* Write the new register value *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL2, mode);<\/pre><\/div>\n\n\n\n<p>Set the pins to be GPIO\/Touch as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"232\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-1024x232.png\" alt=\"\" class=\"wp-image-2099\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-1024x232.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-300x68.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-768x174.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-1536x349.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-2048x465.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-1150x261.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-750x170.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-400x91.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.45.27\u202fPM-250x57.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Select TSC pins in TSC alternate mode *\/\n\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_IO_AF, STMPE811_TOUCH_IO_ALL);<\/pre><\/div>\n\n\n\n<p>Turn on the touch:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tmode&amp;= ~(STMPE811_TS_FCT | STMPE811_ADC_FCT);\n\n\t\/* Write the new register value *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL2, mode);<\/pre><\/div>\n\n\n\n<p>Set the sample resolution and settling time:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"734\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-1024x734.png\" alt=\"\" class=\"wp-image-2100\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-1024x734.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-300x215.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-768x550.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-1536x1101.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-2048x1468.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-1150x824.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-750x538.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-400x287.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.49.14\u202fPM-250x179.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Select Sample Time, bit number and ADC Reference *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_ADC_CTRL1, 0x49);<\/pre><\/div>\n\n\n\n<p>Wait for 2ms:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Wait for 2 ms *\/\n\tdelay(2);<\/pre><\/div>\n\n\n\n<p>Set the  ADC clock to 3.25MHz<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Select the ADC clock speed: 3.25 MHz *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_ADC_CTRL2, 0x01);<\/pre><\/div>\n\n\n\n<p>Configure the touch screen with the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Touch average control: 4 samples.<\/li><li>Touch delay time: 500uS.<\/li><li>Panel Driver settling time: 500uS.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"442\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-1024x442.png\" alt=\"\" class=\"wp-image-2102\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-1024x442.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-300x129.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-768x331.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-1536x663.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-2048x884.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-1150x496.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-750x324.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-400x173.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.55.51\u202fPM-250x108.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"520\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-1024x520.png\" alt=\"\" class=\"wp-image-2103\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-1024x520.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-300x152.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-768x390.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-1536x780.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-2048x1040.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-1150x584.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-750x381.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-400x203.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.56.29\u202fPM-250x127.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Select 2 nF filter capacitor *\/\n\t\/* Configuration:\n\t- Touch average control    : 4 samples\n\t- Touch delay time         : 500 uS\n\t- Panel driver setting time: 500 uS\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_CFG, 0x9A);<\/pre><\/div>\n\n\n\n<p>Set threshold reading to be single reading:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"338\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-1024x338.png\" alt=\"\" class=\"wp-image-2104\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-1024x338.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-300x99.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-768x254.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-1536x507.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-2048x676.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-1150x380.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-750x248.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-400x132.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.57.57\u202fPM-250x83.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Configure the Touch FIFO threshold: single point reading *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_TH, 0x01);<\/pre><\/div>\n\n\n\n<p>Clear the FIFO and put the FIFO back in the operation mode:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"745\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-1024x745.png\" alt=\"\" class=\"wp-image-2105\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-1024x745.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-300x218.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-768x559.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-1536x1117.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-2048x1490.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-1150x837.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-750x546.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-400x291.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-4.59.37\u202fPM-250x182.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Clear the FIFO memory content. *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x01);\n\n\t\/* Put the FIFO back into operation mode  *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x00);<\/pre><\/div>\n\n\n\n<p>Set the range and accuracy of z measurement: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Fractional Range: 7<\/li><li>Whole part: 1<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"584\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-1024x584.png\" alt=\"\" class=\"wp-image-2106\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-1024x584.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-300x171.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-768x438.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-1536x876.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-2048x1168.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-1150x656.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-750x428.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-400x228.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.02.24\u202fPM-250x143.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Set the range and accuracy pf the pressure measurement (Z) :\n\t- Fractional part :7a\n\t- Whole part      :1\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_FRACT_XYZ, 0x07);<\/pre><\/div>\n\n\n\n<p>Set the current to be 50mA:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"415\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-1024x415.png\" alt=\"\" class=\"wp-image-2107\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-1024x415.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-300x121.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-768x311.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-1536x622.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-2048x829.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-1150x466.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-750x304.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-400x162.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.03.37\u202fPM-250x101.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Set the driving capability (limit) of the device for TSC pins: 50mA *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_I_DRIVE, 0x01);<\/pre><\/div>\n\n\n\n<p>Configure the touch controller with the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>No window tracking index.<\/li><li>XYZ acquisition mode.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"760\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-1024x760.png\" alt=\"\" class=\"wp-image-2108\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-1024x760.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-300x223.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-768x570.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-1536x1140.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-2048x1520.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-1150x854.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-750x557.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-400x297.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.05.54\u202fPM-250x186.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/* Touch screen control configuration (enable TSC):\n\t- No window tracking index\n\t- XYZ acquisition mode\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_CTRL, 0x01);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Clear any pending flag (if any):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"673\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-1024x673.png\" alt=\"\" class=\"wp-image-2109\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-1024x673.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-300x197.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-768x505.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-1536x1010.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-2048x1346.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-1150x756.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-750x493.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-400x263.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.07.58\u202fPM-250x164.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*  Clear all the status pending bits if any *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_INT_STA, 0xFF);<\/pre><\/div>\n\n\n\n<p>Delay by 5ms:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tdelay(5);<\/pre><\/div>\n\n\n\n<p>Hence the function as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void STMPE811_Touch_Enable(void)\n{\n\n\tuint8_t mode;\n\t\n\t\/* Power Down the stmpe811 *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL1, 2);\n\n\t\/* Wait for a delay to ensure registers erasing *\/\n\tdelay(10);\n\n\t\/* Power On the Codec after the power off =&gt; all registers are reinitialized *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL1, 0);\n\n\t\/* Wait for a delay to ensure registers erasing *\/\n\tdelay(2);\n\n\t\/*Disable clock access to GPIO*\/\n\t\n\ti2c3_readByte(deviceAddress, STMPE811_REG_SYS_CTRL2, &amp;mode);\n\n\tmode &amp;= ~(STMPE811_IO_FCT);\n\n\t\/* Write the new register value *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL2, mode);\n\n\n\t\/*Select TSC pins in TSC alternate mode *\/\n\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_IO_AF, STMPE811_TOUCH_IO_ALL);\n\n\n\tmode&amp;= ~(STMPE811_TS_FCT | STMPE811_ADC_FCT);\n\n\t\/* Write the new register value *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL2, mode);\n\n\n\n\t\/* Select Sample Time, bit number and ADC Reference *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_ADC_CTRL1, 0x49);\n\n\t\/* Wait for 2 ms *\/\n\tdelay(2);\n\n\t\/* Select the ADC clock speed: 3.25 MHz *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_ADC_CTRL2, 0x01);\n\n\n\n\t\/* Select 2 nF filter capacitor *\/\n\t\/* Configuration:\n\t- Touch average control    : 4 samples\n\t- Touch delay time         : 500 uS\n\t- Panel driver setting time: 500 uS\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_CFG, 0x9A);\n\n\t\/* Configure the Touch FIFO threshold: single point reading *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_TH, 0x01);\n\n\t\/* Clear the FIFO memory content. *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x01);\n\n\t\/* Put the FIFO back into operation mode  *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x00);\n\n\t\/* Set the range and accuracy pf the pressure measurement (Z) :\n\t- Fractional part :7a\n\t- Whole part      :1\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_FRACT_XYZ, 0x07);\n\n\t\/* Set the driving capability (limit) of the device for TSC pins: 50mA *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_I_DRIVE, 0x01);\n\n\t\/* Touch screen control configuration (enable TSC):\n\t- No window tracking index\n\t- XYZ acquisition mode\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_CTRL, 0x01);\n\n\t\/*  Clear all the status pending bits if any *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_INT_STA, 0xFF);\n\n\n\t\/*Delay for 5ms*\/\n\n\tdelay(5);\n\n}<\/pre><\/div>\n\n\n\n<p>In order to check if there is a touch or not:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Read Touch Control Register.<\/li><li>Check if touch is detected or not.<\/li><li>If yes, Check the fifo if there is any data and return touched state.<\/li><li>If no, clear the FIFO and put it back into operation and return no touch state.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">TouchDetect_t isToched(void)\n{\n\n\tuint8_t state=0;\n\tuint8_t value=0;\n\n\ti2c3_readByte(deviceAddress, STMPE811_REG_TSC_CTRL, &amp;value);\n\n\tvalue&amp;=STMPE811_TS_CTRL_STATUS;\n\n\tstate=(value&amp;STMPE811_TS_CTRL_STATUS)==0x80;\n\n\tif(value==STMPE811_TS_CTRL_STATUS)\n\t{\n\t\ti2c3_readByte(deviceAddress,STMPE811_REG_FIFO_SIZE, &amp;value);\n\t\tif(value&gt;0)\n\t\t{\n\t\t\treturn touched;\n\t\t}\n\t}\n\n\telse\n\t{\n\t\t\/* Clear the FIFO memory content. *\/\n\t\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x01);\n\n\t\t\/* Put the FIFO back into operation mode  *\/\n\t\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x00);\n\t}\n\n\n\n\treturn no_touch;\n}<\/pre><\/div>\n\n\n\n<p>To get the touch values:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Burst read 4 bytes from Touchscreen controller DATA in non-increment mode.<\/li><li>Calculate the position of XY.<\/li><li>Reset the FIFO.<\/li><li>Put FIFO back into operation mode.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"235\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-1024x235.png\" alt=\"\" class=\"wp-image-2110\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-1024x235.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-300x69.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-768x176.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-1536x353.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-2048x471.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-1150x264.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-750x172.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-400x92.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-12-at-5.14.22\u202fPM-250x57.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void getTouchValue(uint16_t *X, uint16_t *Y)\n{\n\tuint32_t uldataXYZ;\n\tuint8_t  dataXYZ[4];\n\tuint8_t mode;\n\n\tI2C3_ReadMultiByte(deviceAddress, STMPE811_REG_TSC_DATA_NON_INC, dataXYZ, 4) ;\n\n\t\/* Calculate positions values *\/\n\tuldataXYZ = (dataXYZ[0] &lt;&lt; 24)|(dataXYZ[1] &lt;&lt; 16)|(dataXYZ[2] &lt;&lt; 8)|(dataXYZ[3] &lt;&lt; 0);\n\t*X = (uldataXYZ &gt;&gt; 20) &amp; 0x00000FFF;\n\t*Y = (uldataXYZ &gt;&gt;  8) &amp; 0x00000FFF;\n\n\t\/* Reset FIFO *\/\n\tmode=0x01;\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, mode);\n\n\t\/* Enable the FIFO again *\/\n\tmode=0x00;\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, mode);\n\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>To get the ID, burst read of two bytes from register 0x00:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Address 0x00 contains the higher bits of the ID.<\/li><li>Address 0x01 contains the lower buts of the ID.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">uint16_t getID(void)\n{\n\tuint8_t data[2];\n\tI2C3_ReadMultiByte(deviceAddress, 0x00, data, 2);\n\tuint16_t data_re=data[0]&lt;&lt;8|data[1];\n\treturn (data_re);\n\n}<\/pre><\/div>\n\n\n\n<p>Hence, the source file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;i2c3.h&quot;\n#include &quot;STMPE811.h&quot;\n#include &quot;delay.h&quot;\n#include &quot;STM32F4xx.h&quot;\n\n\nvoid STMPE811_Touch_Enable(void)\n{\n\n\tuint8_t mode;\n\t\n\t\/* Power Down the stmpe811 *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL1, 2);\n\n\t\/* Wait for a delay to ensure registers erasing *\/\n\tdelay(10);\n\n\t\/* Power On the Codec after the power off =&gt; all registers are reinitialized *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL1, 0);\n\n\t\/* Wait for a delay to ensure registers erasing *\/\n\tdelay(2);\n\n\t\/*Disable clock access to GPIO*\/\n\t\n\ti2c3_readByte(deviceAddress, STMPE811_REG_SYS_CTRL2, &amp;mode);\n\n\tmode &amp;= ~(STMPE811_IO_FCT);\n\n\t\/* Write the new register value *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL2, mode);\n\n\n\t\/*Select TSC pins in TSC alternate mode *\/\n\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_IO_AF, STMPE811_TOUCH_IO_ALL);\n\n\n\tmode&amp;= ~(STMPE811_TS_FCT | STMPE811_ADC_FCT);\n\n\t\/* Write the new register value *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_SYS_CTRL2, mode);\n\n\n\n\t\/* Select Sample Time, bit number and ADC Reference *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_ADC_CTRL1, 0x49);\n\n\t\/* Wait for 2 ms *\/\n\tdelay(2);\n\n\t\/* Select the ADC clock speed: 3.25 MHz *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_ADC_CTRL2, 0x01);\n\n\n\n\t\/* Select 2 nF filter capacitor *\/\n\t\/* Configuration:\n\t- Touch average control    : 4 samples\n\t- Touch delay time         : 500 uS\n\t- Panel driver setting time: 500 uS\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_CFG, 0x9A);\n\n\t\/* Configure the Touch FIFO threshold: single point reading *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_TH, 0x01);\n\n\t\/* Clear the FIFO memory content. *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x01);\n\n\t\/* Put the FIFO back into operation mode  *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x00);\n\n\t\/* Set the range and accuracy pf the pressure measurement (Z) :\n\t- Fractional part :7a\n\t- Whole part      :1\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_FRACT_XYZ, 0x07);\n\n\t\/* Set the driving capability (limit) of the device for TSC pins: 50mA *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_I_DRIVE, 0x01);\n\n\t\/* Touch screen control configuration (enable TSC):\n\t- No window tracking index\n\t- XYZ acquisition mode\n\t*\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_TSC_CTRL, 0x01);\n\n\t\/*  Clear all the status pending bits if any *\/\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_INT_STA, 0xFF);\n\n\n\t\/*Delay for 5ms*\/\n\n\tdelay(5);\n\n}\n\n\n\nTouchDetect_t isToched(void)\n{\n\n\tuint8_t state=0;\n\tuint8_t value=0;\n\n\ti2c3_readByte(deviceAddress, STMPE811_REG_TSC_CTRL, &amp;value);\n\n\tvalue&amp;=STMPE811_TS_CTRL_STATUS;\n\n\tstate=(value&amp;STMPE811_TS_CTRL_STATUS)==0x80;\n\n\tif(value==STMPE811_TS_CTRL_STATUS)\n\t{\n\t\ti2c3_readByte(deviceAddress,STMPE811_REG_FIFO_SIZE, &amp;value);\n\t\tif(value&gt;0)\n\t\t{\n\t\t\treturn touched;\n\t\t}\n\t}\n\n\telse\n\t{\n\t\t\/* Clear the FIFO memory content. *\/\n\t\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x01);\n\n\t\t\/* Put the FIFO back into operation mode  *\/\n\t\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, 0x00);\n\t}\n\n\n\n\treturn no_touch;\n}\n\n\n\n\nvoid getTouchValue(uint16_t *X, uint16_t *Y)\n{\n\tuint32_t uldataXYZ;\n\tuint8_t  dataXYZ[4];\n\tuint8_t mode;\n\n\tI2C3_ReadMultiByte(deviceAddress, STMPE811_REG_TSC_DATA_NON_INC, dataXYZ, 4) ;\n\n\t\/* Calculate positions values *\/\n\tuldataXYZ = (dataXYZ[0] &lt;&lt; 24)|(dataXYZ[1] &lt;&lt; 16)|(dataXYZ[2] &lt;&lt; 8)|(dataXYZ[3] &lt;&lt; 0);\n\t*X = (uldataXYZ &gt;&gt; 20) &amp; 0x00000FFF;\n\t*Y = (uldataXYZ &gt;&gt;  8) &amp; 0x00000FFF;\n\n\t\/* Reset FIFO *\/\n\tmode=0x01;\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, mode);\n\n\t\/* Enable the FIFO again *\/\n\tmode=0x00;\n\tI2C3_WriteByte(deviceAddress, STMPE811_REG_FIFO_STA, mode);\n\n}\n\n\n\nuint16_t getID(void)\n{\n\tuint8_t data[2];\n\tI2C3_ReadMultiByte(deviceAddress, 0x00, data, 2);\n\tuint16_t data_re=data[0]&lt;&lt;8|data[1];\n\treturn (data_re);\n\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the source file.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Main.c Code:<\/h2>\n\n\n\n<p>In main.c:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;LCD_Pins.h&quot;\n#include &quot;ILI9341.h&quot;\n#include &quot;i2c3.h&quot;\n#include &quot;STMPE811.h&quot;\n#include &quot;exti.h&quot;\n#include &quot;stdio.h&quot;\n\nuint16_t TouchX,TouchY;\n\nchar lcd_data[50];\n\nint main(void)\n{\n\tdelay_init(180000000);\n\n\ti2c3_init();\n\tSTMPE811_Touch_Enable();\n\n\tLCD_Pin_Init();\n\tLCD_SPI_Init();\n\tILI9341_Init();\n\tILI9341_setRotation(1);\n\tILI9341_Fill(COLOR_WHITE);\n\n\n\twhile(1)\n\t{\n\n\n\t\tif (isToched()==touched)\n\t\t{\n\t\t\tgetTouchValue(&amp;TouchX,&amp;TouchY);\n\t\t\tsprintf(lcd_data,&quot;X-axis %d      &quot;,TouchX);\n\t\t\tILI9341_DrawString(1,1,lcd_data,COLOR_BLACK,COLOR_WHITE,2);\n\t\t\tsprintf(lcd_data,&quot;Y-axis %d      &quot;,TouchY);\n\t\t\tILI9341_DrawString(1,2,lcd_data,COLOR_BLACK,COLOR_WHITE,2);\n\n\n\n\t\t}\n\n\t}\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>You should get the following once you upload the code:<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Touch Controller in STM32F429 Discovery\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/OUVnmYqhkYM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look at the touch controller and its features, initialize the I2C peripheral and external interrupt. In second part of the touch controller on STM32F429 discovery, we shall initialize the controller and display the results on the display itself. In this guide, we shall cover the following: Developing [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,19,11,12],"tags":[],"class_list":["post-2093","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-lcd","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2093"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2093"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2093\/revisions"}],"predecessor-version":[{"id":2111,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2093\/revisions\/2111"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}