ST AN3301 Application note

AN3301
Application note
S-Touch® STMPE812A: a hardware and software guide
Introduction
The STMPE812A is a 4-wire resistive touchscreen controller with an integrated 4-bit port expander. The touchscreen controller is designed to be fully autonomous, requiring only minimal CPU intervention for sampling, filtering and preprocessing operations.
The purpose of this document is to highlight the guidelines and information complementary to the datasheet that is necessary for a proper operation of the STMPE812A device in applications.
The first part of the document highlights information on the hardware. This includes external components/connectivity, power, PCB design and etc.
The second part of the document focuses on information in software in which programming reference codes are shown. This part is to be used in conjunction with the STMPE812A software library available in www.st.com.
December 2010 Doc ID 18161 Rev 1 1/35
www.st.com
Contents AN3301
Contents
1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Typical application circuit and external components . . . . . . . . . . . . . . . . . 5
1.2 Power supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.1 Power sequence (fail safe) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Power modes transition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Touchscreen tracks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4.1 Track resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.5 Noise prevention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6 Noise filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.7 PWM controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.8 ADC controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.9 GPIO output configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.9.1 Push-pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.9.2 Open drain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1 Touchscreen controller acquisition modes . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.1 Data acquisition by internal timer (ACQ_mode “00”) . . . . . . . . . . . . . . . 13
2.1.2 Data acquisition by ACQ command (ACQ_mode “01”) . . . . . . . . . . . . . 14
2.1.3 Data acquisition by host read control (ACQ_mode “10”) . . . . . . . . . . . . 14
2.2 Embedded data valid bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3 Pen down interrupt mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 TSC_DATA read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.5 Touchscreen controller sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.6 Programming guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.6.1 Touchscreen initialization and interrupt handling (pen down mode) . . . 19
2.6.2 Touchscreen initialization and interrupt handling (normal interrupt mode) 23
2.6.3 GPIO initialization and interrupt handling . . . . . . . . . . . . . . . . . . . . . . . 28
2.6.4 ADC initialization and interrupt handling . . . . . . . . . . . . . . . . . . . . . . . . 29
2.6.5 PWM initialization and interrupt handling . . . . . . . . . . . . . . . . . . . . . . . 32
3 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2/35 Doc ID 18161 Rev 1
AN3301 List of figures
List of figures
Figure 1. Typical application schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 2. Track resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 3. Noise prevention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 4. PWM LED driving configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. GPIO push-pull configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Figure 6. GPIO open drain configuration (output low) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 7. GPIO open drain configuration (output high) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 8. Data acquisition by internal timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 9. Data acquisition by ACQ command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 10. Data acquisition by host read command. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 11. TSC data register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Figure 12. Touchscreen controller sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Doc ID 18161 Rev 1 3/35
List of tables AN3301
List of tables
Table 1. Power modes vs. touchscreen/GPIO/Interrupt/PWM data . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 2. Example of sampling time calculation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Table 3. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4/35 Doc ID 18161 Rev 1
AN3301 Hardware

1 Hardware

1.1 Typical application circuit and external components

Figure 1. Typical application schematic

1.65V – 3.6V
1.65V – 3.6V
Y+
Y+
VCC
SDA
SDA
SCL
SCL
INT
INT
RESET
RESET
R1
R1
R2
R2
R3
R3
R4
R4
C1
C1
VCC
RESETN
RESETN
INT (P 2)
INT (P 2)
SCLK
SCLK
SDATA
SDATA
STMPE812A
X+
X+
Y-
Y-
X-
X-
(P1)ADC
(P1)ADC
(P0)ADDR
(P0)ADDR
GND
GND
R5
R5
4-wire
resistive
touchscreen
ADC input
ADC input
Note: 1 P0 pin is the I
2 P1 pin is configurable to GPIO/ADC/PWM (ADC Vin must be less than V
3 P2 pin is configurable to GPIO/INT
4 Assuming GPIO controlling RESET input is of open drain type
In a typical application, the following external components are required:
R1: 2.2k-10kΩ pull up resistor at RESET
R2: 2.2k-10kΩ pull up resistor at INT.
R3: 2.2k-10kΩ pull up resistor at SCLK
R4: 2.2k-10kΩ pull up resistor at SDATA
R5: 2.2k-10kΩ pull up resistor at ADDR
C1: 100 nF capacitor at V
2
C address bit upon power up or reset and is configurable to GPIO
)
CC
CC
Doc ID 18161 Rev 1 5/35
AM004192V1
Hardware AN3301

1.2 Power supply

The implementation and layout of the power connection’s section is fundamental for the correct operation of the STMPE812A touchscreen controller.
The STMPE812A device is equipped with a 12-bit ADC that is used during the touchscreen controller and auxiliary voltage measurement operations.
The analog blocks require a clean and stable supply voltage in order to operate in optimum performance. In the STMPE812, the analog blocks and the digital core are supplied by V The operating V with the increase in V
voltage range is 1.65 V to 3.6 V. Power consumption will be increased
CC
. The lowest power consumption is at VCC = 1.8 V.
CC
It is a good practice to connect a 0.1 pin.

1.2.1 Power sequence (fail safe)

All GPIOs and sense pins of STMPE812A are NOT fail safe. This means that it is necessary to make sure that the V inputs.
All other pins (SCL and SDA) are with fail safe structure. It is possible to turn on the pull-up supply before V
CC
.
supply to STMPE812A is first turned before driving the GPIO
CC
µF filtering capacitor as close as possible to the V
CC
CC
.
6/35 Doc ID 18161 Rev 1
AN3301 Hardware

1.3 Power modes transition

The following table highlights the states of touchscreen FIFO, GPIO, Interrupt and PWM during the various power modes:
Active mode
Hibernation mode
Reset
Table 1. Power modes vs. touchscreen/GPIO/Interrupt/PWM data
Description Active mode Hibernation mode
Touchscreen FIFO data Active Sustained Cleared
GPIO configuration, pin state and data
Interrupt configuration and data
PWM configuration and data
Active Sustained Cleared
Active Sustained Cleared
Active Sustained Cleared
Reset (HW, SW, POR
and General call)
Hibernation mode is entered automatically when ALL of the following listed activities are met:
Absent of I
PWM disabled
ADC disabled
Absent of GPIO input transition for 10 ms
Absent of touchsceen or pen down interrupt for 10 ms
2
C transaction with valid STMPE812A slave address for 10 ms
Doc ID 18161 Rev 1 7/35
Hardware AN3301

1.4 Touchscreen tracks

The touchscreen tracks (X+, X-, Y+, Y-) are sensitive lines. Noise may be captured by the touchscreen tracks if the line is too long and if placed nearby noisy lines, for example the digital data lines and the I2C/SPI lines.
Although there is no recommended standard for track sizes, tracks that are too long reduce the resolution of the touchscreen controller. As a matter of fact, long tracks introduce a voltage drop during the measurement cycle at the terminal of the touchscreen panel.

1.4.1 Track resistance

Any track has a certain amount of resistance, thus reducing the effective resolution of the touchscreen controller.
During the measurement, the current flows to the touchscreen panel through the tracks. If the resistance is too high, the voltage in the panel terminal is no longer at the same level as VIO and GND.
From Figure 2 it can be seen that, during the measurement cycle, the device bias the touchscreen panel with the VIO voltage. Due to the track resistance, the voltage at panel's terminals is:
Equation 1
Vx V
IO
R
R1 R2 Rx++()=
x
Hence, the effective resolution is reduced by the same factor as well. The track resistance may be reduced by designing the track as short as possible with a reasonable width.
Figure 2. Track resistance
Tr ack resistance, R1
VIO
To uch panel
Vx
Tr ack resistance, R2
GND
resistance, Rx
8/35 Doc ID 18161 Rev 1
AM004193V2
AN3301 Hardware
s

1.5 Noise prevention

Noise may be coupled to the tracks connecting the touchscreen and this should be prevented as much as possible.
Two practices may be applied:
1. Prevent the tracks overlap with other noisy signal tracks, such as I2C/SPI lines and digital data lines. If the overlap is not avoidable, GND lines separation between touchscreen lines and noisy lines is recommended (in more than 2 layers PCB).
2. Put GND shielding at each side of touchscreen tracks routing.

Figure 3. Noise prevention

TSC
TSC tracks
Top Layer

1.6 Noise filtering

A filtering capacitor can be placed on the touchscreen tracks to further suppress the noise. In this case, the best location for the filtering capacitor is as near as possible to the STMPE812A sense pins (X+, X-, Y+, Y-).
The values recommended for the filtering capacitor are:
1. 1-2 nF for an LCD less than 6 inches
2. 5-10 nF for an LCD bigger than 6 inches
Noisy tracks
Bottom Layer
GNDGND
GND
Oth er
Noisy lin e
AM004194V2
The Settling time and Touch detect delay registers must be set correctly to adapt to the filtering capacitor, otherwise the touchscreen controller may not work properly. Additional information is found in the STMPE812A datasheet.
Doc ID 18161 Rev 1 9/35
Hardware AN3301

1.7 PWM controller

The STMPE812A is integrated with push-pull type of GPIO/PWM outputs. At VCC of 3.3 V, the outputs are able to provide 8mA of sourcing (out of device) and 12mA of sinking (into device) current capability. As such, STMPE812A is able to support LED driving in both sourcing and sinking configuration.
Note: the PWM timing and duty cycle settings in datasheet are based on a LED sourcing configuration. When used in sinking configuration, the inversion must be executed accordingly.

Figure 4. PWM LED driving configurations

C u rrent s o urcing
configu ra tion (8 mA)
S TMPE8 12A
S TMPE8 12A
PWM(A1)
PWM(A1)
C u rrent s inking
configu ra tion (12mA)
S TMPE8 12A
S TMPE8 12A
PWM(A1)
PWM(A1)
VCC
VCC
AM004194V1
10/35 Doc ID 18161 Rev 1
AN3301 Hardware

1.8 ADC controller

The STMPE812A is equipped with a 12-bit analog-to-digital converter (ADC). Besides the use for ADC conversion during touchsceen controller operation, it is possible to be used as general purpose ADC conversion for up to maximum two external auxiliary analog signals feed through pins B2 and C2.
The touchscreen controller has the priority for the ADC conversion. Selection of conversion of the two external auxiliary analog signals is programmed through Bit[0] of the ADC control register (0x20).
Whenever the touchscreen data acquisition is initiated, the ADC conversion is triggered automatically without needs to program the ADC control register. Writing ‘1’ to Bit[6] of ADC Control register to initialize conversion for Touchscreen data is redundant and will result in higher current consumption if ADC is in continuous capture mode.
The STMPE812A is integrated with an internal charge pump in order to ensure ADC performance in low V ADC control register in the device initialization phase whenever the V
Important: If V
CC
disabled to prevent possible reliability issue or permanent damage of the device.
condition. The internal charge pump should be turned on through
CC
is less than 2.5 V.
CC
is higher than 2.5 V, it is important to ensure the charge pump is

1.9 GPIO output configurations

The STMPE812A provides push-pull type of GPIO output. If open drain GPIO outputs are required, it is configurable, with a tweak to the software programming routine. See Figure 5,
Figure 6 and Figure 7.

1.9.1 Push-pull

Set the GPIO to output state through PORT_FUNTION (0x04) register. Input path will be disabled. Output path will be enabled in push-pull configuration.
Figure 5. GPIO push-pull configuration
OUTPUT
INPUT
STMPE812A
disabled
enabled
GPIOxGPIOx
AM004195V1
Doc ID 18161 Rev 1 11/35
Loading...
+ 24 hidden pages