Touch prints same coordinate, the maximum value

STM32F103RCT6 (RAM 48 KB, custom board)
display: 128*160, RGB565(16 bit), ST7735/ST7789 lcd driver, SPI comm.
IDE: STM32CubeIDE
touch driver: xpt2046

What LVGL version are you using?

the latest one (v8.0)

What do you want to achieve?

When I touch the screen, I get the maximum coordinate value, especially (255, 255), the uint8_t maximum value.
I repeated it and calculated average, the data overflow happened.
I just touched screen, I’m not sure what the problem is.

What have you tried so far?

Code to reproduce

main function

void App_Start(void)
{
// lcd init
			lv_init();
			LCD_Init();
			HAL_Delay(5);

// function for setting lcd and touch configuration
			lv_disp_config();
			lv_touch_config();

// put button example function 
            lv_example_btn_1();
}

indev setting

void lv_touch_config(void)
{
	static lv_indev_drv_t indev_drv;
	lv_indev_drv_init(&indev_drv);		// basic initialization
	indev_drv.type = LV_INDEV_TYPE_POINTER;

	static lv_indev_data_t* data;
	my_input_read(&indev_drv, &data);
	indev_drv.read_cb = my_input_read;
	lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);
}

my_input_read()

bool my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
	static int8_t lastX = 0;
	static int8_t lastY = 0;
// check the touch interrupt occurs
	if(XPT2046_TouchPressed())
	{
		XPT2046_TouchGetCoordinates(&lastX, &lastY);
		data->state = LV_INDEV_STATE_PRESSED;
	}
	else
	{
		data->point.x = lastX;
		data->point.y = lastY;
		data->state = LV_INDEV_STATE_RELEASED;
	}
	return false;
}

get coordinate function

I deleted the real code for getting coordinates, because the touched data is incorrect.
I just put the code that check if the touch signal exists or not.

#define READ_X 0xD0
#define READ_Y 0x90

    static const uint8_t cmd_read_x[] = { READ_X };
    static const uint8_t cmd_read_y[] = { READ_Y };
    static const uint8_t zeroes_tx[] = { 0x00, 0x00 };

bool XPT2046_TouchGetCoordinates(uint16_t* x, uint16_t* y)
{
// chip selection reset function
    XPT2046_TouchSelect();

      	    HAL_SPI_Transmit(&hspi1, (uint8_t*)cmd_read_y, sizeof(cmd_read_y), HAL_MAX_DELAY);
	        uint8_t y_raw[2];
	        HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)zeroes_tx, y_raw, sizeof(y_raw), HAL_MAX_DELAY);
	        HAL_Delay(1);
	        HAL_SPI_Transmit(&hspi1, (uint8_t*)cmd_read_x, sizeof(cmd_read_x), HAL_MAX_DELAY);
	        uint8_t x_raw[2];
	        HAL_SPI_TransmitReceive(&hspi1, (uint8_t*)zeroes_tx, x_raw, sizeof(x_raw), HAL_MAX_DELAY);
	        HAL_Delay(1);
    }

    XPT2046_TouchUnselect();
		data->state = LV_INDEV_STATE_PRESSED;

	else
	{
		data->point.x = lastX;
		data->point.y = lastY;
		data->state = LV_INDEV_STATE_RELEASED;
		//printf("released\r");
	}
}

Screenshot and/or video

my spi comm setting
123 1234
[/quote]

Hmmm,

what does it mean, ‘the data overflow happened’?

Also your code example with XPT2046_TouchGetCoordinates seems to be a little mixed up

Hmm, hard to find some good example, but I found this one: https://github.com/magore/esp8266_ili9341/blob/master/xpt2046/xpt2046.c (and https://github.com/magore/esp8266_ili9341/blob/master/xpt2046/xpt2046.h)
The commands (for reading x and y) look a little different than yours (see the include file).
And it is reading three 8-bit values and ignoring the first 8-bit value.

I’ve solved the problem,
When I use a function that performs transmit and receive together, it seems that the data is twisted somewhere.
After sending the command to the buffer, the data was received again in that place, and the data was written again in the two buffer places, and the coordinates were output.

uint16_t XPT2046_read(uint8_t cmd)
{
	uint8_t buf[3];

	buf[0] = cmd;
	buf[1] = 0;
	buf[2] = 0;

	XPT2046_TouchSelect();
	HAL_SPI_TransmitReceive(&hspi1, &cmd, buf, 3, 10000);
	HAL_Delay(100);
	XPT2046_TouchUnselect();

	val = buf[0];
	val <<8;
	HAL_Delay(100);
	val |= buf[1];

	if(val<0)
	{
		val = 0;
	}
	if(val >4095)
	{
		val = 4095;
	}

	return (val);
}