Basic touch screen routines up and running
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 the touchpoint. Depending on voltage drop, it is possible to calculate the coordinates. There is a touch screen controller that takes most of the hard work – it has an internal ADC that measures the voltage and sends a value to the microcontroller using one of the selected interfaces (I2C or SPI). There is a typical ADS7843 controller used in the board, 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 many 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: