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.

TMS320F28069: 8 BIT SPI read /Write On SSD1309 OLED Controller

Part Number: TMS320F28069

I am trying to Setup OLED 1309 OLED Controller using TMS320F28069M Launchpad , For that Purpose I am using Example_2806xSpi_FFDLB.c Which Containg the Following Code

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

//
// Function Prototypes
//
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
void error(void);

//
// Main
//
void main(void)
{
    Uint16 sdata;  // send data
    Uint16 rdata;  // received data

    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2806x_SysCtrl.c file.
    //
    InitSysCtrl();

    //
    // Step 2. Initalize GPIO: 
    // This example function is found in the F2806x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
    //InitGpio();  // Skipped for this example  
    
    //
    // Setup only the GP I/O only for SPI-A functionality
    // This function is found in F2806x_Spi.c
    //
    InitSpiaGpio();

    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts 
    //
    DINT;

    //
    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.  
    // This function is found in the F2806x_PieCtrl.c file.
    //
    InitPieCtrl();

    //
    // Disable CPU interrupts and clear all CPU interrupt flags
    //
    IER = 0x0000;
    IFR = 0x0000;

    //
    // Initialize the PIE vector table with pointers to the shell Interrupt 
    // Service Routines (ISR).  
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2806x_DefaultIsr.c.
    // This function is found in F2806x_PieVect.c.
    //
    InitPieVectTable();

    //
    // Step 4. Initialize all the Device Peripherals:
    // This function is found in F2806x_InitPeripherals.c
    //
    //InitPeripherals(); // Not required for this example
    spi_fifo_init();	  // Initialize the Spi FIFO
    spi_init();		  // init SPI

    //
    // Step 5. User specific code:
    // Interrupts are not used in this example. 
    //
    sdata = 0x0000;							
    for(;;)
    {
        //        
        // Transmit data
        //
        spi_xmit(sdata);
        
        //
        // Wait until data is received
        //
        while(SpiaRegs.SPIFFRX.bit.RXFFST !=1)
        {
            
        }

        //        
        // Check against sent data
        //
        rdata = SpiaRegs.SPIRXBUF;				
        if(rdata != sdata)
        {
            error();
        }
        
        sdata++;
    }
} 	

//
// error - Step 7. Insert all local Interrupt Service Routines (ISRs) 
// and functions here
//
void
error(void)
{
    __asm("     ESTOP0");						// Test failed!! Stop!
    for (;;);
}

//
// spi_init - 
//
void
spi_init()
{    
    SpiaRegs.SPICCR.all =0x000F;  // Reset on, rising edge, 16-bit char bits  
    
    //
    // Enable master mode, normal phase, enable talk, and SPI int disabled.
    //
    SpiaRegs.SPICTL.all =0x0006;
   
    SpiaRegs.SPIBRR =0x007F;									
    SpiaRegs.SPICCR.all =0x009F;   // Relinquish SPI from Reset   
    SpiaRegs.SPIPRI.bit.FREE = 1;  // Set so breakpoints don't disturb xmission
}

//
// spi_xmit - 
//
void
spi_xmit(Uint16 a)
{
    SpiaRegs.SPITXBUF=a;
}    

//
// spi_fifo_init - 
//
void
spi_fifo_init(void)										
{
    //
    // Initialize SPI FIFO registers
    //
    SpiaRegs.SPIFFTX.all=0xE040;
    SpiaRegs.SPIFFRX.all=0x2044;
    SpiaRegs.SPIFFCT.all=0x0;
}  

//
// End of File
//

Now, the quest is how to set the SPI in 8 bit mode, I found some examples over the forums but nothing seems to be fruitful.

  • Ashkar,

    Ashkar Malik48 said:
    Now, the quest is how to set the SPI in 8 bit mode, I found some examples over the forums but nothing seems to be fruitful.

    In the spi_init() function, the write to SPICCR is setting the data bit size and other parameters. In this case, the SPICHAR bit field is set to 0xF which means 16-bit data. Setting SPICHAR=07h will set the data size to 8-bit. Please refer to the SPI chapter, register section, in the F2806x technical reference manual for more information. 

    Ashkar Malik48 said:
    I am trying to Setup OLED 1309 OLED Controller using TMS320F28069M Launchpad

    I'm not familiar with this particular OLED controller, but I advice you leverage a code example off the web, if you can find one. This will save you some time learning about the controller commands and setup. Below is a forum post I wrote with some example code (not for the OLED you are using) to give you some  idea.

    https://e2e.ti.com/support/microcontrollers/c2000/f/171/p/893612/3307824

  • #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    #include "F2806x_Device.h"
    //
    // Function Prototypes
    //
    void oledCommand( Uint8 ch );
    void oledDisplayOffset( Uint8 offset );
    void oledData( Uint8 data );
    void oledGotoYX(unsigned char Row, unsigned char Column);
    void oledPutChar( char ch );
    void oledPutHexa( unsigned int Var );
    void oledPutDec( unsigned int Var );
    void oledPrint( char *s );
    void oledClear();
    void oledInit();
    void spi_xmit(Uint16 a);
    void spi_init(void);
    void error(void);
    void GPIO_INITIALIZE();
    void msdelay(Uint16 msdelay);
    void SPI_sendData(Uint16 data);
    void SPI_sendCommand(Uint16 command);
    
    #define LCD_RST_LO GpioDataRegs.GPADAT.bit.GPIO0 = 0 // RST HI
    #define LCD_CS_LO  GpioDataRegs.GPADAT.bit.GPIO1 = 0 // CS  HI
    #define LCD_DC_LO  GpioDataRegs.GPADAT.bit.GPIO2 = 0 // DC  HI
    #define LCD_RST_HI GpioDataRegs.GPADAT.bit.GPIO0 = 1 // RST HI
    #define LCD_CS_HI  GpioDataRegs.GPADAT.bit.GPIO1 = 1 // CS  HI
    #define LCD_DC_HI  GpioDataRegs.GPADAT.bit.GPIO2 = 1 // DC  HI
    
    #define SSD1308_Command_Mode            0x80
    #define SSD1308_Data_Mode               0x40
    #define SSD1308_Display_Off_Cmd         0xAE
    #define SSD1308_Display_On_Cmd          0xAF
    #define SSD1308_Normal_Display_Cmd      0xA6
    #define SSD1308_Inverse_Display_Cmd     0xA7
    #define SSD1308_Activate_Scroll_Cmd     0x2F
    #define SSD1308_Dectivate_Scroll_Cmd    0x2E
    #define SSD1308_Set_Brightness_Cmd      0x81
    
    void oledInit()
    {
    // olex way :
    #define OLED_SETCONTRAST 0x81
    #define OLED_DISPLAYALLON_RESUME 0xA4
    #define OLED_DISPLAYALLON 0xA5
    #define OLED_NORMALDISPLAY 0xA6
    #define OLED_INVERTDISPLAY 0xA7
    #define OLED_DISPLAYOFF 0xAE
    #define OLED_DISPLAYON 0xAF
    #define OLED_SETDISPLAYOFFSET 0xD3
    #define OLED_SETCOMPINS 0xDA
    #define OLED_SETVCOMDETECT 0xDB
    #define OLED_SETDISPLAYCLOCKDIV 0xD5
    #define OLED_SETPRECHARGE 0xD9
    #define OLED_SETMULTIPLEX 0xA8
    #define OLED_SETLOWCOLUMN 0x00
    #define OLED_SETHIGHCOLUMN 0x10
    #define OLED_SETSTARTLINE 0x40
    #define OLED_MEMORYMODE 0x20
    #define OLED_COLUMNADDR 0x21
    #define OLED_PAGEADDR   0x22
    #define OLED_COMSCANINC 0xC0
    #define OLED_COMSCANDEC 0xC8
    #define OLED_SEGREMAP 0xA0
    #define OLED_CHARGEPUMP 0x8D
    
        SPI_sendCommand( OLED_DISPLAYOFF );
        msdelay( 100 );
        SPI_sendCommand( OLED_SETDISPLAYCLOCKDIV );
        SPI_sendCommand( 0x80 );   // the suggested ratio 0x80
        msdelay( 100 );
        SPI_sendCommand( OLED_SETMULTIPLEX );
        SPI_sendCommand( 0x1F );
        msdelay( 100 );
        SPI_sendCommand( OLED_SETDISPLAYOFFSET );
        SPI_sendCommand( 0x0 );   // no offset
        msdelay( 100 );
        SPI_sendCommand(OLED_SETSTARTLINE | 0x0); // line #0
        msdelay( 100 );
        SPI_sendCommand( OLED_CHARGEPUMP );
        SPI_sendCommand( 0xAF );
        msdelay( 100 );
        SPI_sendCommand( OLED_MEMORYMODE );
        SPI_sendCommand( 0x0 );  // 0x0 act like ks0108
        msdelay( 100 );
                     // 0x0 act like ks0108
        SPI_sendCommand(OLED_SEGREMAP | 0x1);
        SPI_sendCommand(OLED_COMSCANDEC);
        SPI_sendCommand(OLED_SETCOMPINS);         // 0xDA
        SPI_sendCommand(0x02);
        SPI_sendCommand(OLED_SETCONTRAST);        // 0x81
        SPI_sendCommand(0x8F);
        SPI_sendCommand(OLED_SETPRECHARGE);       // 0xd9
        SPI_sendCommand(0xF1);
        SPI_sendCommand(OLED_SETVCOMDETECT);      // 0xDB
        SPI_sendCommand(0x40);
        SPI_sendCommand(OLED_DISPLAYALLON_RESUME);// 0xA4
        SPI_sendCommand(OLED_NORMALDISPLAY);      // 0xA6
        SPI_sendCommand(OLED_DISPLAYON);          //--turn on oled panel
    
    
    }
    
    const Uint8 OledFont[][8] =
    {
      {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
      {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00},
      {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00},
      {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00},
      {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00},
      {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00},
      {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00},
      {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00},
      {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00},
      {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00},
      {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00},
      {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00},
      {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00},
      {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00},
      {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00},
      {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00},
      {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00},
      {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00},
      {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00},
      {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00},
      {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00},
      {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00},
      {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00},
      {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00},
      {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00},
      {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00},
      {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00},
      {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00},
      {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00},
      {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00},
      {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00},
      {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00},
      {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00},
      {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00},
      {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00},
      {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00},
      {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00},
      {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00},
      {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00},
      {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00},
      {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00},
      {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00},
      {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00},
      {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00},
      {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00},
      {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00},
      {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00},
      {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00},
      {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00},
      {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00},
      {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00},
      {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00},
      {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00},
      {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00},
      {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00},
      {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00},
      {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00},
      {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00},
      {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00},
      {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00},
      {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00},
      {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00},
      {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00},
      {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00},
      {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00},
      {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00},
      {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00},
      {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00},
      {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00},
      {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00},
      {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00},
      {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00},
      {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00},
      {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00},
      {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00},
      {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00},
      {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00},
      {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00},
      {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00},
      {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00},
      {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00},
      {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00},
      {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00},
      {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00},
      {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00},
      {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00},
      {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00},
      {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00},
      {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00},
      {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00},
      {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00},
      {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00},
      {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00},
      {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00},
      {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00},
      {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00}
    };
    void GPIO_INITIALIZE()
    {
        EALLOW;
        GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;   // Enable pullup on GPIO8
        GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;  // GPIO8 = GPIO8
        GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
    
        GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0;   // Enable pullup on GPIO8
        GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0;  // GPIO8 = GPIO8
        GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;
    
        GpioCtrlRegs.GPAPUD.bit.GPIO2 = 0;   // Enable pullup on GPIO8
        GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;  // GPIO8 = GPIO8
        GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
    
        EDIS;
    }
    
    void msdelay(Uint16 msdelay)
    {
        Uint16 i, j;
    
        for(j=0;j<1000;j++)
        {
            for(i=0;i<msdelay;i++)
            {
                asm(" NOP");
            }
        }
    }
    
    //============================================================================
    void SPI_sendCommand(Uint16 command)
      {
        Uint16 volatile dummy = 0;
       LCD_CS_LO;
      // Select the LCD controller
      LCD_DC_LO;
      //Send the command via SPI:
      spi_xmit(command<<8);
      dummy = SpiaRegs.SPITXBUF;
      // Deselect the LCD controller
      LCD_CS_HI;
      LCD_DC_HI;
      }
    
    //----------------------------------------------------------------------------
    void SPI_sendData(Uint16 data)
      {
        Uint16 volatile dummy = 0;
    
      // Select the LCD controller
      LCD_CS_LO;
      LCD_DC_HI;
      //Send the command via SPI:
      spi_xmit(data<<8);
    //
      dummy = SpiaRegs.SPITXBUF;
    
      LCD_CS_HI;
      LCD_DC_LO;
      }
    
    
    //
    // Main
    //
    void main(void)
    {
    
        InitSysCtrl();
    
        InitSpiaGpio();
        GPIO_INITIALIZE();
    
        DINT;
    
        InitPieCtrl();
    
        IER = 0x0000;
        IFR = 0x0000;
    
        InitPieVectTable();
    
        spi_init();		  // init SPI
        oledInit();
    
        for(;;)
        {
            SPI_sendData(0xf4);
            msdelay(1);
    
        }
    
    } 	
    
    //
    // error - Step 7. Insert all local Interrupt Service Routines (ISRs) 
    // and functions here
    //
    void
    error(void)
    {
        __asm("     ESTOP0");						// Test failed!! Stop!
        for (;;);
    }
    
    //
    // spi_init - 
    //
    void
    spi_init()
    {
        SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI
    
        SpiaRegs.SPICCR.all=0x0007;      // 16-bit character, Loopback mode
        SpiaRegs.SPICTL.all=0x0017; // Interrupt enabled, Master/Slave XMIT enabled
        SpiaRegs.SPISTS.all=0x0000;
        SpiaRegs.SPIBRR=0x0063;           // Baud rate
        SpiaRegs.SPIFFTX.all=0xC022;      // Enable FIFO's, set TX FIFO level to 4
        SpiaRegs.SPIFFRX.all=0x0022;      // Set RX FIFO level to 4
        SpiaRegs.SPIFFCT.all=0x00;
        SpiaRegs.SPIPRI.all=0x0010;
    
        SpiaRegs.SPICCR.bit.SPISWRESET=1;  // Enable SPI
    
        SpiaRegs.SPIFFTX.bit.TXFIFO=1;
        SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;
    }
    
    //
    // spi_xmit -
    //
    void
    spi_xmit(Uint16 a)
    {
        SpiaRegs.SPITXBUF=a;
    }
    
    
    void oledPutChar( char ch )
    {
    
    }
    
    void oledPutHexa( unsigned int Var )
    {
    int tmp;
                tmp=Var>>12 & 0x000F;
                if (tmp<=9)     tmp+=0x30;
                        else            tmp+=0x37;
                oledPutChar(tmp);
    
                tmp=Var>>8 & 0x000F;
                if (tmp<=9)     tmp+=0x30;
                        else            tmp+=0x37;
                oledPutChar(tmp);
    
                tmp=Var>>4 & 0x000F;
                if (tmp<=9)     tmp+=0x30;
                        else            tmp+=0x37;
                oledPutChar(tmp);
    
                tmp=Var & 0x000F;
                if (tmp<=9)     tmp+=0x30;
                        else            tmp+=0x37;
                oledPutChar(tmp);
    }
    
    void oledPutDec( unsigned int Var )
    {
    unsigned int k;
    unsigned char c;
    // Char
        k = Var;
        c = k/1000;
        if (c > 0)
            k = k - c*1000;
        oledPutChar(c + 0x30);
        c = k/100;
        if (c > 0)
            k = k - c*100;
        oledPutChar(c + 0x30);
        c = k/10;
        if (c > 0)
            k = k - c*10;
        oledPutChar(c + 0x30);
     // oledPutChar('.');
        oledPutChar(k + 0x30);
    }
    
    void oledPrint( char *s )
    {
        while (*s) oledPutChar( *s++);
    }
    void oledGotoYX(unsigned char Row, unsigned char Column)
    {
        SPI_sendCommand( 0xB0 + Row);
        SPI_sendCommand( 0x00 + (8*Column & 0x0F) );
        SPI_sendCommand( 0x10 + ((8*Column>>4)&0x0F) );
    }
    
    void oledClear()
    {
    Uint16 row, col;
        for ( row = 0; row < 8; row++ ) {
            for ( col = 0; col < 16; col++ ) {
                oledGotoYX( row, col );
                oledPutChar( ' ' );
            }
        }
    }
    
  • So I have stitched a working code for 8 bit SPI Communication,and Initialized a OLED Routine, But I am unable see anything on the display.

  • I have Changed SPI Addressing now So The Initialization code looks like this.

    void oledInit()
    {
        LCD_RST_HI;
        msdelay( 1000 );
        LCD_RST_LO;
        msdelay( 10000 );
        LCD_RST_HI;
    
        SPI_sendCommand( OLED_DISPLAYOFF );
        msdelay( 100 );
        SPI_sendCommand( OLED_SETDISPLAYCLOCKDIV );
        SPI_sendCommand( 0x80 );   // the suggested ratio 0x80
        msdelay( 100 );
        SPI_sendCommand( OLED_SETMULTIPLEX );
        SPI_sendCommand( 0x1F );
        msdelay( 100 );
        SPI_sendCommand( OLED_SETDISPLAYOFFSET );
        SPI_sendCommand( 0x0 );   // no offset
        msdelay( 100 );
        SPI_sendCommand(OLED_SETSTARTLINE | 0x0); // line #0
        msdelay( 100 );
        SPI_sendCommand( OLED_CHARGEPUMP );
        SPI_sendCommand( 0xAF );
        msdelay( 100 );
        SPI_sendCommand( OLED_MEMORYMODE );
        SPI_sendCommand( 0x0 );  // 0x0 act like ks0108
        msdelay( 100 );
                     // 0x0 act like ks0108
        SPI_sendCommand(OLED_SEGREMAP | 0x1);
        SPI_sendCommand(OLED_COMSCANDEC);
        SPI_sendCommand(OLED_SETCOMPINS);         // 0xDA
        SPI_sendCommand(0x02);
        SPI_sendCommand(OLED_SETCONTRAST);        // 0x81
        SPI_sendCommand(0x8F);
        SPI_sendCommand(OLED_SETPRECHARGE);       // 0xd9
        SPI_sendCommand(0xF1);
        SPI_sendCommand(OLED_SETVCOMDETECT);      // 0xDB
        SPI_sendCommand(0x40);
        SPI_sendCommand(OLED_DISPLAYALLON_RESUME);// 0xA4
        SPI_sendCommand(OLED_NORMALDISPLAY);      // 0xA6
        SPI_sendCommand(OLED_DISPLAYON);          //--turn on oled panel
    
    
    }
    
    //============================================================================
    void SPI_sendCommand(Uint16 command)
      {
        Uint16 volatile dummy = 0;
       LCD_CS_LO;
      // Select the LCD controller
      LCD_DC_LO;
      //Send the command via SPI:
      SpiaRegs.SPITXBUF=command<<8;
      dummy = SpiaRegs.SPITXBUF;
      // Deselect the LCD controller
      LCD_CS_HI;
      LCD_DC_HI;
      }
    
    //----------------------------------------------------------------------------
    void SPI_sendData(Uint16 data)
      {
        Uint16 volatile dummy = 0;
    
      // Select the LCD controller
      LCD_CS_LO;
      LCD_DC_HI;
      //Send the command via SPI:
      SpiaRegs.SPITXBUF=data<<8;
      dummy = SpiaRegs.SPITXBUF;
    
      LCD_CS_HI;
      LCD_DC_LO;
      }
    

    Still no display

    Send Data Function isnt sending anything on the MOSI PIN, It is always HIGH

  • Your SPI_sendCommand() and SPI_sendData() functions don't look right to me.

    On SPI_sendCommand(), LCD_CS_HI and LCD_DC_HI instructions will be executed in the middle of a SPI transfer because the CPU is not waiting for the SPI transfer to finish. If you refer to the sample code in the E2E post I referenced, the CPU will block until the SPI transfer is complete. Also, on this function, reading from SPITXBUF should be changed to read from the SPIRXBUF. The SPI_sendData() has the same issues.

  • void SPI_sendCommand(Uint16 command)
      {
        Uint16 volatile dummy = 0;
       LCD_CS_LO;
      LCD_DC_LO;
      SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path
      SpiaRegs.SPITXBUF = command; // Master transmits data
      while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Waits until data rx’d
      dummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself
      SpiaRegs.SPICTL.bit.TALK = 0; // Enable Transmit path
      LCD_CS_HI;
      LCD_DC_HI;
      }
    
    //----------------------------------------------------------------------------
    void SPI_sendData(Uint16 data)
      {
        Uint16 volatile dummy = 0;
    
      // Select the LCD controller
      LCD_CS_LO;
      LCD_DC_HI;
      SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path
      SpiaRegs.SPITXBUF = data; // Master transmits data
      while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Waits until data rx’d
      dummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself
      SpiaRegs.SPICTL.bit.TALK = 0; // Enable Transmit path
      LCD_CS_HI;
      LCD_DC_LO;
      }

    Thank you for pointing out the mistake, I have corrected the proposed error, Now I have put  while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} but I am bit confused on the Role of this register as it is been stuck at this place for ever.

    As Proposed under the datasheet I placed

      while(SpiaRegs.SPIFFTX.bit.TXFFINT !=1) {} 

    Instead of

    while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Waits until data rx’d

  • Ashkar,

    Below are the SPI read and write functions used in the reference project. I think these will help you fix your functions. Note that you want to block on the dummy read, not the write. Also, do not toggle the TALK bit, you can keep it set, unless you specifically want to disable the output buffer for some reason.

    //*****************************************************************************
    //
    //! Waits for the transmit buffer to empty and then writes data to it.
    //!
    //! \param base specifies the SPI module base address.
    //! \param data is the left-justified data to be transmitted over SPI.
    //!
    //! This function places the supplied data into the transmit buffer of the
    //! specified SPI module once it is empty. This function should not be used
    //! when FIFO mode is enabled.
    //!
    //! \note The data being sent must be left-justified in \e data. The lower
    //! 16 - N bits will be discarded where N is the data width selected in
    //! SPI_setConfig(). For example, if configured for a 6-bit data width, the
    //! lower 10 bits of data will be discarded.
    //!
    //! \return None.
    //
    //*****************************************************************************
    static inline void
    SPI_writeDataBlockingNonFIFO(uint32_t base, uint16_t data)
    {
        //
        // Check the arguments.
        //
        ASSERT(SPI_isBaseValid(base));
    
        //
        // Wait until the transmit buffer is not full.
        //
        while((HWREGH(base + SPI_O_STS) & SPI_STS_BUFFULL_FLAG) != 0U)
        {
        }
    
        //
        // Write data to the transmit buffer.
        //
        HWREGH(base + SPI_O_TXBUF) = data;
    }

    //*****************************************************************************
    //
    //! Waits for data to be received and then reads it from the buffer.
    //!
    //! \param base specifies the SPI module base address.
    //!
    //! This function waits for data to be received and then reads it from the
    //! receive buffer of the specified SPI module. This function should not be
    //! used when FIFO mode is enabled.
    //!
    //! \note Only the lower N bits of the value written to \e data contain valid
    //! data, where N is the data width as configured by SPI_setConfig(). For
    //! example, if the interface is configured for 8-bit data width, only the
    //! lower 8 bits of the value written to \e data contain valid data.
    //!
    //! \return Returns the word of data read from the SPI receive buffer.
    //
    //*****************************************************************************
    static inline uint16_t
    SPI_readDataBlockingNonFIFO(uint32_t base)
    {
        //
        // Check the arguments.
        //
        ASSERT(SPI_isBaseValid(base));
    
        //
        // Wait until data has been received.
        //
        while((HWREGH(base + SPI_O_STS) & SPI_STS_INT_FLAG) == 0U)
        {
        }
    
        //
        // Check for data to read.
        //
        return(HWREGH(base + SPI_O_RXBUF));
    }

  • As specified by you I have setup this Code for SPI Now, As I am using FIFO So I introduced the Following

    void SPI_sendCommand(Uint16 command)
      {
        Uint16 volatile dummy = 0;
       LCD_CS_LO;
       LCD_DC_LO;
    
       SpiaRegs.SPITXBUF = command<<8; // Master transmits data
       while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1)
       while(SpiaRegs.SPISTS.bit.INT_FLAG !=0) {} // Wait until data received
    
       LCD_CS_HI;
       LCD_DC_HI;
      }
    
    //----------------------------------------------------------------------------
    void SPI_sendData(Uint16 data)
      {
        Uint16 volatile dummy = 0;
    
      // Select the LCD controller
      LCD_CS_LO;
      LCD_DC_HI;
    
    
      SpiaRegs.SPITXBUF = data<<8; // Master transmits data
      while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG !=0)
      while(SpiaRegs.SPISTS.bit.INT_FLAG !=0) {} // Wait until data received
    
      LCD_CS_HI;
      LCD_DC_LO;
      }

    //---------------------------------------------------------------------------- void SPI_sendData(Uint16 data) { Uint16 volatile dummy = 0; // Select the LCD controller LCD_CS_LO; LCD_DC_HI; // SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path SpiaRegs.SPITXBUF = data<<8; // Master transmits data while(SpiaRegs.SPIFFTX.bit.TXFFINT !=1) {} // Waits until data rx’d dummy = SpiaRegs.SPIRXBUF; // Clears junk data from itself //SpiaRegs.SPICTL.bit.TALK = 0; // Enable Transmit path SpiaRegs.SPIFFTX.bit.TXFFINTCLR =1; LCD_CS_HI; LCD_DC_LO; }

  • Ashkar,

    This doesn't follow the reference code. Has it worked for you?

    Before trying with the FIFO, this is what I would suggest.

    void SPI_sendCommand(Uint16 command)
      {
        Uint16 volatile dummy = 0;
       LCD_CS_LO;
       LCD_DC_LO;
    
       while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG != 0){}  // Wait until TX buffer is not full
       SpiaRegs.SPITXBUF = command<<8; // Master transmits data
       while(SpiaRegs.SPISTS.bit.INT_FLAG ==0) {} // Wait until data received
       dummy = SpiaRegs.SPIRXBUF; // dummy read to clear INT flag
    
       LCD_CS_HI;
       LCD_DC_HI;
      }
    
    //----------------------------------------------------------------------------
    void SPI_sendData(Uint16 data)
      {
        Uint16 volatile dummy = 0;
    
      // Select the LCD controller
      LCD_CS_LO;
      LCD_DC_HI;
    
    
      while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG != 0){}  // Wait until TX buffer is not full
      SpiaRegs.SPITXBUF = data<<8; // Master transmits data
      while(SpiaRegs.SPISTS.bit.INT_FLAG ==0) {} // Wait until data received
      dummy = SpiaRegs.SPIRXBUF; // dummy read to clear INT flag
    
      LCD_CS_HI;
      LCD_DC_LO;
      }

  • After changing Your proposed Modification and some more changes in the SPI Clock
    Now the problem is the Spacing between the horizontal line is comming, That is , after every scan a row is comming out blank. I guess it might be due to 8 Bit Display problem.

    I was able to get the Following output.

  • That's great. It looks you now have SPI communication between the device and the LCD. The issue you point out is probably due to some bug in your firmware flow which is beyond the scope of this thread. Can we go ahead and close this thread? If you face any other C2000 related problem, you can open a new thread.

  • All thanks to you Gus, I appreciate your help.