XPT2046 touch screen experimental process detailed and STM32 code analysis

1.XPT2046 initialization

XPT2046 is actually an AD converter, so it is suitable for initialization settings, and the specific initialization is actually the initialization of the microcontroller IO and the initialization of the SPI.

This time STM32 is operated using SPI1. The SPI settings have already been mentioned in the previous lessons. I will not repeat them here. The specific code for initialization is as follows:

/************************************************* *********************

*FuncTIonName:TOUCH_Init

*DescripTIon: Initialize the touch screen

*Input:None

*Output:None

*Return:None

************************************************** ********************/

voidTOUCH_Init(void)

{

GPIO_InitTypeDefGPIO_InitStructure;

/*SPI IO port and SPI peripheral open clock */RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOD, ENABLE);

/*TOUCH-CS IO port setting */GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_Init(GPIOD, &GPIO_InitStructure);

/*TOUCH-PEN IO port setting */GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;

GPIO_Init(GPIOD, & GPIO_InitStructure); SPI1_Config();

/* To use FLASH to store calibration parameters, so be careful to initialize */ before

/*Check if there is correction parameter*/

FLASH_ReadData(&TouchAdj.posState, TOUCH_ADJ_ADDR, sizeof(TouchAdj));

If(TouchAdj.posState!=TOUCH_ADJ_OK)

{

TOUCH_Adjust();//correction

}

}

In this function, the initialization function of SPI1 is called, and the calibration procedure of the touch screen is shown below.

Initialization procedures, correction principles we will talk about later.

/************************************************* *********************

*FuncTIonName: SPI1_Config

*DescripTIon: Initialize SPI2

*Input:None

*Output:None

*Return:None

************************************************** *******************/

voidSPI1_Config(void)

{

GPIO_InitTypeDefGPIO_InitStructure; SPI_InitTypeDefSPI_InitStructure;

/*SPI IO port and SPI peripheral open clock */RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd (RCC_APB2Periph_SPI1, ENABLE);

/*SPI IO port setting*/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_SetBits(GPIOA, GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7); // PA5.6.7 pull-up

/************************************************* *******************/

/*******************Set SPI parameters ************************** *********/

/************************************************* ******************** / SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // select full duplex mode SPI

SPI_InitStructure.SPI_Mode=SPI_Mode_Master;//Host mode SPI_InitStructure.SPI_DataSize=SPI_DataSize_8b; //8-bit SPISPI_InitStructure.SPI_CPOL=SPI_CPOL_High; // Clock floating high SPI_InitStructure.SPI_CPHA=SPI_CPHA_2Edge; // Collect data SPI_InitStructure on the second clock. SPI_NSS=SPI_NSS_Soft;//Nss uses software control

/*Select the baud rate prescaler to 256*/

SPI_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_256; SPI_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB;//Transfer from the highest bit

SPI_InitStructure.SPI_CRCPolynomial=7;

SPI_Cmd (SPI1, ENABLE); SPI_Init (SPI1, & SPI_InitStructure);

}

Programming Laptop

There is a rule, custom laptop is called programming laptop cause nearly 90% is used for projects. 15.6 inch laptop for coding and programming is usually equipped with 10th or 11th cpu, 2gb or 4gb graphics optional. 15 inch laptop untuk programming is used on big tender or group for a special jobs. 15.6 inch programming laptop under 30000 is a more competitive one for business or high school students or teachers.

However, here is the recommended laptop for programming, especially for heavy office jobs or university coursework, since double heat-releasing, metal body, bigger battery, FHD screen, high-level cpu, etc. Build the deep and stable foundation to enjoy smooth running experience. Your clients will satisfy it`s excellent performance. Of course, there are other lower specification with tight budget.

As a entry windows laptop for programming, this 14 inch celeron Education Laptop is the most competitive and hottest device for elementary project.

Any other special requirements, just contact us freely.

Programming Laptop,Laptop For Coding And Programming,Programming Laptop Under 30000,Recommended Laptop For Programming,Windows Laptop For Programming

Henan Shuyi Electronics Co., Ltd. , https://www.shuyielectronics.com