Reading pixel with CFAF240320E-T/ILI325 displays

ktownsend

New member
It's easy enough to write data to this display thanks to the example code provided, but none of the examples I've seen show how to read data back. I need to be able to determine pixel color for alpha blending, but haven't had any luck reading the GRAM register to get the color. As far as I understand, I need to set the pixel location 'easy enough', make a dummy read, and then read the two 8 bit chunks, but despite trying a number of combinations I'm yet to get any coherent data back.

I've searched high and low on google, but most examples seems to be write-only. Has anyone here figured out the secret formula to get a pixel back? This is my current (hopeless) attempt:

/*************************************************/
uint16_t lcdGetPixel(uint16_t x, uint16_t y)
{
ili9325SetCursor(x, y);
return (ili9325Read());
}

/*************************************************/
uint16_t ili9325Read(void)
{
uint8_t argh, argl;

CLR_CS;
SET_CD;
// set GPIO pins to input
ILI9325_GPIO2DATA_SETINPUT;
CLR_RD;
ili9325Delay(50);
// Dummy read
argl = GPIO_GPIO2DATA >> ILI9325_DATA_OFFSET;
SET_RD;
ili9325Delay(50);
// low byte
argl = GPIO_GPIO2DATA >> ILI9325_DATA_OFFSET;
SET_RD;
ili9325Delay(50);
CLR_RD;
ili9325Delay(50);
// high byte
argh = GPIO_GPIO2DATA >> ILI9325_DATA_OFFSET;
SET_RD;
// Set GPIO pins back to output
ILI9325_GPIO2DATA_SETOUTPUT;
SET_CS;
return argh << 8 | argl;
}

It would definately be helpful to see this added to the examples since one-way communication definately limits you in how much you can take advantage of the LCDs.
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
I see one fatal mistake in your code that would prevent the read function from working:
Code:
/*************************************************/
uint16_t ili9325Read(void)
{
	uint8_t argh, argl;

	CLR_CS;
	SET_CD;
	ILI9325_GPIO2DATA_SETINPUT;  // set GPIO pins to input

	CLR_RD;
	ili9325Delay(5);
	[COLOR="Green"][B]// Dummy read, strobe only, inputting data not required[/B][/COLOR]
	SET_RD;

	[COLOR="Green"][B]ili9325Delay(5);  // you should have a delay here, too[/B][/COLOR]

	[COLOR="Red"][B]CLR_RD;	// you are missing this statement!![/B][/COLOR]
	ili9325Delay(5);
	argl = GPIO_GPIO2DATA >> ILI9325_DATA_OFFSET;  // low byte
	SET_RD;

	ili9325Delay(5);

	CLR_RD;
	ili9325Delay(5);
	argh = GPIO_GPIO2DATA >> ILI9325_DATA_OFFSET;  // high byte
	SET_RD;

	[COLOR="Green"][B]ili9325Delay(5);  // you should have a delay here, too[/B][/COLOR]

	ILI9325_GPIO2DATA_SETOUTPUT;  // Set GPIO pins back to output
	SET_CS;
	return argh << 8 | argl;
}
I don't know what units of time your delays are, but the read width is only 150 nS, and the read after delay is 100 nS (that's why the delay after the read strobe goes high).

You can search the forums for some of my sample code. I haven't used this particular display, but the CFAF320240 code and the CFAF240400 code samples both have the read function implimented. The controller chip is not the same, but the general procedure is similar.

P.S. using code tags will make your code easier to read, as it preserves tabs and spacing. It is the '#' button on the compose window toolbar; or just manually insert "["code"]" and "["/code"]" without the quotes.
 
Top