• AVR Freaks

Hot!TFT screen not working on PIC32MX using SPI

Author
LanternMG
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/04/04 14:39:05
  • Location: 0
  • Status: offline
2020/08/01 10:52:45 (permalink)
0

TFT screen not working on PIC32MX using SPI

I am using the PIC32MX170F256D and this is my first time working with the PIC32. I've previously worked with PIC16F886 and I've always been able to find a good solution to any problem I've come across. Unfortunately. that's not the case with PIC32. For the past 2 weeks I've been trying to get the TFT screen working with this particular PIC.
The TFT screen I'm using is TJCTM24028-SPI. I know that the screen is working because I've been using it with Arduino and the STM32F103C8T6.
I've tried using the MPLAB Code Configurator and the MPLAB Harmony v3 to try and make the screen show just a single color background for a start. But I'm just getting a blank screen.
I am using the PICKit 3 to program the device and I know that it works because I tested a "blink led" program I wrote.
Here is my configuration using the MCC.
 
Configuration bits:

// DEVCFG3
#pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration->Allow only one reconfiguration
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration->Allow only one reconfiguration
// DEVCFG2
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider->2x Divider
#pragma config FPLLMUL = MUL_24 // PLL Multiplier->24x Multiplier
#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider->PLL Divide by 2
// DEVCFG1
#pragma config FNOSC = FRCPLL // Oscillator Selection Bits->Fast RC Osc with PLL
#pragma config FSOSCEN = ON // Secondary Oscillator Enable->Enabled
#pragma config IESO = OFF // Internal/External Switch Over->Disabled
#pragma config POSCMOD = OFF // Primary Oscillator Configuration->Primary osc disabled
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin->Disabled
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor->Pb_Clk is Sys_Clk/1
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection->Clock Switch Disable, FSCM Disabled
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler->1:1048576
#pragma config WINDIS = OFF // Watchdog Timer Window Enable->Watchdog Timer is in Non-Window Mode
#pragma config FWDTEN = OFF // Watchdog Timer Enable->WDT Disabled (SWDTEN Bit Controls)
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size->Window Size is 25%
// DEVCFG0
#pragma config DEBUG = OFF // Background Debugger Enable->Debugger is Disabled
#pragma config JTAGEN = OFF // JTAG Enable->JTAG Disabled
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select->Communicate on PGEC1/PGED1
#pragma config PWP = OFF // Program Flash Write Protect->Disable
#pragma config BWP = OFF // Boot Flash Write Protect bit->Protection Disabled
#pragma config CP = OFF // Code Protect->Protection Disabled

My Oscillator settings are:
- Clock Source: FRC Oscillator (8 MHz)
- PLL: 2x input divider, 24x multiplier, 2x output divider
 
This gives me a speed of 48 MHz for the PIC.
My SPI settings are:
- Communication width: 8 bit
- SPI Clock Frequency: 8MHz
- Clock Polarity: Idle-Low, Active-High
- Clock Edge: Active to Idle (falling edge)
- Input data sampled at: Middle

Pin Configuration:
- TFT_DC - RC8 (4th pin of the 44 pin package)
- TFT_RST - RC9 (5th pin of the 44 pin package)
- TFT_CS - RA10 (12th of the 44 pin package)
- TFT_LED - RC3 (36th pin of the 44 pin package)
- SCK - RB14 (14th pin of the 44 pin package)

I've tried using both a TFT library for the PIC32MX found here: https://hackaday.io/proje...display-with-the-pic32 and I tried to modify the original code from the Adafruit library which I used on the arduino and STM32. As I stated previously, for a start I just want to get the background working just so I know that everything is working, so the modified code from the Adafruit library I used is:
void writecommand(uint8_t c)
{
TFT_DC_SetLow();
TFT_CS_SetLow();
SPI1_Exchange8bit(c);
TFT_CS_SetHigh();
}
void writedata(uint8_t d)
{
TFT_DC_SetHigh();
TFT_CS_SetLow();
SPI1_Exchange8bit(c);
TFT_CS_SetHigh();
}
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
writecommand(0x2A); // Column addr set
writedata(x0 >> 8);
writedata(x0 & 0xFF); // XSTART
writedata(x1 >> 8);
writedata(x1 & 0xFF); // XEND
writecommand(0x2B); // Row addr set
writedata(y0>>8);
writedata(y0); // YSTART
writedata(y1>>8);
writedata(y1); // YEND
writecommand(0x2C); // write to RAM
}
uint8_t lcd_draw_pixel(int16_t x, int16_t y, uint16_t color)
{
setAddrWindow(x,y,x+1,y+1);
writedata(color >> 8);
writedata(color);

return EXIT_SUCCESS;
}
void lcd_fill(uint16_t bg_color)
{
uint16_t width = 320, height = 240;

while(width--)
{
while(height--)
lcd_draw_pixel(bg_color);
height = 240;
}
}

void TFTInit()
{
TFT_RST_SetHigh();
delay_ms(5);
TFT_RST_SetLow();
delay_ms(20);
TFT_RST_SetHigh();
delay_ms(150);

writecommand(0xEF);
writedata(0x03);
writedata(0x80);
writedata(0x02);
writecommand(0xCF);
writedata(0x00);
writedata(0XC1);
writedata(0X30);
writecommand(0xED);
writedata(0x64);
writedata(0x03);
writedata(0X12);
writedata(0X81);
writecommand(0xE8);
writedata(0x85);
writedata(0x00);
writedata(0x78);
writecommand(0xCB);
writedata(0x39);
writedata(0x2C);
writedata(0x00);
writedata(0x34);
writedata(0x02);
writecommand(0xF7);
writedata(0x20);
writecommand(0xEA);
writedata(0x00);
writedata(0x00);
writecommand(0xC0); //Power control
writedata(0x23); //VRH[5:0]
writecommand(0xC1); //Power control
writedata(0x10); //SAP[2:0];BT[3:0]
writecommand(0xC5); //VCM control
writedata(0x3e);
writedata(0x28);
writecommand(0xC7); //VCM control2
writedata(0x86); //--
writecommand(0x36); // Memory Access Control
writedata(0x48);
writecommand(0x3A);
writedata(0x55);
writecommand(0xB1);
writedata(0x00);
writedata(0x18);
writecommand(0xB6); // Display Function Control
writedata(0x08);
writedata(0x82);
writedata(0x27);
writecommand(0xF2); // 3Gamma Function Disable
writedata(0x00);
writecommand(0x26); //Gamma curve selected
writedata(0x01);
writecommand(0xE0); //Set Gamma
writedata(0x0F);
writedata(0x31);
writedata(0x2B);
writedata(0x0C);
writedata(0x0E);
writedata(0x08);
writedata(0x4E);
writedata(0xF1);
writedata(0x37);
writedata(0x07);
writedata(0x10);
writedata(0x03);
writedata(0x0E);
writedata(0x09);
writedata(0x00);
writecommand(0xE1); //Set Gamma
writedata(0x00);
writedata(0x0E);
writedata(0x14);
writedata(0x03);
writedata(0x11);
writedata(0x07);
writedata(0x31);
writedata(0xC1);
writedata(0x48);
writedata(0x08);
writedata(0x0F);
writedata(0x0C);
writedata(0x31);
writedata(0x36);
writedata(0x0F);
writecommand(0x11); //Exit Sleep

delay_ms(120);

writecommand(0x29);

TFT_LED_SetHigh();
}
int main(void)
{
// initialize the device
SYSTEM_Initialize();
TFTInit();
while (1)
{
lcd_fill(0x0010); // Set Color NAVY
delayMs(1000);
}
return -1;
}

 
I would really appreciate it if anyone can help me with this. I really have no idea what I'm doing wrong.
Thank you in advance!
#1

3 Replies Related Threads

    Stefiff
    Senior Member
    • Total Posts : 99
    • Reward points : 0
    • Joined: 2012/07/15 15:26:29
    • Location: 0
    • Status: offline
    Re: TFT screen not working on PIC32MX using SPI 2020/08/03 03:00:22 (permalink)
    0
    Give the code for initialization of the processor and functions. For someone to help you, he needs to understand what you are trying to do. Do you have any transfer to the SPI port at all? ISR? The library is the last stage.
    Don't think like an Arduino user, everyone takes something from somewhere, puts it on, and if it works, it works. If not, black hole, don't even try to figure out how it works.
    Set up to have SPI transfer first, then turn on and add libraries.
    Read the errata file for this processor.
    #2
    MrAureliusR
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2014/06/25 19:55:32
    • Location: Toronto, Ontario, Canada
    • Status: offline
    Re: TFT screen not working on PIC32MX using SPI 2020/08/03 07:50:46 (permalink)
    0
    I would suggest doing a minimum viable example with SPI. If you have a logic analyzer, check to see if you're getting signals on the SPI lines. Create a new project, and have it just initialize the SPI peripheral and then send 0x55 over and over again. This will look like a clock signal coming out of the data pin and makes debugging a bit easier.
     
     

    I <3 PIC32MX
    #3
    LdB_ECM
    Super Member
    • Total Posts : 407
    • Reward points : 0
    • Joined: 2019/04/16 22:01:25
    • Location: 0
    • Status: offline
    Re: TFT screen not working on PIC32MX using SPI 2020/08/04 06:09:10 (permalink)
    0
    Code looks correct .. are you sure about the delays of which weirdly you are using two???
    delay_ms  vs  delayMs

     
    Try delay_ms(10000) on a led and time it and check its roughly 10 seconds.
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5