|
|
View previous topic :: View next topic |
Author |
Message |
Backfire
Joined: 12 Oct 2020 Posts: 46
|
SPI Comms With ILI9341 |
Posted: Mon Oct 12, 2020 10:28 am |
|
|
Hi everyone,
I was hoping for some advice on an issue I'm having trying to get a PIC (specifically a 18F2455) communicating with a ILI9341 based GFX LCD over SPI.
I've used the library from adafruit for the CCS C compiler as a jumping off point, and attach my modified code below for reference.
I just can't seemingly get the display to, well... display anything. I'm awaiting delivery of a cheap logic analyser to look into things further, but until then I thought I'd see if anyone could point out if I'm missing anything simple/obvious, as this is my first foray into SPI comms with CCS.
My hardware connections are all direct, and are listed below, the screen has 3.2V stable d.c. power, and does illuminate, just routines are not producing anything on the display.
PIC RB1 -> LCD SCK
PIC RC4 -> LCD CS
PIC RC5 -> LCD RST
PIC RC6 -> LCD D/C
PIC RC7 -> LCD SDAT
PIC is running from a 8MHz XTAL, PLL'ed up to 48MHz internally, and the LED flash routine of destiny runs without issues.
I know the code is ugly and needs MUCH further development, I've thrown this together to (attempt) the most basic of functionality first with everything clear and step-by-step.
Code: |
#include <main.h>
#include <stdint.h>
#use spi (MASTER, SPI1, MODE=0, BITS=8)
// Screen function prototypes
void LCDHardReset(void);
void LCDInit(void);
void LCDEnableWrite(void);
void LCDDisableWrite(void);
void LCDWriteCmd(int8 Command);
void LCDSetAddressWindow(int16 x1, int16 y1, int16 w, int16 h);
void LCDRenderPixel(int16 x, int16 y, int16 colour);
void LCDSetCursor(int16 X, int16 Y);
void main()
{
int8 i = 0;
setup_adc_ports(AN0, VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0);
LCDHardReset();
LCDInit();
while(TRUE)
{
output_low(LED_BI_GRN);
delay_ms(500);
output_high(LED_BI_GRN);
delay_ms(500);
LCDRenderPixel(100, 100, 0xF800);
i++;
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void LCDHardReset()
{
output_high(SCREEN_RST);
output_drive(SCREEN_RST);
delay_ms(100);
output_low(SCREEN_RST);
delay_ms(100);
output_high(SCREEN_RST);
delay_ms(200);
}
void LCDInit()
{
output_high(SCREEN_CS);
output_drive(SCREEN_CS);
output_drive(SCREEN_DC);
LCDEnableWrite();
LCDWriteCmd(0xCB);
spi_xfer(0x39);
spi_xfer(0x2C);
spi_xfer(0x00);
spi_xfer(0x34);
spi_xfer(0x02);
LCDWriteCmd(0xCF);
spi_xfer(0x00);
spi_xfer(0xC1);
spi_xfer(0x30);
LCDWriteCmd(0xE8);
spi_xfer(0x85);
spi_xfer(0x00);
spi_xfer(0x78);
LCDWriteCmd(0xEA);
spi_xfer(0x00);
spi_xfer(0x00);
LCDWriteCmd(0xED);
spi_xfer(0x64);
spi_xfer(0x03);
spi_xfer(0x12);
spi_xfer(0x81);
/*
LCDWriteCmd(0xEF);
spi_xfer(0x03);
spi_xfer(0x80);
spi_xfer(0x02);
*/
LCDWriteCmd(0xF7);
spi_xfer(0x20);
// Power Control
LCDWriteCmd(0xC0);
spi_xfer(0x23);
LCDWriteCmd(0xC1);
spi_xfer(0x10);
// VCOM Control
LCDWriteCmd(0xC5);
spi_xfer(0x3E);
spi_xfer(0x28);
LCDWriteCmd(0xC7);
spi_xfer(0x86);
// Memory Access Control
LCDWriteCmd(0x36);
spi_xfer(0x88);
/*
// Vertical Scroll Start Address
LCDWriteCmd(0x37);
spi_xfer(0x00);
*/
// Pixel Format Colour Mode
LCDWriteCmd(0x3A);
spi_xfer(0x55);
// Frame Rate Control
LCDWriteCmd(0xB1);
spi_xfer(0x00);
spi_xfer(0x18);
// Display Function Control
LCDWriteCmd(0xB6);
spi_xfer(0x08);
spi_xfer(0x82);
spi_xfer(0x27);
LCDWriteCmd(0xF2);
spi_xfer(0x00);
// Set Screen Gamma
LCDWriteCmd(0x26);
spi_xfer(0x01);
// Positive Gamma Correction
LCDWriteCmd(0xE0);
spi_xfer(0x0F);
spi_xfer(0x31);
spi_xfer(0x2B);
spi_xfer(0x0C);
spi_xfer(0x0E);
spi_xfer(0x08);
spi_xfer(0x4E);
spi_xfer(0xF1);
spi_xfer(0x37);
spi_xfer(0x07);
spi_xfer(0x10);
spi_xfer(0x03);
spi_xfer(0x0E);
spi_xfer(0x09);
spi_xfer(0x00);
// Negative Gamma Correction
LCDWriteCmd(0xE1);
spi_xfer(0x00);
spi_xfer(0x0E);
spi_xfer(0x14);
spi_xfer(0x03);
spi_xfer(0x11);
spi_xfer(0x07);
spi_xfer(0x31);
spi_xfer(0xC1);
spi_xfer(0x48);
spi_xfer(0x08);
spi_xfer(0x0F);
spi_xfer(0x0C);
spi_xfer(0x31);
spi_xfer(0x36);
spi_xfer(0x0F);
LCDWriteCmd(0x11);
delay_ms(150);
LCDWriteCmd(0x2C);
LCDWriteCmd(0x29);
LCDWriteCmd(0x2C);
LCDDisableWrite();
}
void LCDWriteCmd(int8 Command)
{
output_low(SCREEN_DC);
spi_xfer(Command);
output_high(SCREEN_DC);
}
void LCDEnableWrite(void)
{
output_low(SCREEN_CS);
}
void LCDDisableWrite(void)
{
output_high(SCREEN_CS);
}
void LCDSetAddressWindow(int16 x1, int16 y1, int16 w, int16 h)
{
int16 x2 = (x1 + w - 1), y2 = (y1 + h - 1);
LCDWriteCmd(0x2A);
spi_xfer(x1 >> 8);
spi_xfer(x1);
spi_xfer(x2 >> 8);
spi_xfer(x2);
LCDWriteCmd(0x2B);
spi_xfer(y1 >> 8);
spi_xfer(y1);
spi_xfer(y2 >> 8);
spi_xfer(y2);
LCDWriteCmd( 0x2C);
}
void LCDRenderPixel(int16 x, int16 y, int16 colour)
{
LCDEnableWrite();
LCDSetCursor(x, y);
spi_xfer(colour >> 8);
spi_xfer(colour & 0xFF);
LCDDisableWrite();
}
void LCDSetCursor(int16 X, int16 Y)
{
LCDWriteCmd(0x2B);
spi_xfer(X >> 8);
spi_xfer(X & 0xFF);
LCDWriteCmd(0x2C);
LCDWriteCmd(0x2A);
spi_xfer(Y >> 8);
spi_xfer(Y & 0xFF);
LCDWriteCmd(0x2C);
}
|
I'm using the IDE suite and PCH Compiler V5.094
Thanks for taking the time to read this folks!
- BackFire |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Oct 12, 2020 10:47 am |
|
|
1st question, what VDD is the PIC running ? If 3 volts, that's below the spec as shown in figure 28.1 of the datasheet..... |
|
|
Backfire
Joined: 12 Oct 2020 Posts: 46
|
|
Posted: Mon Oct 12, 2020 10:50 am |
|
|
Hi temtronic,
system voltage is a stable, decoupled locally against HF interference, 3.2-3.3V d.c.
Thanks for your reply. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 12, 2020 11:36 am |
|
|
Quote: |
PIC RB1 -> LCD SCK
PIC RC4 -> LCD CS
PIC RC5 -> LCD RST
PIC RC6 -> LCD D/C
PIC RC7 -> LCD SDAT
|
On the 18F2455, pins C4 and C5 are "input only". They are not going to
work for the lcd chip select or reset lines. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Mon Oct 12, 2020 11:41 am |
|
|
and as has already been mentioned, the 18F2455, is not rated to run at
this voltage. You will commonly find that PIC's will work below their
rated voltage, but peripherals won't. I'd not be surprised to find that
the SPI won't work at this voltage.
The 18LF2455 (note the 'L'), is rated to run down at this voltage at
a maximum of about 20MHz. |
|
|
Backfire
Joined: 12 Oct 2020 Posts: 46
|
|
Posted: Mon Oct 12, 2020 2:51 pm |
|
|
Well... that certainly explains that! :-D
I already had some ‘L’ variants on order luckily, but I had straight-up missed the input-only port pins. Thanks for the feedback all, I’ll report back with an update on following the advice!
Cheers again.
- BackFire |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|