Software AN3301
22/35 Doc ID 18161 Rev 1
/*Sets the global variable (Is_Pen_Down) to handle the global variables (Touch_Data
[1] to Touch_Data [4] i.e. 4 bytes of x, y & z data coordinates) in the main while
loop*/
Is_Pen_Down = TRUE;
/*Handling Coordinates codes should be here */
/*Checking either the bit 0 or 1 or both (touch bit [or] data bit [or] touch and
data bits) value from Interrupt status register goes high*/
if ((Touch_Data [0] & 0x03) > 0)
{
/*Getting the Captured value from the Micro-controller Timer2 CNT register*/
Capture = TIM2->CNT;
/*Setting the (Captured value+CCR1_VAL) to the Micro-controller Timer2
CCR1 register.*/
TIM_SetCompare1 (TIM2, capture + CCR1_Val);
/*Enabling the Micro-controller Timer2 for 13ms*/
TIM_Cmd (TIM2, ENABLE);
}
else
{
/*Disabling the Micro-controller Timer2*/
TIM_Cmd (TIM2, DISABLE);
/*Resets the global variable (Is_Pen_Down) to clear the point (x, y & z data
coordinates) in the main while loop*/
Is_Pen_Down = FALSE;
}
}}
Data acquisition triggered by a write to “ACQ” bit
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);
/* Sets the ACQ [4] in the TSC Control Register (0x40) */
STMPE812A_InitiateAcquisition ();
/* Waiting until the ACQ [4] in the TSC Control Register (0x40) goes low */
while (!STMPE812A_IsAcquisitionComplete ())
AN3301 Software
Doc ID 18161 Rev 1 23/35
{}
/*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]);
/*Sets the global variable (Is_Pen_Down) to handle the global variables (Touch_Data
[1] to Touch_Data [4] i.e. 4 bytes of x, y & z data coordinates)*/
Is_Pen_Down = TRUE;
/*Handling Coordinates codes should be here */
/*Checking either the bit 0 or 1 or both (touch bit [or] data bit [or] touch and
data bits) value from Interrupt status register goes high*/
if ((Touch_Data [0] & 0x03) > 0)
{
/*Getting the Captured value from the Micro-controller Timer2 CNT register*/
Capture = TIM2->CNT;
/*Setting the (Captured value+CCR1_VAL) to the Micro-controller Timer2
CCR1 register.*/
TIM_SetCompare1 (TIM2, capture + CCR1_Val);
/*Enabling the Micro-controller Timer2 for 0ms*/
TIM_Cmd (TIM2, ENABLE);
}
else
{
/*Disabling the Micro-controller Timer2*/
TIM_Cmd (TIM2, DISABLE);
/*Resets the global variable (Is_Pen_Down) to clear the point (x, y & z data
coordinates) in the main while loop*/
Is_Pen_Down = FALSE;
}
}}
2.6.2 Touchscreen initialization and interrupt handling (normal interrupt
mode)
The following is an example for device initialization, interrupt servicing routine in normal
interrupt mode.
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*/
Software AN3301
24/35 Doc ID 18161 Rev 1
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);
/*Disabling the StatusRead [5] in the TSC Detection Configuration 2 Register (0x42)*/
STMPE812A_SetTSCStatusRead (STMPE812A_DISABLE);
/*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);
/*Setting the INT_Mode [7] as ‘Normal Interrupt Mode’ in the Interrupt Control
Register (0x08)*/
STMPE812A_SetInterruptMode(STMPE812A_INT_MODE_NORMAL);
/*Setting the INT_Type [1] as ‘Edge Interrupt Type’ in the Interrupt Control Register
(0x08)*/
STMPE812A_SetInterruptType (STMPE812A_INT_TYPE_EDGE);
/*Enabling the Global Interrupt in the Interrupt Control Register (0x08)*/
STMPE812A_EnableGlobalInterrupt (TRUE);
/*Enabling the interrupt from the system related source of TSC_DATA and TSC_RELEASE
to the host in the Interrupt Enable Register (0x09)*/
/*For Acq_Mode [7:6] in the TSC Detection Configuration 2 Register (0x42) is set as
‘Data acquisition timed by internal timer’*/
STMPE812A_EnableInterrupt (STMPE812A_INT_TSC_DATA|STMPE812A_INT_TSC_REL, TRUE);
/*Enabling the interrupt from the system related source of TSC_TOUCH, TSC_DATA and
TSC_RELEASE to the host in the Interrupt Enable Register (0x09)*/
/*For Acq_Mode [7:6] in the TSC Detection Configuration 2 Register (0x42) is set as
either ‘Data acquisition triggered by a write to “ACQ” bit’ (OR) ‘Data acquisition
using Host-Controlled Sampling Rate Control’*/
//STMPE812A_EnableInterrupt
(STMPE812A_INT_TSC_TOUCH|STMPE812A_INT_TSC_DATA|STMPE812A_INT_TSC_REL, TRUE);
/*Enabling the TSC operation in the System Control Register (0x03)*/
STMPE812A_EnableTouchscreen (TRUE);}

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