Library 10- STMPE811 Touch screen driver for STM32F429 Discovery board

STM32F429 Discovery board has LCD with ILI9341 controller and resistive touch screen with STMPE811 controller from STMicroelectonics.

STM32F429 Discovery board with STMPE811 touch driverThe STMPE811 is a 4-wire resistive touch screen controller with a GPIO (general purpose input/output) port expander able to interface a microcontroller or a main digital ASIC via I2C or SPI serial interface. The STMPE811 offers great flexibility, as each I/O can be configured as input, output or specific functions. The touch screen controller is enhanced with a movement tracking algorithm to avoid excessive data, 128 x 32 bit buffer and a programmable active window feature.

We will communicate with STMPE811 via I2C at Fast Mode of 100kbit/s. On Discovery board, driver is connected to pins:

STMPE811 I2C pins
function pin I2Cx PInspack
SCL PA8 I2C3 1
SDA PC9 I2C3 1

STMPE811 support High speed I2C mode, so this give us clock frequency up to 400kb/s.

Library dependencies

To run STMPE811 Library, you need some other libraries:

  • TM I2C


First you have to initialize STMPE811. You can do this with

Then, make an instance of touch data structure:

and pass your touch screen orientation:

That is used to synchronize X and Y coordinates with ILI9341 LCD coordinates. Other possible configurations are:

Read XY coordinates

You can read coordinates with

First you have to read, if touch has been pressed. Do this with



 Project available on Github, download library below.

TM STM32F4 STMPE811 Library

STMPE811 Touch screen library for STM32F429 Discovery


Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • llogar

    Hi. Thanks for these great libraries and tutorials. I have compiled and ran this example just fine (on STM32F429 Discovery board). As I want to send the “key presses/touches” to the PC, I have added the code from your USB VCP example. However once I call the TM_USB_VCP_Init(), the touch screen stops working and the TM_STMPE811_ReadTouch() function call takes almost a second. The touch screen part alone works just fine, the USB VCP part alone works just fine too. Only if I want to use both of them, then the problems occur. Any help would be greatly appreciated.



    • Hi Luka.

      Can you show me your code? main.c. Send me to my address You can send me project and I will take a look.

  • Jo Van Montfort

    @majerletilen:disqus I have Systick_Handler already occupied by another routine. And I think TM_DELAY_TIM is not supported in my std_pher lib?

    • Tm delay tim is not std function. This is my function.
      It is internal function. You dont need it any time.

      If you have systick for other purpose, then enable delay with internal timer. How to do that look for my delay lib.

      You still make a Delayms(x) to delay for x ms. Just this function will use another counter.

      • Jo Van Montfort

        Yes, ‘tm’_…_….
        I added the complete delay lib in my project. But many things are undeclared. For instance TM_DELAY_INT_initTIM, …
        Can I find this in your timer lib?

        • It cannot be. When you call tm delay init, it will automatically set tiner for delay if you cobfigure lib like this. You dont need to manually call inittim.

          On my github you have example how to configure delay with user timer.

          Check for defines.h configuration in project.

          If function has_INT_ then it is meant for internal use in library. I dont make this functions visible for you.

          • Jo Van Montfort

            Ofcourse, configuration! Very much appreciated!

  • Pavel Teroschin

    Hello everybody. Please answer me on my question. I have STMPE610 via I2C. How to set interrupt priority to this one? Because I have Timer7 interruptd (UIE) and UART interrupts (RXNE, TXE), my little main function:

    while (1) {



    If I comment NVIC, My touch works a little bit and then everything stuck (Timer interrupts each second)
    //Timer7 Prescaler :1343; Preload = 62499; Actual Interrupt Time = 2 s
    void InitTimer7(){
    TIM7_CR1.CEN = 0;
    TIM7_PSC = 1343;
    TIM7_ARR = 62499;
    TIM7_DIER.UIE = 1;
    TIM7_CR1.CEN = 1;

    My UART conf
    void USART_init(void){
    USART2_CR1bits.RXNEIE = 1; // enable uart rx interrupt
    NVIC_IntEnable(IVT_INT_USART2); // enable interrupt vector

    But if I uncomment NVIC touch working but I dont know if this is correct. And therefore my question is how to set priority level of my touch ?

    Thanks in advance

    • As I see, you are using some other C, but OK.
      You can use preemption priority, where your touch interrupt will be executed immediately, even if you are currently inside timer interrupt. That’s why preemption interrupts are in use.

      To enable it, you have to set correct NVIC preemption group to more than 0.
      Then, when setting interrupt for your timer and touch, set lower number for preemption for device you need higher priority.

      1. Enable preemption priorities in NVIC
      2. Enable TIM7 interrupt, set preemption to 1 or 0
      3. Enable TP interrupt, set preemption to 0 or 1 (if TIM has 0, then TP should have 1 and vice versa)

      Interrupt with lower number has higher priority.

      That’s fast explanation. For more, you should take a look at Cortex-M4 reference manual in

  • seo


    I am Korean. so I can’t speak English well. Understand me.
    I have a question.
    I did touch touch a lcd. but no change in lcd.
    why this lcd not changed??
    if you have time please tell me reason.

  • fikri

    Hii I just want to make touchpad and work on pc. Is this a similar, if similar how can i do , I really try all of think , but ı didnt do that 🙁

    • You want control PC with this touch?

      • fikri

        Yes sir

        • Buy touch board with usb.

          • fikri

            I made touch board , I just connect to stm32 and try to use on Pc

          • Then read coordinates and send to computer. Then use program to receive data and do what you need to do.

            Or act like usb hid device as mouse and computer will do it itself.

          • fikri

            my question, “Read XY Cordinate” is useful for me ? I mean upside code useful for me ?

          • If you have STMPE811 controller on board, then yes, otherwise not!

          • fikri

            I have stm32f4 :/ do you have code for stm32f4 like that ?

          • Next time, think first before asking.. How can I know which custom board and driver you have?

          • fikri

            I am Sorry about that

  • Suraj Vanjeeswaran

    Hi will this library work with

    STM32F469I-Discovery microcontroller boards,if yes what modifications will have to be made ?
    Suraj V

  • 馮天懋

    Hello everybody

    I using the STM32F429 discovery board
    I download this tutorial and compile it have some error(almost appear in the other project demonstration )
    Could anybody help me for this problem
    the main.h is vacancy

    the error said as follows:
    In the tm_stm32f4_ili9341.c

    ..0-STM32F429_LIBRARIEStm_stm32f4_ili9341.c(96): error: #20: identifier “GPIO_PIN_13” is undefined
    ..0-STM32F429_LIBRARIEStm_stm32f4_ili9341.c(99): error: #20: identifier “GPIO_PIN_2” is undefined
    ..0-STM32F429_LIBRARIEStm_stm32f4_ili9341.c(102): error: #20: identifier “GPIO_PIN_12” is undefined

  • Sid

    Hi, I am working on STM32H7 Discovery board, trying to make Touch panel work and read coordinates using HAL Library. I can able to read ChipID number through executing I2C function when placed before main while loop. But, as and when I try to do similar using interrupt generated by LCD (Interrupt works perfectly fine), I get stuck to this I2C_WaitOnFlagUntilTimeout() loop and it gets stuck. Any idea, how can I able to make touch coordinates read using interrupt??

    • Sid

      “STM32H7 Nucleo Board”