This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

3- Wire SPI with 9 bit frame to use LCD

Hi,

We have chose LCD which has only 3-Wire support CS, CLK and DI so we have connected that pins with nRF51822 chipset. Now Please see the below image which shows that we have to add 1 bit in 8-bit SPI to identify the Command or Data by the LCD.

I have checked the APIs in SDK but didn't find right solution for this.

So request you to guide in this case.

Thanks in advance

Sachin 

  • If you can work without background transfer the Nordic driver can provide, and without knowing details of LCD timing demands,  I would suggest that you

    1) Configure SPI driver without CS

    2) Create an SPIwrite function to send a byte  to the LCD. In that function

    • set MOSI low if command, high if parameter
    • Toggle SCLK
    • send byte of data using spi
    • detect end of transmit and raise CS

    While not exactly the same, I had implemented something similar  for four wire lcd operation where command/data is denoted by state of the fourth line. In that instance I simple set/cleared the 4th line after CS and before SPI TX whereas you'll need to set the MOSI line and pulse the SCLK. You should be able to do that because I think even when a pin is assigned to SPI you can still do base GPIIO functions on those lines. As long as there are no timing restrictions in the LCD, doing it in this bitbang mode should work for you.

  • So assuming you are setting a large number of pixels what I did is break up data into 8 bytes.  That is for every 8 bytes of pixel data I send 9 bytes through the SPI.   This works great for setting pixels, but still bit bang register settings. 

    What I do is insert the 'command/data' bits into the data stream for example I send 16bit color data, so if I want to set 4 pixels I need to send 72bit (9 bytes). 

    uint8_t data[9];

    set_spi_data(color,data);

    static void set_spi_data(color_t color,uint8_t *ptrData)
    {
    uint32_t i;
    int j=15;
    memset(ptrData,0,9);
    for(i=0; i<(9*8); i++)
    {
    uint8_t byte,bit;
    byte=i/8;
    bit=7-i%8;

    if ((i%9)==0)
    {
    ptrData[byte]|=(0x01)<<bit;
    }else
    {
    if ((uint32_t)color & 0x01ul<<j)
    {
    ptrData[byte]|=(0x01)<<bit;
    }
    j--;
    if (j<0)
    {
    j=15;
    }
    }
    }
    }

Related