This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28335: TFT-LCD control using SPI module

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hi, I was trying to control my TFT-LCD by using hardware SPI. While using software SPI, LCD can dsiplay with nothing wrong.

The only difference in my code between them is that if #define USE_HARDWARE_SPI, the WriteData function will use SPI module or it will use software SPI.

Here's my code about SPI configuration, actually I referred to the example code:

void SPI_Init(void){
    InitSpiaGpio();
    SpiaRegs.SPIFFTX.all=0xE040;
    SpiaRegs.SPIFFRX.all=0x204f;
    SpiaRegs.SPIFFCT.all=0x0;                //delay=0
    SpiaRegs.SPICCR.all =0x0007;                 // Reset on, rising edge, 8-bit char bits
    SpiaRegs.SPICTL.all =0x0006;                 // Enable master mode, normal phase,
                                                     // enable talk, and SPI int disabled.
    SpiaRegs.SPIBRR =0x007F;
    SpiaRegs.SPICCR.all =0x0087;                 // Relinquish SPI from Reset
    SpiaRegs.SPIPRI.bit.FREE = 1;                // Set so breakpoints don't disturb xmission
}

void SPI_WriteData_Hardware(unsigned char Data){
    Uint16 temp,clear;
    temp=Data;
    SpiaRegs.SPITXBUF=(temp<<8);
    while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
    clear=SpiaRegs.SPIRXBUF;
}

The problem is that when I build the project, ccs will give a warning:

variable "clear" was set but never used.

In fact, when I run it step by step, the program can run the last step in function SPI_WriteData_Hardware. But the lcd still cannot display. I thought SPI maybe where the problem is.

Could you help me? Thanks so much.

 

  • Now I find something new.
    If I run the program not step by step( and without a breakpoint) for a while enough and suspend it, then when I reset and run it step by step(there is a breakpoint when it starts to initialize the lcd,that where it suspend and I run the next few WriteData functions step by step) again the variable "clear" will never be used and program will always loop.

    PS: main function is posted below

    #include "DSP28x_Project.h"
    #include "TFT.h"
    #include "font.h"
    #include "spi.h"

    void main(void) {
    InitSysCtrl();
    DINT;
    InitPieCtrl();
    IER=0x0000;
    IFR=0x0000;
    InitPieVectTable();
    TFT_Init();
    TFT_Clear(BLACK);
    while(1){
    TFT_DrawString_16(0,30,WHITE,BLACK,"V" );
    }
    }
  • Hello,

    The warning about the variable "clear" is safe to ignore. The compiler doesn't know that you're just using it to do a dummy read of RX buffer and since SpiaRegs is volatile, you shouldn't have to worry about that line getting optimized out.

    I'm not seeing anything wrong with the code you've shared. Since you're only sending one byte at a time, the use of the FIFO isn't really necessary, but I don't think there's anything wrong with it either.

    How are you configuring the pins you want to use as SPI pins? Maybe the problem is there.

    Whitney
  • Hi Whitney,

    Thank you for your reply.

    The use of FIFO is in case for my carefulness while configuring SPI. :)

    InitSpia() set GPIO16 to 19 as SPI and 2 pins of my TFT have to be connected to SPI. They are:
    SDA and SCL(other pins such as RST, RS, CS have been connected to other GPIO to meet their electrical level)

    GPIO16(SPISIMOA)->SDA
    GPIO17(SPISOMIA)->GND(because I think no data has to be sent back)
    GPIO18(SPISCKA)->SCL
    GPIO19(SPISTEA) suspended

    I know that SPISTEA is usually used as chip selection signal. But since I am not familiar with SPI, I choose to suspend it).

    Do I need to do something more for the configuration of SPI pins apart from what I have done in function SPI_Init?


    Sherry
  • Hi Sherry,

    So you are calling InitSpia() in TFT_Init()?

    I don't understand what you mean by SPISTEA being "suspended." Are you connecting CS to a GPIO instead and asserting it when you're sending data or is it tied to a constant value?

    Thanks,
    Whitney
  • Hi,

    Yes, I am calling InitSpia() in TFT_Init().

    Other pins was connected to GPIO pins which are configured as general purpose output. For example, RST is connected GPIO15 and if I need to reset TFT I write the command " GpioDataRegs.GPASET.bit.GPIO15=1".

    Thanks for your patience!

    Sherry
  • Hi Sherry,

    What about CS? When do you toggle CS?

    Thanks,

    Whitney

  • Hi Whitney,

    CS connected to an GPIO which is always at low level.

    Thanks,

    Sherry
  • Sherry,

    That doesn't seem right to me. What does the datasheet for your LCD say about CS and how it should be asserted? Have you tried connecting it to SPISTEA?

    Thanks,
    Whitney