Software AN3301
28/35 Doc ID 18161 Rev 1
2.6.3 GPIO initialization and interrupt handling
The following is an example for GPIO initialization and interrupt servicing routine.
A: Initialization
void STMPE812A_GPIO_Initialization (void) {
/*Enabling the Soft Reset in the System Control Register (0x03)*/
STMPE812A_SoftReset ();
/*Enabling the GPIO Clock in the System Control Register (0x03)*/
STMPE812A_SetClock (STMPE812A_ENABLE, STMPE812A_GPIO_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 Port - 1 as a GPIO Input in the Port Function Control Register (0x04)*/
STMPE812A_SetPortFunction (STMPE812A_PORT1, STMPE812A_PORT_FUNC_GPIO_IP);
/*Enabling the IO-1 [1] as GPIO Falling Edge Detection in the GPIO Falling Edge
Detection Register (0x14)*/
STMPE812A_EnableGPIOFallingEdgeInterrupt (STMPE812A_IO1, TRUE);
/*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 ‘Level Interrupt Type’ in the Interrupt Control
Register (0x08)*/
STMPE812A_SetInterruptType (STMPE812A_INT_TYPE_LEVEL);
/*Enabling the Global Interrupt in the Interrupt Control Register (0x08)*/
STMPE812A_EnableGlobalInterrupt (TRUE);
/*Enabling the interrupt from the system related source of P1 to the host in the
Interrupt Enable Register (0x09)*/
STMPE812A_EnableInterrupt (STMPE812A_INT_P1, TRUE);
}
AN3301 Software
Doc ID 18161 Rev 1 29/35
B: Interrupt handling
void IRQHandler (void) {
if (GetITStatus (INTERRUPT_LINE)! = RESET)
{
/*Clearing the Interrupt pending bit from the Micro-controller*/
ClearITPendingBit (INTERRUPT_LINE);
/*Checking the Interrupt Pin Status goes low*/
while ((GPIO_INTERRUPT->IDR & GPIO_PIN_INTERRUPT) == 0)
{
/*Reading the Interrupt status register*/
STMPE812A_GetInterruptStatus (&Touch_Data [0]);
/*Checking the bit 3(P1 bit) value from Interrupt status register goes high*/
if ((Touch_Data [0] & 0x08) == 0x08)
{
/*Printing“GPIO Falling Edge is Detected” on the monitor screen*/
printf (“GPIO Falling Edge is Detected”);
}
}
}}
2.6.4 ADC initialization and interrupt handling
The following is an example for ADC initialization and interrupt servicing routine.
A: Initialization
void STMPE812A_ADC_Initialization (void) {
/*Enabling the Soft Reset in the System Control Register (0x03)*/
STMPE812A_SoftReset ();
/*Enabling the ADC and GPIO Clocks in the System Control Register (0x03)*/
STMPE812A_SetClock (STMPE812A_ENABLE, STMPE812A_ADC_CLK|STMPE812A_GPIO_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);
Software AN3301
30/35 Doc ID 18161 Rev 1
/*Setting the Port - 1 as an ADC Input in the Port Function Control Register (0x04)*/
STMPE812A_SetPortFunction (STMPE812A_PORT1, STMPE812A_PORT_FUNC_ADC_IP);
/*Setting the ADC_MODE [7] as 'One-shot capture', ADC_FREQ [5:4] as '15Ksamples/sec'
and ADC_PORT in the ADC Control Register (0x20) respectively*/
STMPE812A_SetADC (STMPE812A_ADC_1_SHOT_CAPTURE, STMPE812A_ADC_FREQ_15K,
STMPE812A_ADC_PORT);
/*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 ‘Level Interrupt Type’ in the Interrupt Control
Register (0x08)*/
STMPE812A_SetInterruptType (STMPE812A_INT_TYPE_LEVEL);
/*Enabling the Global Interrupt in the Interrupt Control Register (0x08)*/
STMPE812A_EnableGlobalInterrupt (TRUE);
/*Enabling the interrupt from the system related source of P1 to the host in the
Interrupt Enable Register (0x09)*/
STMPE812A_EnableInterrupt (STMPE812A_INT_P1, TRUE);
/*Starting the ADC Conversion (Initiate Data Acquisition by setting the bit [6]) in
the ADC Control Register (0x20)*/
STMPE812A_StartADC (TRUE);
}
Interrupt handling
void IRQHandler (void) {
if (GetITStatus (INTERRUPT_LINE)! = RESET)
{
/*Clearing the Interrupt pending bit from the Micro-controller*/
ClearITPendingBit (INTERRUPT_LINE);
/*Checking the Interrupt Pin Status goes low*/
while ((GPIO_INTERRUPT->IDR & GPIO_PIN_INTERRUPT) == 0)
{
/*Reading the Interrupt status register*/
STMPE812A_GetInterruptStatus (&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