Basic touch screen routines up and running

STm32 touch screen

STM32103ZET6 prototyping board comes with LCD having touch screen capability. It is a great way to interact with the device. Practically speaking Touch screen is a resistive film that can be accessed as a regular potentiometer which value depends on touch point. Depending on voltage drop it is possible to calculate the coordinates. There is a touch screen controller which takes most of the hard work – it has internal ADC that measures the voltage and sends a value to the microcontroller using one of the selected interfaces (I2C or SPI). In the board, there is a common ADS7843 controller used, which talks to the microcontroller using SPI. After playing around, I’ve put a messy code that reads touch screen coordinates. It is a glued code from various sources, so it is only to fix some results. Currently, the code reads a bunch of values, then averages to get rid of most garbage and then calculates screen matching coordinates. This is the trickiest part to do. You can do this empirically by reading min and max ADC values for each axis and then calculate coordinates using formulas:

Continue reading