AN3301 Software
Doc ID 18161 Rev 1 19/35
2.6 Programming guide
In this section, the reference software programming code is shared based on the general
application of the STMPE812A. This includes the initialization and interrupt handling
routines for touchscreen controller (in all 3 acquisition modes and both normal and pen
down interrupt modes), GPIO, ADC and PWM.
The reference code is supplemented by the STMPE812A software library.
2.6.1 Touchscreen initialization and interrupt handling (pen down mode)
The following is an example for touchscreen initialization, interrupt servicing routine in pen
down mode, whereby all other interrupt sources (eg. GPIO, PWM and ADC) are not used in
the application.
A: Initialization
void STMPE812A_Initialization (void) {
/*Enabling the Soft Reset in the System Control Register (0x03)*/
STMPE812A_SoftReset ();
/*Enabling the ADC and TSC Clocks in the System Control Register (0x03)*/
STMPE812A_SetClock (STMPE812A_ENABLE, STMPE812A_ADC_CLK|STMPE812A_TSC_CLK);
/*Setting the Port - 2 as a special function in the Port Function Control Register
(0x04)*/
STMPE812A_SetPortFunction (STMPE812A_PORT2, STMPE812A_PORT_FUNC_SPECIAL_FUNC);
/*Setting the MAV_MODE [2:0] as ‘20 remove 4’, Precharge [1:0] as ‘no pre-charge’ and
Current _Limit [1:0] as ‘20mA’ in the TSC Control Register (0x40) respectively*/
STMPE812A_SetTSCController (STMPE812A_TSC_MAV_20_4, STMPE812A_TSC_NO_PRE,
STMPE812A_TSC_Current20M);
/*Setting the PenStrength [1:0] as ‘Most Sensitive (20K Pull-Up)’, TDetDly [2:0] as
‘40us’ and Settling [2:0] as ‘40us’ in the TSC Detection Configuration 1 Register
(0x41) respectively*/
STMPE812A_ConfigureTSC (STMPE812A_TSC_MOST_SEN, STMPE812A_TSC_TDD40,
STMPE812A_TSC_PDST40);
/*Setting the TSC operating mode OpMode [4] as ’12-bit X, 12-bit Y, 8-bit Z
acquisition’ in the TSC Detection Configuration 2 Register (0x42)*/
STMPE812A_SetTSCOpMode (STMPE812A_DISABLE);
/*Enabling the StatusRead [5] in the TSC Detection Configuration 2 Register (0x42)*/
STMPE812A_SetTSCStatusRead (STMPE812A_ENABLE);
/*Setting the Acq_Mode [7:6] as ‘Data acquisition timed by internal timer’ in the TSC
Detection Configuration 2 Register (0x42)*/
STMPE812A_SetTSCAcquisitionMode (STMPE812A_TSC_INTERNAL_TIMER);
/*Setting the Acq_Mode [7:6] as ‘Data acquisition triggered by a write to “ACQ” bit’
in the TSC Detection Configuration 2 Register (0x42)*/
//STMPE812A_SetTSCAcquisitionMode (STMPE812A_TSC_TRI_ACQ);
/*Setting the Acq_Mode [7:6] as ‘Data acquisition using Host-Controlled Sampling Rate
Control’ in the TSC Detection Configuration 2 Register (0x42)*/
//STMPE812A_SetTSCAcquisitionMode (STMPE812A_TSC_HC_SRC);
/*Setting the TSC sampling rate value of ‘0x0A’ in the TSC Sampling Rate Register
(0x43)*/
STMPE812A_SetTSCSamplingRate (0x0A);
Software AN3301
20/35 Doc ID 18161 Rev 1
/*Setting the INT_Mode [7] as ‘Pendown Interrupt Mode’ in the Interrupt Control
Register (0x08)*/
STMPE812A_SetInterruptMode(STMPE812A_INT_MODE_PEN_DOWN);
/*Enabling the Global Interrupt in the Interrupt Control Register (0x08)*/
STMPE812A_EnableGlobalInterrupt (TRUE);
/*Enabling the interrupt from the system related source of TSC_TOUCH and TSC_DATA to
the host in the Interrupt Enable Register (0x09)*/
STMPE812A_EnableInterrupt (STMPE812A_INT_TSC_TOUCH|STMPE812A_INT_TSC_DATA, TRUE);
/*Enabling the TSC operation in the System Control Register (0x03)*/
STMPE812A_EnableTouchscreen (TRUE);}
B: Interrupt handling (pen down mode)
Data acquisition timed by internal timer
void IRQHandler (void) {
u8 data [5];
if (GetITStatus (INTERRUPT_LINE)! = RESET)
{
/*Clearing the Interrupt pending bit from the Micro-controller*/
ClearITPendingBit (INTERRUPT_LINE);
/*Checking the Interrupt Pin Status goes low*/
if ((GPIO_INTERRUPT->IDR & GPIO_PIN_INTERRUPT) == 0)
{
/*Start host timer with an interval of 13ms*/
/*Check below for the timer routine*/
TIM_Cmd (TIM2, ENABLE);
}
}
}
Data acquisition triggered by a write to “ACQ” bit
void IRQHandler (void) {
u8 data [5];
if (GetITStatus (INTERRUPT_LINE)! = RESET)
{
/*Clearing the Interrupt pending bit from the Micro-controller*/
ClearITPendingBit (INTERRUPT_LINE);
/*Checking the Interrupt Pin Status goes low*/
if ((GPIO_INTERRUPT->IDR & GPIO_PIN_INTERRUPT) == 0)
{
/*Start host timer with an interval of 0ms*/
/*Check below for the timer routine*/
TIM_Cmd (TIM2, ENABLE);
}
}
}
AN3301 Software
Doc ID 18161 Rev 1 21/35
Data acquisition using host-controlled sampling rate control
void IRQHandler (void) {
u8 data [5];
if (GetITStatus (INTERRUPT_LINE)! = RESET)
{
/*Clearing the Interrupt pending bit from the Micro-controller*/
ClearITPendingBit (INTERRUPT_LINE);
/*Checking the Interrupt Pin Status goes low*/
if ((GPIO_INTERRUPT->IDR & GPIO_PIN_INTERRUPT) == 0)
{
/*Reading the Interrupt status register and Dummy data of 4 bytes of x, y & z data
from the register address of 0x44 to 0x48*/
I2C_Read_Data (STMPE812A_SLAVE_ADDR, STMPE812A_TSC_DATA, 5, &data [0]);
/*Start host timer with an interval of 13ms*/
/*Check below for the timer routine*/
TIM_Cmd (TIM2, ENABLE);
}
}
}
Micro-controller timer routine
Data acquisition timed by internal timer or data acquisition using host-controlled sampling
rate control:
void TIM2_IRQHandler (void) {
if (TIM_GetITStatus (TIM2, TIM_IT_CC1) != RESET)
{
/*Clearing the Timer 2 Interrupt pending bit from the Micro-controller*/
TIM_ClearITPendingBit (TIM2, TIM_IT_CC1);
/*Reading the Interrupt status register and 4 bytes of x, y & z data from the
register address of 0x44 to 0x48*/
I2C_Read_Data (STMPE812A_SLAVE_ADDR, STMPE812A_TSC_DATA, 5, &Touch_Data [0]);

STMPE812ABJR

Mfr. #:
Manufacturer:
STMicroelectronics
Description:
Touch Screen Controllers Touchscreen cntrlr S-Touch
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet