STMPE610 Library
The STMPE610 is a GPIO (general purpose input/output) port expander able to interface a main digital ASIC via the two-line bidirectional bus (I2C). A 4-wire touchscreen controller is built into the STMPE610. The touchscreen controller is enhanced with a movement tracking algorithm to avoid excessive data, 128 x 32 bit buffer and a programmable active window feature. This library will focus on Touchscreen controlling part od the IC.

- STMPE610 library routines use I²C so it is necessary to initialize I²C module of the MCU before working with STMPE610 controller.
Library Routines
- STMPE610_WriteReg
- STMPE610_ReadReg
- STMPE610_ReadID
- STMPE610_IsOperational
- STMPE610_SetI2CAddress
- STMPE610_Reset
- STMPE610_Module
- STMPE610_AlternateFunction
- STMPE610_SetGPIOPin
- STMPE610_EnableInterrupt
- STMPE610_ConfigureInterrupt
- STMPE610_SetADC
- STMPE610_SetADCClock
- STMPE610_ConfigureTSC
- STMPE610_SetFIFOThreshold
- STMPE610_ResetFIFO
- STMPE610_ZDataFraction
- STMPE610_SetTouchPressureThreshold
- STMPE610_TSIDrive
- STMPE610_TSControl
- STMPE610_ClearInterrupts
- STMPE610_ClearInterruptFlagsAndFIFO
- STMPE610_SetSize
- STMPE610_GetRawXYZ
- STMPE610_GetXYZ
- STMPE610_PressDetect
- STMPE610_GetCoordinates
- STMPE610_GetLastCoordinates
- STMPE610_SetCalibrationConsts
- STMPE610_GetCalibrationConsts
- STMPE610_SetDefaultMode
- STMPE610_Rotate180
- STMPE610_CalibratePoint
STMPE610_WriteReg
Prototype |
char STMPE610_WriteReg(char RegisterAddr, char RegisterValue) ; |
---|---|
Description |
This function sets desired STMPE610 register (on RegisterAddr address) with given value (RegisterValue). |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Initialize the STMPE610_SYS_CTRL1_REG register with the value 0x02 STMPE610_WriteReg(STMPE610_SYS_CTRL1_REG, 0x02); |
Notes |
|
STMPE610_ReadReg
Prototype |
char STMPE610_ReadReg(char RegisterAddr); |
---|---|
Description |
This function reads desired STMPE610 register (on RegisterAddr address) and returns its value. |
Parameters |
|
Returns |
Value of the STMPE610 register at given address. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Initialize the STMPE610_SYS_CTRL1_REG register with the value 0x02 char temp; temp = STMPE610_WriteReg(STMPE610_SYS_CTRL1_REG, 0x02); |
Notes |
|
STMPE610_ReadID
Prototype |
unsigned int STMPE610_ReadID(); |
---|---|
Description |
This routine reads STMPE610 ID register, and returns its value. |
Parameters |
None. |
Returns |
If I²C, and STMPE610 modules have been properly initialized function should return correct ID nimber and that is 0x0811. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
unsigned int temp; temp = STMPE610_ReadID(); |
Notes |
|
STMPE610_IsOperational
Prototype |
char STMPE610_IsOperational(); |
---|---|
Description |
This routine checks if STMPE610 responds correctly via I²C communication. |
Parameters |
None. |
Returns |
STMPE610_OK if STMPE610 responds correctly, otherwise function returns STMPE610_FAILURE. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
if (STMPE610_IsOperational() == STMPE610_OK) { // STMPE610 initialized OK } else { // STMPE610 did not initialize OK } |
Notes |
|
STMPE610_SetI2CAddress
Prototype |
void STMPE610_SetI2CAddress(char DeviceAddr); |
---|---|
Description |
This procedure sets default addres which will be used fo all further commnunication with STMPE610 IC. |
Parameters |
|
Requires |
Adress set must be either 0x82 or 0x88, any other values will cause IC to not work properly. |
Example |
// Initialize the STMPE610 I2C communication address at 0x88 STMPE610_SetI2CAddress(STMPE610_I2C_ADDR1); |
Notes |
|
STMPE610_Reset
Prototype |
char STMPE610_Reset(); |
---|---|
Description |
This is a reset routine for STMPE610. |
Parameters |
None. |
Returns |
STMPE610_OK if STMPE610 responds correctly, otherwise function returns STMPE610_FAILURE. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_Reset(); |
Notes |
|
STMPE610_Module
Prototype |
unsigned char STMPE610_Module(char module_mask, char newState); |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Enable or Disable the various STMPE610 modules. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||
Example |
STMPE610_Module(STMPE610_MODULE_TS | STMPE610_MODULE_ADC, STMPE610_ENABLE); |
||||||||||||||||
Notes |
|
STMPE610_AlternateFunction
Prototype |
char STMPE610_AlternateFunction(char IO_Pin, char NewState); |
||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Sets weather STMPE610 GPIO pins will have alternate function(s) or not. |
||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||
Returns |
STMPE610_OK if STMPE610 responds correctly, otherwise function returns STMPE610_FAILURE. |
||||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||||
Example |
STMPE610_AlternateFunction(STMPE610_GPIO_PIN6 | STMPE610_GPIO_PIN4, _STMPE610_ENABLE); |
||||||||||||||||||||||||||
Notes |
|
STMPE610_SetGPIOPin
Prototype |
char STMPE610_SetGPIOPin(char IO_Pin, char BitVal); |
||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Sets or clears STMPE610 GPIO pin. |
||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||||
Requires |
MCU with at least one STMPE610 module. Used STMPE610 module must be initialized before using this function. See STMPE610x_Init and STMPE610x_Init_Advanced routines. |
||||||||||||||||||||||||||
Example |
STMPE610_SetGPIOPin(STMPE610_GPIO_PIN7 | STMPE610_GPIO_PIN6, 1); |
||||||||||||||||||||||||||
Notes |
|
STMPE610_EnableInterrupt
Prototype |
char STMPE610_EnableInterrupt(char interrupt_mask, char enable); |
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Enables/Disables different types of STMPE610 interrupt generation. |
||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||
Example |
STMPE610_EnableInterrupt(STMPE610_IE_ADC | STMPE610_IE_TOUCH_DET, STMPE610_ENABLE); | ||||||||||||||||||||||||
Notes |
|
STMPE610_ConfigureInterrupt
Prototype |
function STMPE610_ConfigureInterrupt(interrupt_mask : byte) : byte; |
||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Configure Interrupt Type. |
||||||||||||||
Parameters |
|
||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||
Example |
STMPE610_ConfigureInterrupt(STMPE610_INT_POLARITY_ACTIVE_HIGH or STMPE610_INT_TYPE_EDGE); | ||||||||||||||
Notes |
|
STMPE610_SetADC
Prototype |
char STMPE610_SetADC(char mode); |
||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Configure STMPE610 ADC module. |
||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||
Example |
STMPE610_SetADC(STMPE610_ADC_CTRL1_SAMPLETIME_56 | STMPE610_ADC_CTRL1_ADC_12BIT | STMPE610_ADC_CTRL1_INT_REFERENCE); | ||||||||||||||||||||||
Notes |
|
STMPE610_SetADCClock
Prototype |
char STMPE610_SetADCClock(char clock); |
||||||||
---|---|---|---|---|---|---|---|---|---|
Description |
Configure STMPE610 ADC clock. |
||||||||
Parameters |
|
||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||
Example |
STMPE610_SetADCClock(STMPE610_ADC_CTRL2_6500_kHZ); | ||||||||
Notes |
|
STMPE610_ConfigureTSC
Prototype |
char STMPE610_ConfigureTSC(char average_sample, char touch_detect_delay, char settling_time); |
||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Configure various parameters of STMPE610 module. |
||||||||||||||||||||||||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||||||||||||||||||||||||||
Example |
STMPE610_ConfigureTSC(STMPE610_TSC_CFG_AVE_CTRL_2S, STMPE610_TSC_CFG_TOUCH_DET_DELAY_500uS, STMPE610_TSC_CFG_TOUCH_DET_DELAY_500uS); | ||||||||||||||||||||||||||||||||||||||||||||||||
Notes |
|
STMPE610_SetFIFOThreshold
Prototype |
char STMPE610_SetFIFOThreshold(char point); |
---|---|
Description |
Configure threshold of STMPE610 FIFO register. |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
FIFO threshold value must be within 1-128 range. Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_SetFIFOThreshold(5); |
Notes |
|
STMPE610_ResetFIFO
Prototype |
char STMPE610_ResetFIFO(); |
---|---|
Description |
Procedure resets STMPE610 FIFO register. |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_ResetFIFO(); |
Notes |
|
STMPE610_ZDataFraction
Prototype |
function STMPE610_ZDataFraction(_value : byte) : byte; |
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
Procedure sets the range and accuracy of the STMPE610 pressure measurement. |
||||||||||||||||||
Parameters |
|
||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||
Example |
STMPE610_ZDataFraction(STMPE610_FRACP0_WHOLP8); | ||||||||||||||||||
Notes |
|
STMPE610_SetTouchPressureThreshold
Prototype |
void STMPE610_SetTouchPressureThreshold(char threshold); |
---|---|
Description |
Use this function to set desired touch panel pressure value. This value is compare with Z readout value, based on result touch is qualified as valid or invalid. If the Z value is lager then trashold value, press is invalid. (Z value decreases with increase of touch pressure) |
Parameters |
|
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Discard the press if Z value is grater then 45 STMPE610_SetTouchPressureThreshold(45); |
Notes |
|
STMPE610_TSIDrive
Prototype |
char STMPE610_TSIDrive(char _drive); |
||||||
---|---|---|---|---|---|---|---|
Description |
This function sets the current limit value of the STMPE610 touchscreen drivers. |
||||||
Parameters |
|
||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||
Example |
STMPE610_TSIDrive(STMPE610_TSC_I_DRIVE_50mA); | ||||||
Notes |
|
STMPE610_TSControl
Prototype |
char STMPE610_TSControl(char _ctrl); |
||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function sets tracking index, and value ADC acquisition of STMPE610. |
||||||||||||||||||||||||||||
Parameters |
|
||||||||||||||||||||||||||||
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
||||||||||||||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||||||||||||||
Example |
STMPE610_TSControl(STMPE610_TSC_CTRL_TRACK4 | STMPE610_TSC_CTRL_ACQU_XYZ); | ||||||||||||||||||||||||||||
Notes |
|
STMPE610_ClearInterrupts
Prototype |
char STMPE610_ClearInterrupts(); |
---|---|
Description |
Procedure clears all STMPE610 interrupts. |
Parameters |
|
Returns |
STMPE610_OK: if all operations are OK. Other value if error. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_ClearInterrupts(); |
Notes |
|
STMPE610_ClearInterruptFlagsAndFIFO
Prototype |
void STMPE610_ClearInterruptFlagsAndFIFO(); |
---|---|
Description |
Procedure clears all STMPE610 interrupt flags and resets FIFO register. |
Parameters |
|
Returns |
Nothing. |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_ClearInterruptFlagsAndFIFO(); |
Notes |
|
STMPE610_SetSize
Prototype |
char STMPE610_SetSize(unsigned int display_width, unsigned int display_height); |
---|---|
Description |
This function sets touch screen size in pixels. |
Parameters |
|
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
STMPE610_SetSize(480, 272); |
Notes |
|
STMPE610_GetRawXYZ
Prototype |
char STMPE610_GetRawXYZ(unsigned int *x_data, unsigned int *y_data, unsigned short *z_data); |
---|---|
Description |
Function reads raw(ADC values) Touch panel values from FIFO(first in FIFO, last touched) for X, Y, and Z. |
Parameters |
|
Returns |
STMPE610_OK if reading goes OK STMPE610_FAILURE if there are no data sets to be read.(FIFO empty) |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Read raw Touch panel (ADC conversion) values (X, Y, and Z) STMPE610_GetRawXYZ(&adc_x, &adc_y, &adc_z ); |
Notes |
|
STMPE610_GetXYZ
Prototype |
void STMPE610_GetXYZ(unsigned int *x_data, unsigned int *y_data, unsigned short *z_data); |
---|---|
Description |
Function reads Touch panel coordinate(pixel) from FIFO(first in FIFO, last touched), for X, Y, and Z |
Parameters |
|
Returns |
STMPE610_OK if reading goes OK STMPE610_FAILURE if there are no data sets to be read.(FIFO empty) |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Read raw Touch panel coordinates(pixel) (X, Y, and Z) STMPE610_GetXYZ(&x_px, &y_px, &z_px); |
Notes |
|
STMPE610_PressDetect
Prototype |
char STMPE610_PressDetect(); |
---|---|
Description |
This function detects it touch panel has been pressed and also returns pendown value. |
Parameters |
|
Returns |
One: if touchscreen has been pressed. Zero: if touchscreen hasn't been pressed. Additionaly, function returns value of PenDown (detects changes on touchscreen, PressDown or PressUp). |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
if (STMPE610_PressDetect()) { ... |
Notes |
|
STMPE610_GetCoordinates
Prototype |
char STMPE610_GetCoordinates(unsigned int *x_coordinate, unsigned int *y_coordinate); |
---|---|
Description |
This function returns coordinates(in pixels) where touchscreen has been pressed. |
Parameters |
|
Returns |
0x00 : if returned values are correct |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
if (STMPE610_GetCoordinates(&Xcoord, &Ycoord) == 0) { ... |
Notes |
|
STMPE610_GetLastCoordinates
Prototype |
char STMPE610_GetLastCoordinates(unsigned int *x_coordinate, unsigned int *y_coordinate); |
---|---|
Description |
Returns last display coordinates (from FIFO register) where touch panel has been pressed. |
Parameters |
|
Returns |
0x00 : if returned values are correct |
Requires |
Properly initialized I²C, and STMPE610 module. |
Example |
// Get last valid value from FIFO STMPE610_GetLastCoordinates(&x_c, &y_c); |
Notes |
|
STMPE610_SetCalibrationConsts
Prototype |
void STMPE610_SetCalibrationConsts(TTPConstants *TPConstsStruct); |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function sets calibration constants and orientation by structure defined parameters. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||
Example |
TTPConstants TPConstsStruct; TPConstsStruct.X_Max = 3898; TPConstsStruct.X_Min = 137; TPConstsStruct.Y_Max = 3828; TPConstsStruct.Y_Min = 362; TPConstsStruct.Rotate = 0; TSC_set_Calib_Consts(&TPConstsStruct); | ||||||||||||||||
Notes |
|
STMPE610_GetCalibrationConsts
Prototype |
void STMPE610_GetCalibrationConsts(TTPConstants *TPConstsStruct); |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function returns calibration constants and orientation to structure previously defined. |
||||||||||||||||
Parameters |
|
||||||||||||||||
Requires |
Properly initialized I²C, and STMPE610 module. |
||||||||||||||||
Example |
TTPConstants TPConstsStruct; STMPE610_GetCalibrationConsts(&TPConstsStruct); | ||||||||||||||||
Notes |
|
STMPE610_SetDefaultMode
Prototype |
void STMPE610_SetDefaultMode(); |
---|---|
Description |
Procedure sets default STMPE610 touchscreen values neccesary for normal operation. |
Parameters |
|
Requires |
None. |
Example |
STMPE610_SetDefaultMode(); |
Notes |
|
STMPE610_Rotate180
Prototype |
void STMPE610_Rotate180(char rotate); |
||||||
---|---|---|---|---|---|---|---|
Description |
This function rotates touchscreen by 180 degrees. |
||||||
Parameters |
|
||||||
Requires |
None. |
||||||
Example |
STMPE610_Rotate180(STMPE610_ROTATE_180); | ||||||
Notes |
|
STMPE610_CalibratePoint
Prototype |
void STMPE610_CalibratePoint(_point : byte); |
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Description |
This function calibrates touchscreen. |
||||||||||
Parameters |
|
||||||||||
Requires |
None. |
||||||||||
Example |
STMPE610_CalibratePoint(_STMPE610_FIRST_CORNER); | ||||||||||
Notes |
|
What do you think about this topic ? Send us feedback!