Problem with CFAF240400D-030T-CB

ADRIAN BARRANCO

New member
Hello, I have a CFAF240400D-030T-CB, I tried to use the demostration code that comes with the product, but I cant see anything in the display, I´m using a freescale demoqe128 microcontroller. I read that the "IM0" "IM1" and "IM2" for the 8, 9, 16 and 18 bit mode pins are wrong in the datasheet.
I´m using PTFD for one data bus, and for the other PTAD (bits 1,2,3,6,7) and PTBD (bits 0,4,5).
This is the code that Im using:
Code:
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "stdint.h"
void LCD_test();
void delay(unsigned int t);
void write_command(unsigned int command);
void write_data(unsigned int data);
void initialization();
void Display_Home();
void display_rgb(unsigned int data);
void ini_port(void);
#define CLR_CD PTCD &= ~PTCD_PTCD7_MASK;
#define SET_CD PTCD |=  PTCD_PTCD7_MASK;
#define CLR_CS PTCD &= ~PTCD_PTCD4_MASK;
#define SET_CS PTCD |=  PTCD_PTCD4_MASK;
#define CLR_RESET PTCD &= ~PTCD_PTCD2_MASK;
#define SET_RESET PTCD |=  PTCD_PTCD2_MASK;
#define CLR_WR PTCD &= ~PTCD_PTCD6_MASK;
#define SET_WR PTCD |=  PTCD_PTCD6_MASK;
#define CLR_RD PTCD &= ~PTCD_PTCD5_MASK;
#define SET_RD PTCD |=  PTCD_PTCD5_MASK;
// color definitions
#define	BLACK	  0x0000
#define	BLUE	  0x001F
#define	RED 	  0xF800
#define	GREEN	  0x07E0
#define CYAN	  0x07FF
#define MAGENTA   0xF81F
#define YELLOW    0xFFE0
#define WHITE	  0xFFFF
//#define uint8 unsigned char
//#define uint16 unsigned int
//#define uint32 unsigned long
//uint8_t datoA = 0xCE; //%11001110
//uint8_t datoB = 0x31; //%00110001
/*************************************************/
void main()
	{
	EnableInterrupts;
	ini_port();	
	// Initialize the display
	initialization();
	while(1) 
		{
		__RESET_WATCHDOG();    /* feeds the dog */
		/*if(PTDD_PTDD3 == 0)
			{
			PTAD = 0x55;
			PTBD = 0x55;
			PTFD = 0x55;
			PTCD = ;
			}
		else
			{
			PTAD = 0xAA;
			PTBD = 0xAA;
			PTFD = 0xAA;
			PTCD = ;
			}*/
		LCD_test();
		} /* loop forever */
	/* please make sure that you never leave main */
	
	}
/*************************************************/
void delay(unsigned int t)
	{
	while(t > 0)
		{
		__RESET_WATCHDOG();
		t--;
		}
	}
/*************************************************/
void write_command(unsigned int command)
	{
	CLR_CS;
	CLR_CD;
	SET_RD;
	SET_WR;
	PTAD = (unsigned char)command;
	//PTAD = ((unsigned char)command)&&datoA;
	PTBD = (unsigned char)command;
	//PTBD = ((unsigned char)command)&&datoB;
	PTFD = (unsigned char)command>>8;
	CLR_WR;
	SET_WR;
	SET_CS;
	}
/*************************************************/
void write_data(unsigned int data)
	{
	CLR_CS;
	SET_CD;
	SET_RD;
	SET_WR;
	PTAD = (unsigned char)data;
	//PTAD = ((unsigned char)data)&&datoA;
	PTBD = (unsigned char)data;
	//PTBD = ((unsigned char)data)&&datoB;
	PTFD = (unsigned char)data >>8;	
	CLR_WR;
	SET_WR;
	SET_CS;
	// keeps the display from going wonky -- don't know why this is.
	PTAD = (unsigned char)0xFFFF;
	//PTAD = ((unsigned char)0xFFFF)&&datoA;
	PTBD = (unsigned char)0xFFFF;
	//PTBD = ((unsigned char)0xFFFF)&&datoB;
	PTFD = (unsigned char)0xFFFF;
	}	
/*************************************************/
void initialization()
	{
	SET_RD;
	SET_WR;
	SET_CS;
	SET_CD;
	PTAD = 0x00;
	PTBD = 0x00;
	PTFD = 0x00;
	CLR_RESET;
	delay(10000);
	delay(10000);
	SET_RESET;
	delay(500);
	write_command(0x0606);    // Pin Control (R606h)
	write_data(0x0000);       // Page 41 of SPFD5420A Datasheet
	delay(50);
	write_command(0x0007);    // Display Control 1 (R007h)
	write_data(0x0001);       // Page 16 of SPFD5420A Datasheet 
	delay(50);
	write_command(0x0110);    // Power Control 6(R110h)
	write_data(0x0001);       // Page 30 of SPFD5420A Datasheet
	delay(50);
	write_command(0x0100);    // Power Control 1 (R100h)
	write_data(0x17B0);       // Page 26 of SPFD5420A Datasheet
	write_command(0x0101);    // Power Control 2 (R101h)
	write_data(0x0147);       // Page 27 of SPFD5420A Datasheet
	write_command(0x0102);    // Power Control 3 (R102h)
	write_data(0x019D);       // Page 28 of SPFD5420A Datasheet
	write_command(0x0103);    // Power Control 4 (R103h)
	write_data(0x3600);       // Page 29 of SPFD5420A Datasheet
	write_command(0x0281);    // NVM read data 2 (R281h)  
	write_data(0x0010);       // Page 34 of SPFD5420A Datasheet
	delay(50);
	write_command(0x0102);    // Power Control 3 (R102h)
	write_data(0x01BD);       // Page 28 of SPFD5420A Datasheet
	delay(50);
	//--------------- Power control 1~6 ---------------//
	write_command(0x0100);    // Power Control 1 (R100h)
	write_data(0x16B0);       // Page 26 of SPFD5420A Datasheet
	write_command(0x0101);    // Power Control 2 (R101h)
	write_data(0x0147);       // Page 27 of SPFD5420A Datasheet
	write_command(0x0102);    // Power Control 3 (R102h)
	write_data(0x01BD);       // Page 28 of SPFD5420A Datasheet
	write_command(0x0103);    // Power Control 4 (R103h)
	write_data(0x2d00);       // Page 29 of SPFD5420A Datasheet
	write_command(0x0107);    // Power Control 5 (R107h)
	write_data(0x0000);       // Page 30 of SPFD5420A Datasheet
	write_command(0x0110);    // Power Control 6(R110h)
	write_data(0x0001);       // Page 30 of SPFD5420A Datasheet
	write_command(0x0280);    // NVM read data 1 (R280h)
	write_data(0x0000);       // Page 33 of SPFD5420A Datasheet
	write_command(0x0281);    // NVM read data 2 (R281h)
	write_data(0x0006);       // Page 34 of SPFD5420A Datasheet
	write_command(0x0282);    // NVM read data 3 (R282h)
	write_data(0x0000);       // Page 34 of SPFD5420A Datasheet
	//------- Gamma 2.2 control (R300h to R30Fh) ------//
	write_command(0x0300); 
	write_data(0x0101);    
	write_command(0x0301); 
	write_data(0x0b27);    
	write_command(0x0302); 
	write_data(0x132a);    
	write_command(0x0303); 
	write_data(0x2a13);    
	write_command(0x0304); 
	write_data(0x270b);    
	write_command(0x0305); 
	write_data(0x0101);    
	write_command(0x0306); 
	write_data(0x1205);    
	write_command(0x0307); 
	write_data(0x0512);    
	write_command(0x0308); 
	write_data(0x0005);    
	write_command(0x0309); 
	write_data(0x0003);    
	write_command(0x030A); 
	write_data(0x0f04);    
	write_command(0x030B); 
	write_data(0x0f00);    
	write_command(0x030C); 
	write_data(0x000f);    
	write_command(0x030D);    
	write_data(0x040f);       
	write_command(0x030E);    
	write_data(0x0300);       
	write_command(0x030F);    
	write_data(0x0500);       

	write_command(0x0400);    // Base Image Number of Line (R400h)
	write_data(0x3500);       // Page 36 of SPFD5420A Datasheet
	write_command(0x0401);    // Base Image Display Control (R401h)
	write_data(0x0001);       // Page 39 of SPFD5420A Datasheet
	write_command(0x0404);    // Based Image Vertical Scroll Control (R404h)
	write_data(0x0000);       // Page 40 of SPFD5420A Datasheet
	//--------------- Normal set ---------------//
	write_command(0x0000);    // ID Read Register (R000h)
	write_data(0x0000);       // Page 13 of SPFD5420A Datasheet
	write_command(0x0001);    // Driver Output Control Register (R001h)
	write_data(0x0100);       // Page 14 of SPFD5420A Datasheet
	write_command(0x0002);    // LCD Driving Waveform Control (R002h)
	write_data(0x0100);       // Page 14 of SPFD5420A Datasheet
	write_command(0x0003);    // Entry Mode (R003h)
	write_data(0x1030);       // Page 15 of SPFD5420A Datasheet
	write_command(0x0006);    // Display Control 1 (R007h)
	write_data(0x0000);       // Page 16 of SPFD5420A Datasheet	
	write_command(0x0008);    // Display Control 2 (R008h)
	write_data(0x0808);       // Page 17 of SPFD5420A Datasheet
	write_command(0x0009);    // Display Control 3 (R009h)
	write_data(0x0001);       // Page 18 of SPFD5420A Datasheet
	write_command(0x000B);    // Low Power Control (R00Bh)
	write_data(0x0010);       // Page 19 of SPFD5420A Datasheet
	write_command(0x000C);    // External Display Interface Control 1 (R00Ch)
	write_data(0x0000);       // Page 19 of SPFD5420A Datasheet
	write_command(0x000F);    // External Display Interface Control 2 (R00Fh)
	write_data(0x0000);       // Page 20 of SPFD5420A Datasheet
	write_command(0x0007);    // Display Control 1 (R007h)
	write_data(0x0001);       // Page 16 of SPFD5420A Datasheet
	//--------------- Panel interface control 1~6 ---------------//
	write_command(0x0010);    // Panel Interface Control 1 (R010h)
	write_data(0x0012);       // Page 20 of SPFD5420A Datasheet
	write_command(0x0011);    // Panel Interface Control 2 (R011h)
	write_data(0x0202);       // Page 21 of SPFD5420A Datasheet
	write_command(0x0012);    // Panel Interface control 3 (R012h)
	write_data(0x0300);       // Page 22 of SPFD5420A Datasheet
	write_command(0x0020);    // Panel Interface control 4 (R020h)
	write_data(0x021E);       // Page 22 of SPFD5420A Datasheet
	write_command(0x0021);    // Panel Interface Control 5 (021Rh)
	write_data(0x0202);       // Page 24 of SPFD5420A Datasheet
	write_command(0x0022);    // Panel Interface Control 6 (R022h)
	write_data(0x0100);       // Page 25 of SPFD5420A Datasheet
	write_command(0x0090);    // Frame Marker Control (R090h)
	write_data(0x8000);       // Page 25 of SPFD5420A Datasheet
	//--------------- Partial display ---------------//
	write_command(0x0210);    // Window Horizontal RAM Address Start (R210h)
	write_data(0x0000);       // Page 35 of SPFD5420A Datasheet
	write_command(0x0211);    // Window Horziontal RAM Address End (R211h)
	write_data(0x00EF);       // Page 35 of SPFD5420A Datasheet
	write_command(0x0212);    // Window Vertical RAM Address Start (R212h)
	write_data(0x0000);       // Page 35 of SPFD5420A Datasheet
	write_command(0x0213);    // Window Vertical RAM Address End (R213h)
	write_data(0x018F);       // Page 35 of SPFD5420A Datasheet
	write_command(0x0500);    // Display Position - Partial Display 1 (R500h)
	write_data(0x0000);       // Page 40 of SPFD5420A Datasheet
	write_command(0x0501);    // RAM Address Start - Partial Display 1 (R501h)
	write_data(0x0000);       // Page 40 of SPFD5420A Datasheet
	write_command(0x0502);    // RAM Address End - Partail Display 1 (R502h)
	write_data(0x0000);       // Page 40 of SPFD5420A Datasheet
	write_command(0x0503);    // Display Position - Partial Display 2 (R503h)
	write_data(0x0000);       // Page 40 of SPFD5420A Datasheet
	write_command(0x0504);    // RAM Address Start – Partial Display 2 (R504h)
	write_data(0x0000);       // Page 41 of SPFD5420A Datasheet
	write_command(0x0505);    // RAM Address End – Partial Display 2 (R505h)
	write_data(0x0000);       // Page 41 of SPFD5420A Datasheet
	write_command(0x0606);    // Pin Control (R606h)
	write_data(0x0000);       // Page 41 of SPFD5420A Datasheet
	write_command(0x06F0);    // NVM Access Control (R6F0h)
	write_data(0x0000);       // Page 41 of SPFD5420A Datasheet
	write_command(0x0007);    // Display Control 1 (R007h)
	write_data(0x0173);       // Page 16 of SPFD5420A Datasheet
	delay(50);
	write_command(0x0007);    // Display Control 1 (R007h)
	write_data(0x0171);       // Page 16 of SPFD5420A Datasheet
	delay(10);
	write_command(0x0007);    // Display Control 1 (R007h)
	write_data(0x0173);       // Page 16 of SPFD5420A Datasheet
	}
void Display_Home()
	{
	write_command(0x0200);    // GRAM Address Set (Horizontal Address) (R200h)
	write_data(0x0000);       // Page 30 of SPFD5420A Datasheet
	write_command(0x0201);    // GRAM Address Set (Vertical Address) (R201h)
	write_data(0x0000);       // Page 30 of SPFD5420A Datasheet
	write_command(0x0202);    // Write Data to GRAM (R202h)
	}
void display_rgb(unsigned int data)
	{
	unsigned int i,j;
	for(i=0;i<400;i++)
		{
		for(j=0;j<240;j++)
			{
			write_data(data);
			}
		}
	}
void LCD_test()
	{
	unsigned int i,j;
	Display_Home();
	for(i=0;i<240;i++)
		{
		__RESET_WATCHDOG(); 
		for(j=0;j<400;j++)
			{
			__RESET_WATCHDOG(); 
			if(i>209)write_data(BLACK);
			else if(i>179)write_data(BLUE);
			else if(i>149)write_data(RED);
			else if(i>119)write_data(GREEN);
			else if(i>89)write_data(CYAN);
			else if(i>59)write_data(MAGENTA);
			else if(i>29)write_data(YELLOW);
			else write_data(WHITE);
			}
		}
	}
void ini_port(void)
	{
	PTADD = 0x00;  //datos
	PTADD |= PTADD_PTADD1_MASK | PTADD_PTADD2_MASK | PTADD_PTADD3_MASK | PTADD_PTADD6_MASK | PTADD_PTADD7_MASK;
	PTFDD = 0xFF;	//dato
	PTBDD = 0x00;
	PTBDD |= PTBDD_PTBDD0_MASK | PTBDD_PTBDD4_MASK | PTBDD_PTBDD5_MASK;
	PTCDD = 0xFF;	//instruc
	PTDDD = 0xFF;
	PTDDD_PTDDD3 = 0;
	PTDPE_PTDPE3 = 1;
	}
Put code formatting in: Moderator
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
I have the prior version of this display (CFAF240400D-T), which I have working in a test jig. Your code looks very similar to mine, except for the I/O port assignments, of course.

Explain more about how you are connected to IM0, IM1, and IM2, and what value are you setting those pins to. I'm not familiar with your cpu and the port control registers, and your port settings are somewhat cryptic. Where did you read about the mode pins in the SPFD5420A being "wrong" in the datasheet? (I'm wondering if this might be something I wrote, as I have a vague memory of one of these TFT displays having that issue, but I don't remember which one.)

Three ideas come to mind:
1. a wiring problem, such that the display is not receiving the signals you think you are sending.
2. wrong mode selected (perhaps).
3. cpu speed too high, resulting in write timings & pulse width being too short.

Need more info to suggest further.
Do you have a way to verify your signal/data wiring (o'scope)?
 

ADRIAN BARRANCO

New member
I checked my data using a logic analyzer, it is correct. My CPU is running at 4Mhz, and the delay times seems to be ok.
I connected the "IM" at all the posibles ways: "000" ,"001","010","011","100","101","110" and "111", and all of them result in the same, it didn´t worked. The data sheet says "IM0(ID), IM1(IM0), IM2(IM1), what does that means? IM1 is connected to IM0? I can´t understand that.
In this post I read the discrepancy between the CFA data sheet and the SPFD5420 data sheet, check out the 11 coment. https://forum.crystalfontz.com/showthread.php?6656-CFAF240400DT-initialization
Thanks and sorry for my bad english.
 
Last edited:
I checked my data using a logic analyzer, it is correct.
I wonder whether you measured at the cpu outputs or the display inputs. What matters is which pins are receiving the signals in the display board.

The data sheet says "IM0(ID), IM1(IM0), IM2(IM1), what does that means? IM1 is connected to IM0? I can´t understand that. In this post I read the discrepancy between the CFA data sheet and the SPFD5420 data sheet, check out the 11 coment. https://forum.crystalfontz.com/showthread.php?6656-CFAF240400DT-initialization Thanks and sorry for my bad english.
Yeah, that is the old post I was thinking of, and it refers to datasheets that are now obsolete, I think, because I don't see any text which says "IM0(ID), IM1(IM0), IM2(IM1)".

The next question is whether you noticed that the data connections are this:
8 bit: DB10 - DB17
16 bit: DB10 - DB17 (high byte) and DB1 - DB8 (low byte)
DB0 and DB9 are not used in these modes

In my code, which works in both 8 bit and 16 bit modes has these mode bits (which are different from the datasheet):
8 bit: IM2-IM1-IM0 = 001
16 bit: IM2-IM1-IM0 = 011
I have those bits on an I/O port so I can switch between modes in software.

If this info does not help your problem, then it suggests a subtle error somewhere. I am assuming there is no power or signal voltage level problems, and that there is a good ground connection between boards, and no noise/crosstalk.
 
Top