30. Touch sensing controller (TSC)

30.1 TSC introduction

The touch sensing controller provides a simple solution for adding capacitive sensing functionality to any application. Capacitive sensing technology is able to detect finger presence near an electrode that is protected from direct touch by a dielectric (for example glass, plastic). The capacitive variation introduced by the finger (or any conductive object) is measured using a proven implementation based on a surface charge transfer acquisition principle.

The touch sensing controller is fully supported by the STMTouch touch sensing firmware library, which is free to use and allows touch sensing functionality to be implemented reliably in the end application.

30.2 TSC main features

The touch sensing controller has the following main features:

Note: The number of capacitive sensing channels is dependent on the size of the packages and subject to I/O availability.

30.3 TSC implementation

Table 278. TSC implementation

TSC featuresSTM32U356/366STM32U375/385STM32U3B5/3C5
Number of analog I/O groups778
Number of channels212124
Comparator usage (1)X (2)-X (2)

1. See Section 30.5.1: Comparator usage overview .

2. X = supported.

30.4 TSC functional description

30.4.1 TSC block diagram

The block diagram of the touch sensing controller is shown in Figure 296 .

Figure 296. TSC block diagram

Figure 296. TSC block diagram. The diagram shows the internal architecture of the TSC. An input f_HCLK enters a 'Clock prescalers' block. The output of this block connects to a 'Pulse generator' and a 'Spread spectrum' block. The 'Pulse generator' and 'Spread spectrum' block both connect to a large 'I/O control logic' block. The 'I/O control logic' block has multiple output pins labeled SYNC, G1_IO1, G1_IO2, G1_IO3, G1_IO4, G2_IO1, G2_IO2, G2_IO3, G2_IO4, ..., Gx_IO1, Gx_IO2, Gx_IO3, Gx_IO4. A 'Group counters' block is also connected to the 'I/O control logic' block. The 'Group counters' block contains sub-blocks TSC_IOG1CR, TSC_IOG2CR, ..., TSC_IOGxCR.
graph LR
    fHCLK[f_HCLK] --> CP[Clock prescalers]
    CP --> PG[Pulse generator]
    CP --> SS[Spread spectrum]
    PG --> IOL[I/O control logic]
    SS --> IOL
    IOL --> GC[Group counters]
    GC --> TSC_IOG1CR[TSC_IOG1CR]
    GC --> TSC_IOG2CR[TSC_IOG2CR]
    GC --> TSC_IOGxCR[TSC_IOGxCR]
    IOL --> SYNC[SYNC]
    IOL --> G1_IO1[G1_IO1]
    IOL --> G1_IO2[G1_IO2]
    IOL --> G1_IO3[G1_IO3]
    IOL --> G1_IO4[G1_IO4]
    IOL --> G2_IO1[G2_IO1]
    IOL --> G2_IO2[G2_IO2]
    IOL --> G2_IO3[G2_IO3]
    IOL --> G2_IO4[G2_IO4]
    IOL --> Gx_IO1[Gx_IO1]
    IOL --> Gx_IO2[Gx_IO2]
    IOL --> Gx_IO3[Gx_IO3]
    IOL --> Gx_IO4[Gx_IO4]
  
Figure 296. TSC block diagram. The diagram shows the internal architecture of the TSC. An input f_HCLK enters a 'Clock prescalers' block. The output of this block connects to a 'Pulse generator' and a 'Spread spectrum' block. The 'Pulse generator' and 'Spread spectrum' block both connect to a large 'I/O control logic' block. The 'I/O control logic' block has multiple output pins labeled SYNC, G1_IO1, G1_IO2, G1_IO3, G1_IO4, G2_IO1, G2_IO2, G2_IO3, G2_IO4, ..., Gx_IO1, Gx_IO2, Gx_IO3, Gx_IO4. A 'Group counters' block is also connected to the 'I/O control logic' block. The 'Group counters' block contains sub-blocks TSC_IOG1CR, TSC_IOG2CR, ..., TSC_IOGxCR.

30.4.2 Surface charge transfer acquisition overview

The surface charge transfer acquisition is a proven, robust and efficient way to measure a capacitance. It uses a minimum number of external components to operate with a single ended electrode type. This acquisition is designed around an analog I/O group composed of up to four GPIOs (see Figure 297 ). Several analog I/O groups are available to allow the acquisition of several capacitive sensing channels simultaneously and to support a larger number of capacitive sensing channels. Within a same analog I/O group, the acquisition of the capacitive sensing channels is sequential.

One of the GPIOs is dedicated to the sampling capacitor \( C_S \) . Only one sampling capacitor I/O per analog I/O group must be enabled at a time.

The remaining GPIOs are dedicated to the electrodes and are commonly called channels. For some specific needs (such as proximity detection), it is possible to simultaneously enable more than one channel per analog I/O group.

Figure 297. Surface charge transfer analog I/O group structure

Figure 297: Surface charge transfer analog I/O group structure. The diagram illustrates an 'Analog I/O group' containing four GPIO interfaces: Gx_IO1, Gx_IO2, Gx_IO3, and Gx_IO4. Gx_IO1 is connected to Electrode 1 via resistor Rs1; Electrode 1 has a parasitic capacitance Cx1 and a sensor voltage V_SENSOR. Gx_IO2 is connected to the sampling capacitor Cs with voltage Vcs. Gx_IO3 is connected to Electrode 2 via Rs2, with capacitance Cx2 and voltage V_SENSOR. Gx_IO4 is connected to Electrode 3 via Rs3, with capacitance Cx3 and voltage V_SENSOR. Each GPIO block inside the group shows internal circuitry including two MOSFET switches (one to a high rail, one to a low rail) and a buffer/comparator connected to a common internal bus. The diagram is marked with MSv30930V3.
Figure 297: Surface charge transfer analog I/O group structure. The diagram illustrates an 'Analog I/O group' containing four GPIO interfaces: Gx_IO1, Gx_IO2, Gx_IO3, and Gx_IO4. Gx_IO1 is connected to Electrode 1 via resistor Rs1; Electrode 1 has a parasitic capacitance Cx1 and a sensor voltage V_SENSOR. Gx_IO2 is connected to the sampling capacitor Cs with voltage Vcs. Gx_IO3 is connected to Electrode 2 via Rs2, with capacitance Cx2 and voltage V_SENSOR. Gx_IO4 is connected to Electrode 3 via Rs3, with capacitance Cx3 and voltage V_SENSOR. Each GPIO block inside the group shows internal circuitry including two MOSFET switches (one to a high rail, one to a low rail) and a buffer/comparator connected to a common internal bus. The diagram is marked with MSv30930V3.

Note: \( G_x\_IO_y \) where x is the analog I/O group number and y the GPIO number within the selected group.

The surface charge transfer acquisition principle consists of charging an electrode capacitance ( \( C_X \) ) and transferring a part of the accumulated charge into a sampling

capacitor ( \( C_S \) ). This sequence is repeated until the voltage across \( C_S \) reaches a given threshold ( \( V_{IH} \) in our case). The number of charge transfers required to reach the threshold is a direct representation of the size of the electrode capacitance.

Table 279 details the charge transfer acquisition sequence of the capacitive sensing channel 1. States 3 to 7 are repeated until the voltage across \( C_S \) reaches the given threshold. The same sequence applies to the acquisition of the other channels. The electrode serial resistor \( R_S \) improves the ESD immunity of the solution.

Table 279. Acquisition sequence summary

StateGx_IO1
(channel)
Gx_IO2
(sampling)
Gx_IO3
(channel)
Gx_IO4
(channel)
State description
#1Input floating
with analog
switch closed
Output open-
drain low with
analog switch
closed
Input floating with analog switch
closed
Discharge all \( C_X \) and
\( C_S \)
#2Input floatingDead time
#3Output push-
pull high
Input floatingCharge \( C_{X1} \)
#4Input floatingDead time
#5Input floating with analog switch
closed
Input floatingCharge transfer from
\( C_{X1} \) to \( C_S \)
#6Input floatingDead time
#7Input floatingMeasure \( C_S \) voltage

Note: Gx_IOy where x is the analog I/O group number and y the GPIO number within the selected group.

The voltage variation over the time on the sampling capacitor \( C_S \) is detailed below (refer to Figure 297 for \( V_{SENSOR} \) and \( V_{CS} \) definition):

Figure 298. Sampling capacitor voltage variation

Figure 298: Sampling capacitor voltage variation. The graph shows the voltage Vcs (yellow curve) increasing over time (t) during two sampling periods, S1 and S2. The voltage is measured relative to VDD (top dashed line) and VIH (middle dashed line). The voltage starts at a low level and rises towards VDD. The sampling periods are indicated by vertical blue lines representing the clock signal. The graph is labeled MSV71405V1.

The graph illustrates the voltage variation of a sampling capacitor (V CS ) over time (t) during two sampling periods, S1 and S2. The vertical axis represents voltage, with markers for V SENSOR , V CS , V DD , and V IH . The horizontal axis represents time (t). The voltage V CS (yellow curve) starts at a low level and rises towards V DD during each sampling period. The sampling periods are indicated by vertical blue lines representing the clock signal. The graph is labeled MSV71405V1.

Figure 298: Sampling capacitor voltage variation. The graph shows the voltage Vcs (yellow curve) increasing over time (t) during two sampling periods, S1 and S2. The voltage is measured relative to VDD (top dashed line) and VIH (middle dashed line). The voltage starts at a low level and rises towards VDD. The sampling periods are indicated by vertical blue lines representing the clock signal. The graph is labeled MSV71405V1.

30.4.3 Reset and clocks

The TSC clock source is the AHB clock (HCLK). Two programmable prescalers are used to generate the pulse generator and the spread spectrum internal clocks:

The reset and clock controller (RCC) provides dedicated bits to enable the touch sensing controller clock and to reset this peripheral. For more information, refer to Section 10: Reset and clock control (RCC) .

30.4.4 Charge transfer acquisition sequence

An example of a charge transfer acquisition sequence is detailed in Figure 299 .

Figure 299. Charge transfer acquisition sequence

Timing diagram showing the charge transfer acquisition sequence. The diagram plots three signals over time: CLK_AHB (a high-frequency square wave), Cx (channel I/O), and Cs (sampling capacitor I/O). The sequence starts with a 'Discharge Cx and Cs' state where both signals are at 0V. This is followed by a 'Dead time state'. Then, a 'Pulse high state (charge of Cx)' occurs where Cx goes to 1V. This is followed by another 'Dead time state'. Then, a 'Pulse low state (charge transfer from Cx to Cs)' occurs where Cx goes to 0V. This is followed by a 'Cs reading' state. Then, a 'Dead time state'. Then, a 'Pulse high state' occurs where Cx goes to 1V. This is followed by a 'Spread spectrum state' where the charge transfer frequency varies. This is followed by a 'Dead time state'. Then, a 'Pulse low state' occurs where Cx goes to 0V. This is followed by another 'Cs reading' state. Finally, a 'Dead time state' occurs. The 'Charge transfer frequency' is indicated by a double-headed arrow between the start of the first pulse high state and the start of the second pulse high state. The diagram is labeled MSv30932V3.
Timing diagram showing the charge transfer acquisition sequence. The diagram plots three signals over time: CLK_AHB (a high-frequency square wave), Cx (channel I/O), and Cs (sampling capacitor I/O). The sequence starts with a 'Discharge Cx and Cs' state where both signals are at 0V. This is followed by a 'Dead time state'. Then, a 'Pulse high state (charge of Cx)' occurs where Cx goes to 1V. This is followed by another 'Dead time state'. Then, a 'Pulse low state (charge transfer from Cx to Cs)' occurs where Cx goes to 0V. This is followed by a 'Cs reading' state. Then, a 'Dead time state'. Then, a 'Pulse high state' occurs where Cx goes to 1V. This is followed by a 'Spread spectrum state' where the charge transfer frequency varies. This is followed by a 'Dead time state'. Then, a 'Pulse low state' occurs where Cx goes to 0V. This is followed by another 'Cs reading' state. Finally, a 'Dead time state' occurs. The 'Charge transfer frequency' is indicated by a double-headed arrow between the start of the first pulse high state and the start of the second pulse high state. The diagram is labeled MSv30932V3.

For higher flexibility, the charge transfer frequency is fully configurable. Both the pulse high state (charge of \( C_X \) ) and the pulse low state (transfer of charge from \( C_X \) to \( C_S \) ) duration can be defined using the CTPH[3:0] and CTPL[3:0] bits in the TSC_CR register. The standard range for the pulse high and low states duration is 500 ns to 2 \( \mu\text{s} \) . To ensure a correct measurement of the electrode capacitance, the pulse high state duration must be set to ensure that \( C_X \) is always fully charged.

A dead time where both the sampling capacitor I/O and the channel I/O are in input floating state is inserted between the pulse high and low states to ensure an optimum charge transfer acquisition sequence. This state duration is 1 period of HCLK.

At the end of the pulse high state and if the spread spectrum feature is enabled, a variable number of periods of the SSCLK clock are added.

The reading of the sampling capacitor I/O, to determine if the voltage across \( C_S \) has reached the given threshold, is performed at the end of the pulse low state.

Note: The following TSC control register configurations are forbidden:

30.4.5 Spread spectrum feature

The spread spectrum feature generates a variation of the charge transfer frequency. This is done to improve the robustness of the charge transfer acquisition in noisy environments and also to reduce the induced emission. The maximum frequency variation is in the range of 10% to 50% of the nominal charge transfer period. For instance, for a nominal charge transfer frequency of 250 kHz (4 \( \mu\text{s} \) ), the typical spread spectrum deviation is 10% (400 ns) which leads to a minimum charge transfer frequency of ~227 kHz.

In practice, the spread spectrum consists of adding a variable number of SSCLK periods to the pulse high state using the principle shown below:

Figure 300. Spread spectrum variation principle

Figure 300. Spread spectrum variation principle. A graph showing 'Deviation value' on the y-axis and 'Number of pulses' on the x-axis. The y-axis has labels 0, 1, 2, 3, and (SSD +1). The x-axis has labels n-1, n, and n+1. The graph shows a staircase-like curve that increases from 0 to (SSD +1) at pulse n, and then decreases back towards 0. The curve is symmetric around pulse n. The text 'MS30933V1' is in the bottom right corner of the graph area.
Figure 300. Spread spectrum variation principle. A graph showing 'Deviation value' on the y-axis and 'Number of pulses' on the x-axis. The y-axis has labels 0, 1, 2, 3, and (SSD +1). The x-axis has labels n-1, n, and n+1. The graph shows a staircase-like curve that increases from 0 to (SSD +1) at pulse n, and then decreases back towards 0. The curve is symmetric around pulse n. The text 'MS30933V1' is in the bottom right corner of the graph area.

The table below details the maximum frequency deviation with different HCLK settings:

Table 280. Spread spectrum deviation versus AHB clock frequency

\( f_{HCLK} \)Spread spectrum stepMaximum spread spectrum deviation
24 MHz41.6 ns10666.6 ns
48 MHz20.8 ns5333.3 ns

The spread spectrum feature can be disabled/enabled using the SSE bit in the TSC_CR register. The frequency deviation is also configurable to accommodate the device HCLK clock frequency and the selected charge transfer frequency through the SSPSC and SSD[6:0] bits in the TSC_CR register.

30.4.6 Max count error

The max count error prevents long acquisition times resulting from a faulty capacitive sensing channel. It consists of specifying a maximum count value for the analog I/O group counters. This maximum count value is specified using the MCV[2:0] bits in the TSC_CR register. As soon as an acquisition group counter reaches this maximum value, the ongoing acquisition is stopped and the end of acquisition (EOAF bit) and max count error (MCEF bit) flags are both set. An interrupt can also be generated if the corresponding end of acquisition (EOAIE bit) or/and max count error (MCEIE bit) interrupt enable bits are set.

30.4.7 Sampling capacitor I/O and channel I/O mode selection

To allow the GPIOs to be controlled by the touch sensing controller, the corresponding alternate function must be enabled through the standard GPIO registers and the GPIOxAFR registers.

The GPIOs modes controlled by the TSC are defined using the TSC_IOSCR and TSC_IOCCR register.

When there is no ongoing acquisition, all the I/Os controlled by the touch sensing controller are in default state. While an acquisition is ongoing, only unused I/Os (neither defined as

sampling capacitor I/O nor as channel I/O) are in default state. The IODEF bit in the TSC_CR register defines the configuration of the I/Os which are in default state. The table below summarizes the configuration of the I/O depending on its mode.

Table 281. I/O state depending on its mode and IODEF bit value

IODEF bitAcquisition statusUnused I/O modeChannel I/O modeSampling capacitor I/O mode
0
(output push-pull low)
NoOutput push-pull lowOutput push-pull lowOutput push-pull low
0
(output push-pull low)
OngoingOutput push-pull low--
1
(input floating)
NoInput floatingInput floatingInput floating
1
(input floating)
OngoingInput floating--

Unused I/O mode

An unused I/O corresponds to a GPIO controlled by the TSC peripheral but not defined as an electrode I/O nor as a sampling capacitor I/O.

Sampling capacitor I/O mode

To allow the control of the sampling capacitor I/O by the TSC peripheral, the corresponding GPIO must be first set to alternate output open drain mode and then the corresponding Gx_IOy bit in the TSC_IOSCR register must be set.

Only one sampling capacitor per analog I/O group must be enabled at a time.

Channel I/O mode

To allow the control of the channel I/O by the TSC peripheral, the corresponding GPIO must be first set to alternate output push-pull mode and the corresponding Gx_IOy bit in the TSC_IOCCR register must be set.

For proximity detection where a higher equivalent electrode surface is required or to speed-up the acquisition process, it is possible to enable and simultaneously acquire several channels belonging to the same analog I/O group.

Note: During the acquisition phase and even if the TSC peripheral alternate function is not enabled, as soon as the TSC_IOSCR or TSC_IOCCR bit is set, the corresponding GPIO analog switch is automatically controlled by the touch sensing controller.

30.4.8 Acquisition mode

The touch sensing controller offers two acquisition modes:

capacitive sensing channels acquisition with an external signal without additional CPU load.

The GxE bits in the TSC_IOGCSR registers specify which analog I/O groups are enabled (corresponding counter is counting). The C S voltage of a disabled analog I/O group is not monitored and this group does not participate in the triggering of the end of acquisition flag. However, if the disabled analog I/O group contains some channels, they are pulsed.

When the C S voltage of an enabled analog I/O group reaches the given threshold, the corresponding GxS bit of the TSC_IOGCSR register is set. When the acquisition of all enabled analog I/O groups is complete (all GxS bits of all enabled analog I/O groups are set), the EOAF flag in the TSC_ISR register is set. An interrupt request is generated if the EOAIE bit in the TSC_IER register is set.

In the case that a max count error is detected, the ongoing acquisition is stopped and both the EOAF and MCEF flags in the TSC_ISR register are set. Interrupt requests can be generated for both events if the corresponding bits (EOAIE and MCEIE bits of the TSCIER register) are set. Note that when the max count error is detected the remaining GxS bits in the enabled analog I/O groups are not set.

To clear the interrupt flags, the corresponding EOAIC and MCEIC bits in the TSC_ICR register must be set.

The analog I/O group counters are cleared when a new acquisition is started. They are updated with the number of charge transfer cycles generated on the corresponding channel(s) upon the completion of the acquisition.

30.4.9 I/O hysteresis and analog switch control

In order to offer a higher flexibility, the touch sensing controller is able to take the control of the Schmitt trigger hysteresis and analog switch of each Gx_IOy. This control is available whatever the I/O control mode is (controlled by standard GPIO registers or other peripherals) assuming that the touch sensing controller is enabled. This may be useful to perform a different acquisition sequence or for other purposes.

In order to improve the system immunity, the Schmitt trigger hysteresis of the GPIOs controlled by the TSC must be disabled by resetting the corresponding Gx_IOy bit in the TSC_IOHCR register.

30.5 TSC low-power modes

Table 282. Effect of low-power modes on TSC

ModeDescription
SleepNo effect. Peripheral interrupts cause the device to exit Sleep mode.
StopPeripheral registers content is kept.
StandbyPowered-down. The peripheral must be reinitialized after exiting Standby mode.

30.5.1 Comparator usage overview

This low-power mode requires that the GPIO dedicated to the sampling capacitor C S has both the TSC alternate function (TSC_Gx_IOy) and the COMP alternate function (COMPx_INP) available, see product datasheet.

In this case, the TSC peripheral has the possibility to use the microcontroller internal comparator to achieve lower power consumption.

The method uses the same principle as the surface charge transfer acquisition that is the acquisition of the different sensors is automatically stopped when the voltage on the sampling capacitor reaches a certain threshold.

Figure 301. Surface charge transfer with comparator analog I/O group structure

Figure 301: Surface charge transfer with comparator analog I/O group structure. The diagram illustrates the hardware architecture for TSC using an internal comparator. It shows three electrodes (Electrode 1, 2, and 3) each with a series resistor (Rs1, Rs2, Rs3) and parasitic capacitance (Cx1, Cx2, Cx3) connected to an 'Analog I/O group'. Inside this group, switches connect the electrodes to a common sampling capacitor (Cs) with voltage Vcs. The voltage Vcs is fed into the non-inverting input (COMPx INP) of a comparator (COMPx). The inverting input (COMPx INM) is connected to a multiplexer (COMPx_INM_SEL) which selects between different fractions of VREFINT (1/4, 1/2, 3/4, or 1). The comparator output goes through a system configuration controller (SYSCFG_TSCCR) to the TSC controller. The TSC controller also manages the switches in the Analog I/O group. The diagram is labeled MSv71404V1.
Figure 301: Surface charge transfer with comparator analog I/O group structure. The diagram illustrates the hardware architecture for TSC using an internal comparator. It shows three electrodes (Electrode 1, 2, and 3) each with a series resistor (Rs1, Rs2, Rs3) and parasitic capacitance (Cx1, Cx2, Cx3) connected to an 'Analog I/O group'. Inside this group, switches connect the electrodes to a common sampling capacitor (Cs) with voltage Vcs. The voltage Vcs is fed into the non-inverting input (COMPx INP) of a comparator (COMPx). The inverting input (COMPx INM) is connected to a multiplexer (COMPx_INM_SEL) which selects between different fractions of VREFINT (1/4, 1/2, 3/4, or 1). The comparator output goes through a system configuration controller (SYSCFG_TSCCR) to the TSC controller. The TSC controller also manages the switches in the Analog I/O group. The diagram is labeled MSv71404V1.

Unlike charge transfer acquisition (where the threshold is fixed = \( V_{IH} \) ), here the threshold is programmable. The sampling capacitor is internally redirected to the comparator input in order to offer a programmable voltage threshold value \( V_{COMP} \) based on \( V_{REFINT} \) . The possible configurations are about 0.3, 0.6, 0.9 or 1.2 V (corresponding to \( 1/4 V_{REFINT} \) , \( 1/2 V_{REFINT} \) , \( 3/4 V_{REFINT} \) or \( V_{REFINT} \) ).

\( V_{REFINT} \) is the bandgap voltage ( \( \sim 1.2 \) V).

By reducing the voltage threshold, the acquisition time is shortened which in turn reduces the power consumption.

The selection of the threshold value is a compromise between sensor acquisition time (the lowest the threshold the best) and sensor sensitivity (the highest the threshold the best).

Figure 302 below compares the normal mode and the comparator mode (see Figure 301 for \( V_{SENSOR} \) and \( V_{CS} \) definition).

The SYSCFG_TSCCR register should be set appropriately in order to configure the MUX allowing the use of the comparator mode instead of the usual TSC mode (see device reference manual).

Figure 302. Sensor voltage variation for both normal and comparator mode

Two graphs comparing TSC normal operation and TSC with comparator mode. The top graph shows sensor voltage (V_SENSOR) rising towards V_IH threshold in two segments (S1, S2) with many pulses. The bottom graph shows sensor voltage rising towards V_COMP threshold in two segments (S1, S2) with fewer pulses, indicating faster acquisition.

The figure consists of two vertically stacked plots. The top plot, labeled 'TSC normal operation', shows the sensor voltage ( \( V_{SENSOR} \) ) over time ( \( t \) ). The y-axis has markers for \( V_{CS} \) , \( V_{DD} \) , and \( V_{IH} \) . The voltage rises in two segments, S1 and S2, towards the \( V_{IH} \) threshold. Blue vertical lines represent charging pulses. The bottom plot, labeled 'TSC with comparator mode', shows the sensor voltage over time. The y-axis has markers for \( V_{SENSOR} \) , \( V_{CS} \) , \( V_{DD} \) , \( V_{IH} \) , and \( V_{COMP} \) . The voltage rises in two segments, S1 and S2, towards the \( V_{COMP} \) threshold. This plot shows fewer charging pulses to reach the threshold compared to the normal mode. A small code 'MSV71403V1' is visible in the bottom right corner of the figure area.

Two graphs comparing TSC normal operation and TSC with comparator mode. The top graph shows sensor voltage (V_SENSOR) rising towards V_IH threshold in two segments (S1, S2) with many pulses. The bottom graph shows sensor voltage rising towards V_COMP threshold in two segments (S1, S2) with fewer pulses, indicating faster acquisition.

Using the internal comparator, the acquisition time is consequently reduced. This implies that the number of counts needed to reach the threshold is also reduced, thus, the TSC peripheral achieves lower power consumption.

The COMPx_INM_SEL and COMPx_INP_SEL bitfields used to configure the comparator are available in Section 26.6.1: COMP1 control and status register (COMP1_CSR) and Section 26.6.2: COMP2 control and status register (COMP2_CSR) .

30.6 TSC interrupts

Table 283. Interrupt control bits

Interrupt eventEnable control bitEvent flagClear flag bitExit the Sleep modeExit the Stop modeExit the Standby mode
End of acquisitionEOAIEEOAIFEOAICYesNoNo
Max count errorMCEIEMCEIFMCEICYesNoNo

30.7 TSC registers

Refer to Section 1.2 of the reference manual for a list of abbreviations used in register descriptions.

The peripheral registers can be accessed by words (32-bit).

30.7.1 TSC control register (TSC_CR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
CTPH[3:0]CTPL[3:0]SSD[6:0]SSE
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
SSPSCPGPSC[2:0]Res.Res.Res.Res.MCV[2:0]IODEFSYNC POLAMSTARTTSCE
rwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:28 CTPH[3:0] : Charge transfer pulse high

These bits are set and cleared by software. They define the duration of the high state of the charge transfer pulse (charge of \( C_X \) ).

0000: 1x \( t_{PGCLK} \)

0001: 2x \( t_{PGCLK} \)

...

1111: 16x \( t_{PGCLK} \)

Note: These bits must not be modified when an acquisition is ongoing.

Bits 27:24 CTPL[3:0] : Charge transfer pulse low

These bits are set and cleared by software. They define the duration of the low state of the charge transfer pulse (transfer of charge from \( C_X \) to \( C_S \) ).

0000: \( 1 \times t_{PGCLK} \)

0001: \( 2 \times t_{PGCLK} \)

...

1111: \( 16 \times t_{PGCLK} \)

Note: These bits must not be modified when an acquisition is ongoing.

Note: Some configurations are forbidden. Refer to the Section 30.4.4: Charge transfer acquisition sequence for details.

Bits 23:17 SSD[6:0] : Spread spectrum deviation

These bits are set and cleared by software. They define the spread spectrum deviation which consists in adding a variable number of periods of the SSCLK clock to the charge transfer pulse high state.

0000000: \( 1 \times t_{SSCLK} \)

0000001: \( 2 \times t_{SSCLK} \)

...

1111111: \( 128 \times t_{SSCLK} \)

Note: These bits must not be modified when an acquisition is ongoing.

Bit 16 SSE : Spread spectrum enable

This bit is set and cleared by software to enable/disable the spread spectrum feature.

0: Spread spectrum disabled

1: Spread spectrum enabled

Note: This bit must not be modified when an acquisition is ongoing.

Bit 15 SSPSC : Spread spectrum prescaler

This bit is set and cleared by software. It selects the AHB clock divider used to generate the spread spectrum clock (SSCLK).

0: \( f_{HCLK} \)

1: \( f_{HCLK} / 2 \)

Note: This bit must not be modified when an acquisition is ongoing.

Bits 14:12 PGPSC[2:0] : Pulse generator prescaler

These bits are set and cleared by software. They select the AHB clock divider used to generate the pulse generator clock (PGCLK).

000: \( f_{HCLK} \)

001: \( f_{HCLK} / 2 \)

010: \( f_{HCLK} / 4 \)

011: \( f_{HCLK} / 8 \)

100: \( f_{HCLK} / 16 \)

101: \( f_{HCLK} / 32 \)

110: \( f_{HCLK} / 64 \)

111: \( f_{HCLK} / 128 \)

Note: These bits must not be modified when an acquisition is ongoing.

Note: Some configurations are forbidden. Refer to the Section 30.4.4: Charge transfer acquisition sequence for details.

Bits 11:8 Reserved, must be kept at reset value.

Bits 7:5 MCV[2:0]: Max count value

These bits are set and cleared by software. They define the maximum number of charge transfer pulses that can be generated before a max count error is generated.

000: 255

001: 511

010: 1023

011: 2047

100: 4095

101: 8191

110: 16383

111: reserved

Note: These bits must not be modified when an acquisition is ongoing.

Bit 4 IODEF: I/O Default mode

This bit is set and cleared by software. It defines the configuration of all the TSC I/Os when there is no ongoing acquisition. When there is an ongoing acquisition, it defines the configuration of all unused I/Os (not defined as sampling capacitor I/O or as channel I/O).

0: I/Os are forced to output push-pull low

1: I/Os are in input floating

Note: This bit must not be modified when an acquisition is ongoing.

Bit 3 SYNCPOL: Synchronization pin polarity

This bit is set and cleared by software to select the polarity of the synchronization input pin.

0: Falling edge only

1: Rising edge and high level

Bit 2 AM: Acquisition mode

This bit is set and cleared by software to select the acquisition mode.

0: Normal acquisition mode (acquisition starts as soon as START bit is set)

1: Synchronized acquisition mode (acquisition starts if START bit is set and when the selected signal is detected on the SYNC input pin)

Note: This bit must not be modified when an acquisition is ongoing.

Bit 1 START: Start a new acquisition

This bit is set by software to start a new acquisition. It is cleared by hardware as soon as the acquisition is complete or by software to cancel the ongoing acquisition.

0: Acquisition not started

1: Start a new acquisition

Bit 0 TSCE: Touch sensing controller enable

This bit is set and cleared by software to enable/disable the touch sensing controller.

0: Touch sensing controller disabled

1: Touch sensing controller enabled

Note: When the touch sensing controller is disabled, TSC registers settings have no effect.

30.7.2 TSC interrupt enable register (TSC_IER)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MCEIEEOAIE
rwrw

Bits 31:2 Reserved, must be kept at reset value.

Bit 1 MCEIE : Max count error interrupt enable

This bit is set and cleared by software to enable/disable the max count error interrupt.

0: Max count error interrupt disabled

1: Max count error interrupt enabled

Bit 0 EOAIE : End of acquisition interrupt enable

This bit is set and cleared by software to enable/disable the end of acquisition interrupt.

0: End of acquisition interrupt disabled

1: End of acquisition interrupt enabled

30.7.3 TSC interrupt clear register (TSC_ICR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MCEICEOAIC
rwrw

Bits 31:2 Reserved, must be kept at reset value.

Bit 1 MCEIC : Max count error interrupt clear

This bit is set by software to clear the max count error flag and it is cleared by hardware when the flag is reset. Writing a 0 has no effect.

0: No effect

1: Clears the corresponding MCEF of the TSC_ISR register

Bit 0 EOAIC : End of acquisition interrupt clear

This bit is set by software to clear the end of acquisition flag and it is cleared by hardware when the flag is reset. Writing a 0 has no effect.

0: No effect

1: Clears the corresponding EOAF of the TSC_ISR register

30.7.4 TSC interrupt status register (TSC_ISR)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MCEF
r
EOAF
r

Bits 31:2 Reserved, must be kept at reset value.

Bit 1 MCEF : Max count error flag

This bit is set by hardware as soon as an analog I/O group counter reaches the max count value specified. It is cleared by software writing 1 to the bit MCEIC of the TSC_ICR register.

0: No max count error (MCE) detected

1: Max count error (MCE) detected

Bit 0 EOAF : End of acquisition flag

This bit is set by hardware when the acquisition of all enabled group is complete (all GxS bits of all enabled analog I/O groups are set or when a max count error is detected). It is cleared by software writing 1 to the bit EOAIC of the TSC_ICR register.

0: Acquisition is ongoing or not started

1: Acquisition is complete

30.7.5 TSC I/O hysteresis control register (TSC_IOHCR)

Address offset: 0x10

Reset value: 0xFFFF FFFF

31302928272625242322212019181716
G8_IO4G8_IO3G8_IO2G8_IO1G7_IO4G7_IO3G7_IO2G7_IO1G6_IO4G6_IO3G6_IO2G6_IO1G5_IO4G5_IO3G5_IO2G5_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
G4_IO4G4_IO3G4_IO2G4_IO1G3_IO4G3_IO3G3_IO2G3_IO1G2_IO4G2_IO3G2_IO2G2_IO1G1_IO4G1_IO3G1_IO2G1_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 Gx_IOy : Gx_IOy Schmitt trigger hysteresis mode

These bits are set and cleared by software to enable/disable the Gx_IOy Schmitt trigger hysteresis.

0: Gx_IOy Schmitt trigger hysteresis disabled

1: Gx_IOy Schmitt trigger hysteresis enabled

Note: These bits control the I/O Schmitt trigger hysteresis whatever the I/O control mode is (even if controlled by standard GPIO registers).

30.7.6 TSC I/O analog switch control register (TSC_IOASCR)

Address offset: 0x18

Reset value: 0x0000 0000

31302928272625242322212019181716
G8_IO4G8_IO3G8_IO2G8_IO1G7_IO4G7_IO3G7_IO2G7_IO1G6_IO4G6_IO3G6_IO2G6_IO1G5_IO4G5_IO3G5_IO2G5_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

1514131211109876543210
G4_IO4G4_IO3G4_IO2G4_IO1G3_IO4G3_IO3G3_IO2G3_IO1G2_IO4G2_IO3G2_IO2G2_IO1G1_IO4G1_IO3G1_IO2G1_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 Gx_IOy : Gx_IOy analog switch enable

These bits are set and cleared by software to enable/disable the Gx_IOy analog switch.

0: Gx_IOy analog switch disabled (opened)

1: Gx_IOy analog switch enabled (closed)

Note: These bits control the I/O analog switch whatever the I/O control mode is (even if controlled by standard GPIO registers).

30.7.7 TSC I/O sampling control register (TSC_IOSCR)

Address offset: 0x20

Reset value: 0x0000 0000

31302928272625242322212019181716
G8_IO4G8_IO3G8_IO2G8_IO1G7_IO4G7_IO3G7_IO2G7_IO1G6_IO4G6_IO3G6_IO2G6_IO1G5_IO4G5_IO3G5_IO2G5_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

1514131211109876543210
G4_IO4G4_IO3G4_IO2G4_IO1G3_IO4G3_IO3G3_IO2G3_IO1G2_IO4G2_IO3G2_IO2G2_IO1G1_IO4G1_IO3G1_IO2G1_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 Gx_IOy : Gx_IOy sampling mode

These bits are set and cleared by software to configure the Gx_IOy as a sampling capacitor I/O. Only one I/O per analog I/O group must be defined as sampling capacitor.

0: Gx_IOy unused

1: Gx_IOy used as sampling capacitor

Note: These bits must not be modified when an acquisition is ongoing.

During the acquisition phase and even if the TSC peripheral alternate function is not enabled, as soon as the TSC_IOSCR bit is set, the corresponding GPIO analog switch is automatically controlled by the touch sensing controller.

30.7.8 TSC I/O channel control register (TSC_IOCCR)

Address offset: 0x28

Reset value: 0x0000 0000

31302928272625242322212019181716
G8_IO4G8_IO3G8_IO2G8_IO1G7_IO4G7_IO3G7_IO2G7_IO1G6_IO4G6_IO3G6_IO2G6_IO1G5_IO4G5_IO3G5_IO2G5_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
G4_IO4G4_IO3G4_IO2G4_IO1G3_IO4G3_IO3G3_IO2G3_IO1G2_IO4G2_IO3G2_IO2G2_IO1G1_IO4G1_IO3G1_IO2G1_IO1
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 Gx_IOy : Gx_IOy channel mode

These bits are set and cleared by software to configure the Gx_IOy as a channel I/O.

0: Gx_IOy unused

1: Gx_IOy used as channel

Note: These bits must not be modified when an acquisition is ongoing.

During the acquisition phase and even if the TSC peripheral alternate function is not enabled, as soon as the TSC_IOCCR bit is set, the corresponding GPIO analog switch is automatically controlled by the touch sensing controller.

30.7.9 TSC I/O group control status register (TSC_IOGCSR)

Address offset: 0x30

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.G8SG7SG6SG5SG4SG3SG2SG1S
rrrrrrrr
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.G8EG7EG6EG5EG4EG3EG2EG1E
rwrwrwrwrwrwrwrw

Bits 31:24 Reserved, must be kept at reset value.

Bits 23:16 GxS : Analog I/O group x status

These bits are set by hardware when the acquisition on the corresponding enabled analog I/O group x is complete. They are cleared by hardware when a new acquisition is started.

0: Acquisition on analog I/O group x is ongoing or not started

1: Acquisition on analog I/O group x is complete

Note: When a max count error is detected the remaining GxS bits of the enabled analog I/O groups are not set.

Bits 15:8 Reserved, must be kept at reset value.

Bits 7:0 GxE : Analog I/O group x enable

These bits are set and cleared by software to enable/disable the acquisition (counter is counting) on the corresponding analog I/O group x.

0: Acquisition on analog I/O group x disabled

1: Acquisition on analog I/O group x enabled

30.7.10 TSC I/O group x counter register (TSC_IOGxCR)

x represents the analog I/O group number.

Address offset: 0x30 + 0x04 * x, (x = 1 to 8)

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
1514131211109876543210
Res.CNT[13:0]
rrrrrrrrrrrrrr

Bits 31:14 Reserved, must be kept at reset value.

Bits 13:0 CNT[13:0] : Counter value

These bits represent the number of charge transfer cycles generated on the analog I/O group x to complete its acquisition (voltage across C S has reached the threshold).

30.7.11 TSC register map

Table 284. TSC register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x0000TSC_CRCTPH[3:0]CTPL[3:0]SSD[6:0]SSESSPSCPGPSC[2:0]Res.MCV[2:0]IODEFSYNCPOLAMSTARTTSCE
Reset value0000000000000000000000000000
0x0004TSC_IERRes.MCEIEEOAIE
Reset value00
0x0008TSC_ICRRes.MCEICEOAIC
Reset value00
0x000CTSC_ISRRes.MCEFEOAF
Reset value00
0x0010TSC_IOHCRG8_IO4G8_IO3G8_IO2G8_IO1G7_IO4G7_IO3G7_IO2G7_IO1G6_IO4G6_IO3G6_IO2G6_IO1G5_IO4G5_IO3G5_IO2G5_IO1G4_IO4G4_IO3G4_IO2G4_IO1G3_IO4G3_IO3G3_IO2G3_IO1G2_IO4G2_IO3G2_IO2G2_IO1G1_IO4G1_IO3G1_IO2G1_IO1
Reset value11111111111111111111111111111111
0x0014Reserved
0x0018TSC_IOASCRG8_IO4G8_IO3G8_IO2G8_IO1G7_IO4G7_IO3G7_IO2G7_IO1G6_IO4G6_IO3G6_IO2G6_IO1G5_IO4G5_IO3G5_IO2G5_IO1G4_IO4G4_IO3G4_IO2G4_IO1G3_IO4G3_IO3G3_IO2G3_IO1G2_IO4G2_IO3G2_IO2G2_IO1G1_IO4G1_IO3G1_IO2G1_IO1
Reset value00000000000000001111111111111111

Table 284. TSC register map and reset values (continued)

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x001CReserved
0x0020TSC_IOSCRG8_I04G8_I03G8_I02G8_I01G7_I04G7_I03G7_I02G7_I01G6_I04G6_I03G6_I02G6_I01G5_I04G5_I03G5_I02G5_I01G4_I04G4_I03G4_I02G4_I01G3_I04G3_I03G3_I02G3_I01G2_I04G2_I03G2_I02G2_I01G1_I04G1_I03G1_I02G1_I01
Reset value00000000000000001111111100000000
0x0024Reserved
0x0028TSC_IOCCRG8_I04G8_I03G8_I02G8_I01G7_I04G7_I03G7_I02G7_I01G6_I04G6_I03G6_I02G6_I01G5_I04G5_I03G5_I02G5_I01G4_I04G4_I03G4_I02G4_I01G3_I04G3_I03G3_I02G3_I01G2_I04G2_I03G2_I02G2_I01G1_I04G1_I03G1_I02G1_I01
Reset value00000000000000001111111100000000
0x002CReserved
0x0030TSC_IOGCSRRes.Res.Res.Res.Res.Res.Res.Res.G8SG7SG6SG5SG4SG3SG2SG1SRes.Res.Res.Res.Res.Res.Res.Res.Res.G8EG7EG6EG5EG4EG3EG2EG1E
Reset value0000000000000000
0x0034TSC_IOG1CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x0038TSC_IOG2CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x003CTSC_IOG3CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x0040TSC_IOG4CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x0044TSC_IOG5CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x0048TSC_IOG6CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x004CTSC_IOG7CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
0x0050TSC_IOG8CRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[13:0]
Reset value000000000000
Refer to Section 2.3: Memory organization for the register boundary addresses.