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/F28M36P63C2: C28 SPI interfacing with LCD

Part Number: F28M36P63C2
Other Parts Discussed in Thread: CONTROLSUITE

Tool/software: Code Composer Studio

Hello,

I am trying to write a SPI Transfer function to write data onto an Crystalfontz OFAL1602C OLED. This is how i am writing the SPI transfer function, i am transferring 10 bits in each transfer because that's how the OLED driver WS0012 operates in spi mode.

void SPI_Transfer (Uint8 type,Uint8 value)
{
    EALLOW;
   
    GpioG1DataRegs.GPADAT.bit.GPIO19=0;  //Enable the active low slave select pin on the LCD to start communication



     if(DATA==type)          //Set the data(1)/command(0) flag
     {   
           SpiaRegs.SPITXBUF=1;  //Set MOSI high
           while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { }
           dummy5 = SpiaRegs.SPIRXBUF;
     }
     else
     {
           SpiaRegs.SPITXBUF=0;  //Pull MOSI Low
           while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { }
           dummy5 = SpiaRegs.SPIRXBUF;
     }

    //Clock it in.
     GpioG1DataRegs.GPADAT.bit.GPIO18=0;
     GpioG1DataRegs.GPADAT.bit.GPIO19=1;

    //Clear the read(1)/write(0) flag to write

       SpiaRegs.SPITXBUF=0;  // Pull MOSI Low because you're always writing to the LCD , not reading from it.
       while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { }
       dummy3 = SpiaRegs.SPIRXBUF;

    //Clock in the data
     GpioG1DataRegs.GPADAT.bit.GPIO18=0;
     GpioG1DataRegs.GPADAT.bit.GPIO18=1;

       for(mask=0x80;mask;mask>>=1)
        {
           if(mask & value)

             {
               SpiaRegs.SPITXBUF=1;       // if true, SET MOSI High
               while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { }
               dummy4 = SpiaRegs.SPIRXBUF;
           }
           else

             {
               SpiaRegs.SPITXBUF=0;                //if false, PULL MOSI low
               while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { }
               dummy5 = SpiaRegs.SPIRXBUF;
           }

             //CLOCK IT IN
             GpioG1DataRegs.GPADAT.bit.GPIO18=0;
             GpioG1DataRegs.GPADAT.bit.GPIO18=1;
           }


   // Disable the Active low Slave select pin and end communication for one cycle
       GpioG1DataRegs.GPADAT.bit.GPIO19=1;
 
       EDIS;
}

I am looking at the oscilloscope output for the SPI-A pins on the DSP board and i am getting correct outputs on the SPI-STEA signal and SPI-CLK signal. But i don't see any outputs on my MOSI pin.

What am i doing wrong?? Any suggestion or help is greatly appreciated. I have also included my spi init and config function below,

void InitSpi(void)
{
    // Initialize SPI-A

    // Set reset low before configuration changes
    // Clock polarity (0 == rising, 1 == falling)
    // 16-bit character
    //** Enable loop-back
    SpiaRegs.SPICCR.bit.SPISWRESET = 0;
    SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;
    SpiaRegs.SPICCR.bit.SPICHAR = (10-1) ;
    SpiaRegs.SPICCR.bit.SPILBK = 0; //disable loopback

    // Enable master (0 == slave, 1 == master)
    // Enable transmission (Talk)
    // Clock phase (0 == normal, 1 == delayed)
    // SPI interrupts are disabled
    SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1;//In Master mode
    SpiaRegs.SPICTL.bit.TALK = 1; //Enable transmission
    SpiaRegs.SPICTL.bit.CLK_PHASE = 0; //phase normal for the clock
    SpiaRegs.SPICTL.bit.SPIINTENA = 0; //Disable Spi interrupts

    // Set the baud rate
    SpiaRegs.SPIBRR = SPI_BRR; //baud rate for SPI

    // Set FREE bit
    // Halting on a breakpoint will not halt the SPI
    SpiaRegs.SPIPRI.bit.FREE = 1;

    // Release the SPI from reset
    SpiaRegs.SPICCR.bit.SPISWRESET = 1;
}

void InitSpiaGpio()
{

    EALLOW;

/* Enable internal pull-up for the selected pins */

// Pull-up enable should be set in the
// GPIO_O_PUR register in the M3 code.

/* Set qualification for selected pins to asynch only */

// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

    GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
    GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
    GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA)
    GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)

//    GpioCtrlRegs.GPBQSEL2.bit.GPIO54 = 3; // Asynch input GPIO16 (SPISIMOA)
//    GpioCtrlRegs.GPBQSEL2.bit.GPIO55 = 3; // Asynch input GPIO17 (SPISOMIA)
//    GpioCtrlRegs.GPBQSEL2.bit.GPIO56 = 3; // Asynch input GPIO18 (SPICLKA)
//    GpioCtrlRegs.GPBQSEL2.bit.GPIO57 = 3; // Asynch input GPIO19 (SPISTEA)

/* Configure SPI-A pins using GPIO regs*/

// This specifies which of the possible GPIO pins will be SPI functional pins.
// Comment out other unwanted lines.

    GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
    GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
    GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
    GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEA

//    GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 1; // Configure GPIO54 as SPISIMOA
//    GpioCtrlRegs.GPBMUX2.bit.GPIO55 = 1; // Configure GPIO55 as SPISOMIA
//    GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 1; // Configure GPIO56 as SPICLKA
//    GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 1; // Configure GPIO57 as SPISTEA

    EDIS;
}

Thank you,

Srini

  • Srinivasan,

    I don't think your transmit function is doing what you are expecting.

    Please refer to the SPI examples in controlSUITE for the F28M36 device for how the SPI operates.

    I am assuming that you are trying to transmit data to the LCD. writing a 1 to the TSPIXBUF will transmit 0 on SIMO in your current configuration. if you are writing 1 to SPITXBUF and the SPI is configured to transmit 10 bits, it will actually only send 0's as the data should be left justified. You are writing 0x0001 to SPITXBUF.  As SPI expects left-justified data if transmitting less than 16 bits, it will just shift out the upper 10 bits, which are all 0's in your case. I also never see where you are actually writing the data to the SPI in order for it to be transmitted.

    Finally, why are you writing to GPIO18 to "CLOCK IT IN" and then  additionally writing to GPIO19. These pins are assigned to the SPI functions when you call InitSpiaGpio. The SPI will control the Clock and chip select without any CPU intervention. Writing to SPITXBUF will start the next transfer, SPISTE will be driven as configured and the clock will begin to toggle as the data is being put on SIMO and latched in on SOMI.

    Please read through the SPI chapter in the TRM and study the example code provided in controlSUITE. These resources provide the foundation that you need in order to understand and use the SPI module on the F28M36x.

    Side note: please use the Insert Code feature in the rich text editor in the future to share code. It preserves C syntax highlighting and makes it much easier to read. 

    Regards,

    Mark

  • Hello Mark,

    Thank you very much, that helped understand a lot of things i am doing incorrectly and i will keep them in mind. And i apologize, i will keep in mind to post the code the right way in the future.

    I am essentially trying to send 10 bits in one spi transfer. i am calling this function repeatedly in several other functions pertaining to LCD design and operation.

    I have one query though based on your explanation, Let's say i want to transmit the following 10 bits in order
    1000000011
    and i want to put them in the TX buffer one at a time starting from the MSB. To do this should i send the MSB first left justified by 15,
    then the next bit left justified by 14, then the bit after that left justified by 13 ..so on until i reach the LSB is shifted left by 6?? Have i understood you right?

    Again i want to stress that i have read the SPI chapter in the manual and simulated the examples in the control suite but perhaps i haven't understood them well enough. I greatly appreciate your time. I will look into them with greater detail and see what i have missed.

    Srini

  • Thanks Mark, i made it work. Appreciate your time and help.
  • Hi Srini,
    You do not have to send each bit by itself you can send all 10 bits at once and just left justify the entire thing by six bits. The SPIDAT will take care of sending out every bit to the SPIRXBUF.

    Does this make more sense?

    Regards,
    Marlyn
  • Yes, Marylyn. I figured it out and it works. Thank you very much