User avatar
okin
Posts: 4
Joined: Sat Feb 16, 2013 9:47 pm
Location: Austria

HY28A-LCDB, ili9320 (working)

Sat Feb 16, 2013 9:58 pm

Hi,
I've recently bought a 2.8" spi tft on ebay and tried to access it with the raspberry pi using the bcm2835 spi library.
http://www.ebay.at/itm/2-8-inch-320x240 ... 789wt_1188

unfortunately I am not able to receive the ID from the display.

Here is my code

Code: Select all

/**
 *
 *
 *  // gcc -o spi  -l rt main.c -l bcm2835
 *	// sudo ./main
 *
**/



#include <bcm2835.h>
#include <stdio.h>
//#include "GLCD.h"
//#include "TouchPanel.h"

#define MAX_X  240
#define MAX_Y  320   

#define SPI_START   (0x70)              /* Start byte for SPI transfer        */
#define SPI_RD      (0x01)              /* WR bit 1 within start              */
#define SPI_WR      (0x00)              /* WR bit 0 within start              */
#define SPI_DATA    (0x02)              /* RS bit 1 within start byte         */
#define SPI_INDEX   (0x00)              /* RS bit 0 within start byte         */

/* LCD color */
#define White          0xFFFF
#define Black          0x0000
#define Grey           0xF7DE
#define Blue           0x001F
#define Blue2          0x051F
#define Red            0xF800
#define Magenta        0xF81F
#define Green          0x07E0
#define Cyan           0x7FFF
#define Yellow         0xFFE0

#define RESET RPI_GPIO_P1_22 //GPIO25
#define BACKLIGHT RPI_GPIO_P1_12 //GPIO18

unsigned char LPC17xx_SPI_SendRecvByte (unsigned char);
void LCD_Initializtion(void);
void LCD_WriteReg( unsigned short , unsigned short);
void LCD_WriteIndex(unsigned char);
void LCD_WriteData( unsigned short);
unsigned char LPC17xx_SPI_SendRecvByte (unsigned char);
static void LCD_Configuration(void);
void LCD_SetPoint( unsigned short, unsigned short, unsigned short);
void TP_DrawPoint(unsigned int ,unsigned int);
unsigned short LCD_ReadReg( unsigned short );
unsigned short LCD_ReadData(void);
static void LCD_SetCursor( unsigned short , unsigned short  );

int main(void)
{
	if (!bcm2835_init())
		return 1;

	// Set the RESET pin to be an output
    bcm2835_gpio_fsel(RESET, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_write(RESET, HIGH);	//reset is low active
	bcm2835_gpio_fsel(BACKLIGHT, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_write(BACKLIGHT, HIGH);	//HIGH=on, LOW = off;
	
	bcm2835_spi_begin();
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // MODE1
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // The default     BCM2835_SPI_CLOCK_DIVIDER_  4096
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default
	// Send a some bytes to the slave and simultaneously read 
    // some bytes back from the slave
    // Most SPI devices expect one or 2 bytes of command, after which they will send back
    // some data. In such a case you will have the command bytes first in the buffer,
    // followed by as many 0 bytes as you expect returned data bytes. After the transfer, you 
    // Can the read the reply bytes from the buffer.
    // If you tie MISO to MOSI, you should read back what was sent.
	//char buf[] = { 0x01, 0x02, 0x11, 0x33 }; // Data to send
    //bcm2835_spi_transfern(buf, sizeof(buf));
    // buf will now be filled with the data that was read from the slave
    //printf("Read from SPI: %02X  %02X  %02X  %02X \n", buf[0], buf[1], buf[2], buf[3]);
    
    //bcm2835_spi_end();
    //bcm2835_close();
    //return 0;



	//TP_Init(); 
	LCD_Initializtion();	
	//TouchPanel_Calibrate();
	/* Infinite loop */
	//while (1)	
	{
		//getDisplayPoint(&display, Read_Ads7846(), &matrix ) ;
		//TP_DrawPoint(display.x,display.y);
		printf("TP_DrawPoint\n");
		TP_DrawPoint(22,33);
		printf("END:TP_DrawPoint\n");
		//TP_DrawPoint(100,56);
		//TP_DrawPoint(100,57);
		//TP_DrawPoint(100,58);
		//TP_DrawPoint(100,59);
		//TP_DrawPoint(100,60);
	}
	
	return 0;

}


/*******************************************************************************
* Function Name  : LCD_Initializtion
* Description    : Initialize TFT Controller.
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void LCD_Initializtion(void)
{
	unsigned short DeviceCode;
	
	//LCD_Configuration();
	DeviceCode = LCD_ReadReg(0x0000);		/* Read ID	*/	
	/* Different driver IC initialization*/
	if( DeviceCode == 0x9320 || DeviceCode == 0x9300 )
	{
		printf("DeviceCode: \n");
		printf("%hu", DeviceCode);
		printf("\n");
	}	
	else
	{
		printf("other Code!\n");
		printf("%hu", DeviceCode);
		printf("\n");
	}
		LCD_WriteReg(0x00,0x0000);
		LCD_WriteReg(0x01,0x0100); /* Driver Output Contral */
		LCD_WriteReg(0x02,0x0700); /* LCD Driver Waveform Contral */
		LCD_WriteReg(0x03,0x1038); /* Set the scan mode */
		LCD_WriteReg(0x04,0x0000); /* Scalling Contral */
		LCD_WriteReg(0x08,0x0202); /* Display Contral 2 */
		LCD_WriteReg(0x09,0x0000); /* Display Contral 3 */
		LCD_WriteReg(0x0a,0x0000); /* Frame Cycle Contal */
		LCD_WriteReg(0x0c,(1<<0)); /* Extern Display Interface Contral 1 */
		LCD_WriteReg(0x0d,0x0000); /* Frame Maker Position */
		LCD_WriteReg(0x0f,0x0000); /* Extern Display Interface Contral 2 */     
		delay(50); 
		LCD_WriteReg(0x07,0x0101); /* Display Contral */
		delay(50);    
		LCD_WriteReg(0x10,(1<<12)|(0<<8)|(1<<7)|(1<<6)|(0<<4)); /* Power Control 1 */
		LCD_WriteReg(0x11,0x0007);                              /* Power Control 2 */
		LCD_WriteReg(0x12,(1<<8)|(1<<4)|(0<<0));                /* Power Control 3 */
		LCD_WriteReg(0x13,0x0b00);                              /* Power Control 4 */
		LCD_WriteReg(0x29,0x0000);                              /* Power Control 7 */
		LCD_WriteReg(0x2b,(1<<14)|(1<<4)); 
	
		LCD_WriteReg(0x50,0);       /* Set X Start */
		LCD_WriteReg(0x51,239);	    /* Set X End */
		LCD_WriteReg(0x52,0);	    /* Set Y Start */
		LCD_WriteReg(0x53,319);	    /* Set Y End */
		delay(50);

		LCD_WriteReg(0x60,0x2700); /* Driver Output Control */
		LCD_WriteReg(0x61,0x0001); /* Driver Output Control */
		LCD_WriteReg(0x6a,0x0000); /* Vertical Srcoll Control */
		
		LCD_WriteReg(0x80,0x0000); /* Display Position? Partial Display 1 */
		LCD_WriteReg(0x81,0x0000); /* RAM Address Start? Partial Display 1 */
		LCD_WriteReg(0x82,0x0000); /* RAM Address End-Partial Display 1 */
		LCD_WriteReg(0x83,0x0000); /* Displsy Position? Partial Display 2 */
		LCD_WriteReg(0x84,0x0000); /* RAM Address Start? Partial Display 2 */
		LCD_WriteReg(0x85,0x0000); /* RAM Address End? Partial Display 2 */
		
		LCD_WriteReg(0x90,(0<<7)|(16<<0)); /* Frame Cycle Contral */
		LCD_WriteReg(0x92,0x0000);         /* Panel Interface Contral 2 */
		LCD_WriteReg(0x93,0x0001);         /* Panel Interface Contral 3 */
		LCD_WriteReg(0x95,0x0110);         /* Frame Cycle Contral */
		LCD_WriteReg(0x97,(0<<8)); 
		LCD_WriteReg(0x98,0x0000);         /* Frame Cycle Contral */    
		LCD_WriteReg(0x07,0x0133); 

    delay(100);   /* delay 50 ms */		
}

/*******************************************************************************
* Function Name  : Lcd_Configuration
* Description    : Configures LCD Control lines
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
static void LCD_Configuration(void)
{
 	//PINSEL_CFG_Type PinCfg;
    //SSP_CFG_Type SSP_ConfigStruct;
	/*
	 * Initialize SPI pin connect
	 * P0.15 - LCD_CSB - used as GPIO
	 * P0.16 - LCD_SCK
	 * P0.17 - LCD_MISO
	 * P0.18 - LCD_MOSI
	 */
	//PinCfg.Funcnum = 2;
	//PinCfg.OpenDrain = 0;
	//PinCfg.Pinmode = 0;
	//PinCfg.Portnum = 0;
	//PinCfg.Pinnum = 15;
	//PINSEL_ConfigPin(&PinCfg);
	//PinCfg.Pinnum = 17;
	//PINSEL_ConfigPin(&PinCfg);
	//PinCfg.Pinnum = 18;
	//PINSEL_ConfigPin(&PinCfg);

	//PinCfg.Funcnum = 0;
	//PinCfg.Portnum = 0;
	//PinCfg.Pinnum = 16;
	//PINSEL_ConfigPin(&PinCfg);

    /* P1.31 LCD_CSB is output */	 
    //GPIO_SetDir(CSB_PORT_NUM, ( (uint32_t) 1 << CSB_PIN_NUM ), 1);
	//GPIO_SetValue(CSB_PORT_NUM, ( (uint32_t) 1 << CSB_PIN_NUM ) );  

	/* initialize SSP configuration structure to default */
	//SSP_ConfigStructInit(&SSP_ConfigStruct);

	//SSP_ConfigStruct.CPHA = SSP_CPHA_SECOND;
	//SSP_ConfigStruct.CPOL = SSP_CPOL_LO;
	//SSP_ConfigStruct.ClockRate = 25000000;

	/* Initialize SSP peripheral with parameter given in structure above */
	//SSP_Init(LPC_SSP0, &SSP_ConfigStruct);
	/* Enable SSP peripheral */
	//SSP_Cmd(LPC_SSP0, ENABLE);
}


/*******************************************************************************
* Function Name  : LCD_WriteReg
* Description    : Writes to the selected LCD register.
* Input          : - LCD_Reg: address of the selected register.
*                  - LCD_RegValue: value to write to the selected register.
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void LCD_WriteReg( unsigned short LCD_Reg, unsigned short LCD_RegValue)
{
	//printf("LCD_WriteReg: ");
	/* Write 16-bit Index, then Write Reg */  
	LCD_WriteIndex(LCD_Reg);         
	/* Write 16-bit Reg */
	LCD_WriteData(LCD_RegValue);  
	//printf("end_LCD_WriteReg;\n");
}

/*******************************************************************************
* Function Name  : LCD_WriteIndex
* Description    : LCD write register address
* Input          : - index: register address
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void LCD_WriteIndex(unsigned char index)
{
	//SPI_CS_LOW;
	//bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    //bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default

        /* SPI write data */
	// LPC17xx_SPI_SendRecvByte(SPI_START | SPI_WR | SPI_INDEX);   /* Write : RS = 0, RW = 0       */
	// LPC17xx_SPI_SendRecvByte(0);
	// LPC17xx_SPI_SendRecvByte(index);
	
	char tbuf[] = { SPI_START | SPI_WR | SPI_INDEX, 0, index}; // Data to send
	char rbuf[] = {0,0,0};
	bcm2835_spi_transfernb(tbuf, rbuf, sizeof(tbuf));
	printf("SPI: WriteIndex: %02X  %02X  %02X \n", rbuf[0], rbuf[1], rbuf[2]);

	//SPI_CS_HIGH; 
	//bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
 //   bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, HIGH);      // the default
}

/*******************************************************************************
* Function Name  : LCD_WriteData
* Description    : LCD write register data
* Input          : - data: register data
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void LCD_WriteData( unsigned short data)
{
	//SPI_CS_LOW;
	//bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    //bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default

	//LPC17xx_SPI_SendRecvByte(SPI_START | SPI_WR | SPI_DATA);    /* Write : RS = 1, RW = 0       */
	//LPC17xx_SPI_SendRecvByte((data >>   8));                    /* Write D8..D15                */
	//LPC17xx_SPI_SendRecvByte((data & 0xFF));                    /* Write D0..D7                 */

	char tbuf[] = { SPI_START | SPI_WR | SPI_DATA, (data >>   8), (data & 0xFF)}; // Data to send
	char rbuf[] = {0,0,0};
	bcm2835_spi_transfernb(tbuf, rbuf, sizeof(tbuf));
	printf("SPI: WriteData: %02X  %02X  %02X \n", rbuf[0], rbuf[1], rbuf[2]);
	
	//SPI_CS_HIGH; 
	//bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
//    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, HIGH);      // the default
}

/*******************************************************************************
* Function Name  : LPC17xx_SPI_SendRecvByte
* Description    : Send one byte then recv one byte of response
* Input          : - byte_s: byte_s
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
// unsigned char LPC17xx_SPI_SendRecvByte (unsigned char byte_s)
// {
		// /* wait for current SSP activity complete */
		// //while (SSP_GetStatus(LPC_SSP0, SSP_STAT_BUSY) ==  SET);

		// //SSP_SendData(LPC_SSP0, (unsigned short) byte_s);
	// // Send a byte to the slave and simultaneously read a byte back from the slave
    // // If you tie MISO to MOSI, you should read back what was sent
    // uint8_t data = bcm2835_spi_transfer(byte_s); //0x23
    // printf("Read from SPI: %02X\n", data);

		// //while (SSP_GetStatus(LPC_SSP0, SSP_STAT_RXFIFO_NOTEMPTY) == RESET);
		// //return (SSP_ReceiveData(LPC_SSP0));
	// return data;
// }

/******************************************************************************
* Function Name  : LCD_SetPoint
* Description    : Drawn at a specified point coordinates
* Input          : - Xpos: Row Coordinate
*                  - Ypos: Line Coordinate 
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void LCD_SetPoint( unsigned short Xpos, unsigned short Ypos, unsigned short point)
{
	if( Xpos >= MAX_X || Ypos >= MAX_Y )
	{
		return;
	}
	//printf("SetPoint");
	LCD_SetCursor(Xpos,Ypos);
	LCD_WriteReg(0x0022,point);	// (REG, VALUE)
	//printf("end_SetPoint\n");
}

/*******************************************************************************
* Function Name  : TP_DrawPoint
* Description    : Draw point Must have a LCD driver
* Input          : - Xpos: Row Coordinate
*                  - Ypos: Line Coordinate 
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void TP_DrawPoint(unsigned int Xpos,unsigned int Ypos)
{
  LCD_SetPoint(Xpos,Ypos,0xf800);     /* Center point */
  LCD_SetPoint(Xpos+1,Ypos,0xf800);
  LCD_SetPoint(Xpos,Ypos+1,0xf800);
  LCD_SetPoint(Xpos+1,Ypos+1,0xf800);	
}

/*******************************************************************************
* Function Name  : LCD_ReadReg
* Description    : Reads the selected LCD Register.
* Input          : None
* Output         : None
* Return         : LCD Register Value.
* Attention		 : None
*******************************************************************************/
unsigned short LCD_ReadReg( unsigned short LCD_Reg)
{
	unsigned short LCD_RAM;
	
	/* Write 16-bit Index (then Read Reg) */
	LCD_WriteIndex(LCD_Reg);
	/* Read 16-bit Reg */
	LCD_RAM = LCD_ReadData();
    	
	return LCD_RAM;
}

/*******************************************************************************
* Function Name  : LCD_ReadData
* Description    : LCD read data
* Input          : None
* Output         : None
* Return         : return data
* Attention	 : None
*******************************************************************************/
unsigned short LCD_ReadData(void)
{ 
	unsigned short value;

	//SPI_CS_LOW;
	//bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    //bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default

	// LPC17xx_SPI_SendRecvByte(SPI_START | SPI_RD | SPI_DATA);    /* Read: RS = 1, RW = 1         */
	// LPC17xx_SPI_SendRecvByte(0);                                /* Dummy read 1                 */
	// value   = LPC17xx_SPI_SendRecvByte(0);                      /* Read D8..D15                 */
	// value <<= 8;
	// value  |= LPC17xx_SPI_SendRecvByte(0);                      /* Read D0..D7                  */

	char tbuf[] = { SPI_START | SPI_RD | SPI_DATA, 0, 0,0}; // Data to send
	char rbuf[] = {0,0,0,0};
	bcm2835_spi_transfernb(tbuf, rbuf, sizeof(tbuf));
	value = (short int)rbuf[3] + (short int)rbuf[2]<<8;
	
	printf("SPI: ReadData: %02X  %02X  %02X  %02X \n", rbuf[0], rbuf[1], rbuf[2], rbuf[3]);
	//SPI_CS_HIGH; 
	//bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
 //   bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, HIGH);      // the default
	
	return value;
}

/*******************************************************************************
* Function Name  : LCD_SetCursor
* Description    : Sets the cursor position.
* Input          : - Xpos: specifies the X position.
*                  - Ypos: specifies the Y position. 
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
static void LCD_SetCursor( unsigned short Xpos, unsigned short Ypos )
{
	/* 0x9320 */
	//printf("SetCursor");
	LCD_WriteReg(0x0020, Xpos );     
	LCD_WriteReg(0x0021, Ypos );    
	//printf("end_SetCursor");	
}

Here I always receive 0 as answer ID. Is there anyone who has an idea of what is going wrong?
cheers

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Sun Feb 17, 2013 1:49 pm

How have you wired it up?

User avatar
okin
Posts: 4
Joined: Sat Feb 16, 2013 9:47 pm
Location: Austria

Re: HY28A-LCDB, ili9320

Sun Feb 17, 2013 6:46 pm

Hi notro,

My wiring is:
Display 3V3 powered (pin20)

Display - RaspberryPi
P1 - NC
P2 - GND (P1-25)
P3 - GPIO11
P4 - CE0
P5 - MISO
P6 - MOSI

P15 - GPIO25 (not reset)
P20 - 3V3
P21 to 40 not connected for testing
else: P40 - PWM (GPIO18)

at the moment, SPI - connection gives the following answers:
SPI:WriteIndex: 70 00 00
SPI: ReadData: 73 00 00
otherCode!
0
TP_Drawpoint...and so on

Any Ideas what I could have missed?
Cheers

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Sun Feb 17, 2013 8:14 pm

The wiring looks right.

Looking closer at the code, you seem to be missing the reset sequence.

ILI9320 datasheet
4. Pin Descriptions
nRESET - Initializes the ILI9320 with a low input. Be sure to execute a power-on reset after supplying power.

12.4. Power Supply Configuration
> 1 ms Power On Reset
> 10 ms Oscillator Stabilizing time

13.4. Reset Timing Characteristics
Reset low-level width: minimum 1 ms

In main() the reset pin is set HIGH, but it should be set HIGH and toggled LOW for a minimum of 1 ms. Then a delay of minimum 10 ms.

I have a hobby project (https://github.com/notro/fbtft) writing framebuffer drivers and tried once to skip the reset sequence, with the result that the display would not initialize.

Another problem is that the PI is Little Endian: http://en.wikipedia.org/wiki/Endianness
You have to swap the bytes to set/get the correct 16-bit value.

User avatar
okin
Posts: 4
Joined: Sat Feb 16, 2013 9:47 pm
Location: Austria

Re: HY28A-LCDB, ili9320

Sun Feb 17, 2013 9:07 pm

Dear notro,
thank you a lot! I've got it working =)

I have changed the following things: added the start sequence as you suggested, then changed to BCM2835_SPI_MODE3. Still I didn't change the byte order, since it is used by the bcm2835 library (BCM2835_SPI_BIT_ORDER_MSBFIRST)

best regards

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Sun Feb 17, 2013 10:03 pm

Glad to hear it's working :)

muelli
Posts: 67
Joined: Sat Jul 21, 2012 12:16 pm

Re: HY28A-LCDB, ili9320

Sat Mar 02, 2013 5:51 pm

hi

did you manage to actually use the display for showing data?

thx

User avatar
okin
Posts: 4
Joined: Sat Feb 16, 2013 9:47 pm
Location: Austria

Re: HY28A-LCDB, ili9320

Sun Mar 03, 2013 1:46 pm

Hi,
unfortunately I didn't have much time the last few weeks. I only drew some lines and didn't display any data yet. Additionally the display seems to be quite slow at the moment...
When I find the time, I want to try to write a framebuffer driver for this display, like in notros project mentioned above. So if someone knows a good tutorial about framebuffer devices and how to add them to the system, I would be very glad.

Mit freundlichen Grüßen,
Okin

jharsem
Posts: 1
Joined: Thu Jan 24, 2013 12:02 pm

Re: HY28A-LCDB, ili9320

Mon Mar 04, 2013 5:08 am

Hiya Okin,

would you mind sharing your final code to talk to this display ? - I have two of these as well =) ..

jcfrog
Posts: 2
Joined: Tue Mar 12, 2013 1:21 am

Re: HY28A-LCDB, ili9320

Tue Mar 12, 2013 1:26 am

Hi okin and notro,

I have one of these same LCDs as well. I'm just wondering if you have to keep the CS low the entire time when you write the index register and then the 16bits of data to the desired register, or if you set the CS high between each write.
I am working with an ATXMega, which is only 8 bits so I can only send 8bits of data at a time. So for me, would I set the CS low, write all 24 bits, then set it high again or toggle it between each of the 8bits?

Thanks!

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Tue Mar 12, 2013 10:58 am

jcfrog wrote: I'm just wondering if you have to keep the CS low the entire time when you write the index register and then the 16bits of data to the desired register, or if you set the CS high between each write.
I am working with an ATXMega, which is only 8 bits so I can only send 8bits of data at a time. So for me, would I set the CS low, write all 24 bits, then set it high again or toggle it between each of the 8bits?
Lets look at the datasheet: http://www.techtoys.com.hk/Displays/TY2 ... LI9320.pdf

7.3. Serial Peripheral Interface (SPI)
Looking at Figure8 Data transmission through serial peripheral interface (SPI) we se that CS is kept low during the entire transfer.

CS - Chip Select is a control line that decides which slave will be communicating with the master. This line is also sometimes called SS - Slave Select.

You can toggle the CS line between bytes, but there is no point in doing so if you will be sending multiple bytes to the same device/chip.

jcfrog
Posts: 2
Joined: Tue Mar 12, 2013 1:21 am

Re: HY28A-LCDB, ili9320

Thu Apr 04, 2013 3:24 am

Hello again,

Thank you for your previous reply, it has certainly helped a ton. I now have my LCD working fine and I am now going through all the registers again as I don't quite understand what they all mean.
In particular, I am curious as to what FMARK is.
Any ideas?

Thank you!

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Thu Apr 04, 2013 10:31 am

jcfrog wrote: I am now going through all the registers again as I don't quite understand what they all mean.
In particular, I am curious as to what FMARK is.
Any ideas?
From 4. Pin Descriptions in the datasheet:
FMARK
I/O: Output
Description: Output a frame head pulse signal. The FMARK signal is used when writing RAM data in synchronization with frame. Leave the pin open when not in use.

Apparently it can be used when synchronization of RAM write is needed. The signal is fed back to the one driving the controller.

A couple of days ago I came across an Application Notes document for the ILI9325 controller.
http://icbank.com/data/ICBShop/board/IL ... _V0.22.pdf

This document lists the initialization sequence for 9 different displays. The only thing that differs between the init codes, is the power supply configuration part.

You can see my updated driver for more info about this: https://github.com/notro/fbtft/blob/master/itdb28fb.c

I have also added full rotation support.

lordmiguel24
Posts: 4
Joined: Wed Mar 27, 2013 6:13 pm

Re: HY28A-LCDB, ili9320

Sat Apr 06, 2013 10:53 pm

This display can be interfaced with 16bit serial? There is the framebuffer driver for show X on the display?

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Sun Apr 07, 2013 12:37 am

lordmiguel24 wrote:This display can be interfaced with 16bit serial?
No, it's 8-bit parallel databus + 4 control lines.
However I have ordered some IC's to try and drive the display with SPI. But I don't know how well it will perform.
lordmiguel24 wrote:There is the framebuffer driver for show X on the display?
This project has a framebuffer driver: https://github.com/notro/fbtft
Here's info about wiring: https://github.com/notro/fbtft/wiki/LCD ... i-ITDB0228

The project also have support for a 2.8" SPI display: Watterott MI0283QT-9A. See wiki. The downside is it's higher price.

User avatar
topogigio
Posts: 38
Joined: Fri May 10, 2013 1:35 am

Re: HY28A-LCDB, ili9320

Fri May 10, 2013 2:00 am

Thanx to notro & okin,
after a couple of day I'm be able to drive LCD, set point, lines, box, circle and text.

there are 3 problems:
1st) draw something is extremely slow, can I try to access SPI using ioctl? increase speed?
2nd) May I put LCD in landscape mode select some register? (I can do that by software)
3rd) how to manage touchpanel

I'll post code, when finished.

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Fri May 10, 2013 8:40 pm

topogigio wrote: after a couple of day I'm be able to drive LCD, set point, lines, box, circle and text.
I need to know more to help you.
How do you drive it?

User avatar
topogigio
Posts: 38
Joined: Fri May 10, 2013 1:35 am

Re: HY28A-LCDB, ili9320

Sat May 11, 2013 1:36 am

Hi notro,
my idea is to use the lcd like separate screen with his touch panel that not influence hdmi + mouse, using SPI with lib BCM2835.
I solved the 1st issue. It was the BCM2835_SPI_CLOCK_DIVIDER_X set to 65536 rather 1
The 2nd is using landscape mode of controller ili9320 if exist. If not I'll do that by software.
3rd is using bcm2835_spi lib read xy position of touchpanel.

thanx for your kind attention

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Sat May 11, 2013 8:47 am

If you want your screen to behave like an ordinary Linux screen, you could try the flexfb driver in the FBTFT image: https://github.com/notro/fbtft/wiki
This will give you a framebuffer /dev/fb1 you can use just like the hdmi output.
I don't have any reports of someone using this driver with the ILI9320, but since you have a working init sequence, it should be easy to try: https://github.com/notro/fbtft/wiki/flexfb#ili9320
topogigio wrote: The 2nd is using landscape mode of controller ili9320 if exist. If not I'll do that by software.
Register Entry Mode (R03h) controls this. You have to take care when setting the GRAM area you are writing to, because it depends upon rotation. See here for an example: https://github.com/notro/fbtft/blob/mas ... xfb.c#L136
topogigio wrote: 3rd is using bcm2835_spi lib read xy position of touchpanel.
What kind of touch controller do you have?

User avatar
topogigio
Posts: 38
Joined: Fri May 10, 2013 1:35 am

Re: HY28A-LCDB, ili9320

Sat May 11, 2013 11:26 am

ADS7843

Thanx

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Sat May 11, 2013 1:07 pm

topogigio wrote:ADS7843
There's a kernel driver for this controller. I don't have experience with touch myself, but this is the info I have gathered so far: https://github.com/notro/fbtft/wiki/Touchpanel
I have seen some Arduino code for touch, but it was driving the X/Y lines directly.
topogigio wrote: The 2nd is using landscape mode of controller ili9320 if exist. If not I'll do that by software.
I forgot to mention that you could try the rotation values for the ILI9325: https://github.com/notro/fbtft/wiki/fle ... 28-ili9325

User avatar
topogigio
Posts: 38
Joined: Fri May 10, 2013 1:35 am

Re: HY28A-LCDB, ili9320

Mon May 13, 2013 12:26 pm

Orientation now works thanks

About touch panel, I'm a novice in programming on linux rather than windows, after the driver installation how can I access driver, I will see it through dev io stream?
If the driver uses the same SPI of the LCD what's happen? Will conflicting with LCD.
thanx

notro
Posts: 755
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: HY28A-LCDB, ili9320

Mon May 13, 2013 6:11 pm

topogigio wrote: About touch panel, I'm a novice in programming on linux rather than windows, after the driver installation how can I access driver, I will see it through dev io stream?
Sorry I can't help you with that.
This command could be a place to start: evtest /dev/input/eventX
It shows events like keypress, cursor movement, button etc.
topogigio wrote: If the driver uses the same SPI of the LCD what's happen? Will conflicting with LCD.
They will share the buslines SCLK and MOSI, but have separate CS lines.
Illustration from Wikipedia SPI article: http://en.wikipedia.org/wiki/File:SPI_three_slaves.svg
CS - Chip Select can also be called SS Slave Select, or CE Chip Enable.

User avatar
topogigio
Posts: 38
Joined: Fri May 10, 2013 1:35 am

Re: HY28A-LCDB, ili9320

Mon May 13, 2013 9:45 pm

notro,
Thanx for your prompt replay, I'll be treasure of your advice.

User avatar
topogigio
Posts: 38
Joined: Fri May 10, 2013 1:35 am

Re: HY28A-LCDB, ili9320

Sat May 18, 2013 2:32 am

Hi,
after 3 days, better now then never!
Touch panel now is touchable :)
Simple BCM2835 doesn't work on spidev0.1.
I have installed wiringPi, tada! It works with freq. to 3.200.000 hz.
Now is a mixed SPI, this means that LCD works with BCM driver TP with wPi.

goodnight :)

Return to “Other projects”