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/TM4C123GH6PM: TM4C123GH6PM+NOKIA 5110 +SPI

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

I am trying to interface nokia5110 with tiva  USING SPI .

Its not working below is the code . 

Help me in this...........any changes 

#include <stdint.h>
#include <stdbool.h>

#include <inc/hw_memmap.h>
#include <inc/hw_types.h>

#include <driverlib/gpio.h>
#include <driverlib/sysctl.h>
#include <driverlib/pin_map.h>
#include <driverlib/ssi.h>

#define LCD_PIN_CLK GPIO_PIN_2 //used by the SSI module
#define LCD_PIN_RST GPIO_PIN_3
#define LCD_PIN_DnC GPIO_PIN_4
#define LCD_PIN_DIN GPIO_PIN_5 //used by the SSI module
//#define LCD_PIN_BL GPIO_PIN_6
#define LCD_PIN_SCE GPIO_PIN_7

#define LCD_PIN_HIGH 0xff
#define LCD_PIN_LOW 0x00

void LCDWriteCmd(uint8_t u8Cmd)
{
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_DnC, LCD_PIN_LOW);
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_SCE, LCD_PIN_LOW);
SSIDataPut(SSI0_BASE, ((uint32_t) u8Cmd));
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_SCE, LCD_PIN_HIGH);
}

void LCDWriteDat(uint8_t u8Data)
{
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_DnC, LCD_PIN_HIGH);
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_SCE, LCD_PIN_LOW);
SSIDataPut(SSI0_BASE, ((uint32_t) u8Data));
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_SCE, LCD_PIN_HIGH);
}

int main(void)
{
//Clock configuration
SysCtlClockSet(SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_SYSDIV_4 | SYSCTL_XTAL_16MHZ);

//Enable GPIOA and SSI eripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//Configure GPIO pins (RST, DnC, BL, SCE) as output
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_7);

//Enable pin PA2 for SSI0 SSI0CLK
GPIOPinConfigure(GPIO_PA2_SSI0CLK);
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2);

//Enable pin PA5 for SSI0 SSI0TX
GPIOPinConfigure(GPIO_PA5_SSI0TX);
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5);

//COnfigures SSI module
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0 , SSI_MODE_MASTER,1000000, 8);
SSIEnable(SSI0_BASE);

//Applies reset signal
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_RST, LCD_PIN_HIGH);
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_RST, LCD_PIN_LOW);
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_RST, LCD_PIN_HIGH);

//SCE line goes low
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_SCE, LCD_PIN_LOW);
//Selects command mode
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_DnC, LCD_PIN_LOW);
//Selects extended instruction set
SSIDataPut(SSI0_BASE, ((uint32_t) 0x21));
//Set Vop
SSIDataPut(SSI0_BASE, ((uint32_t) 0x90));
//Selects normal instruction set
SSIDataPut(SSI0_BASE, ((uint32_t) 0x20));
//Puts display on normal mode
SSIDataPut(SSI0_BASE, ((uint32_t) 0x0c));

//Selectes data mode
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_DnC, LCD_PIN_HIGH);
//Write some data (uppercase letters P and H)
SSIDataPut(SSI0_BASE, ((uint32_t) 0x1f));
SSIDataPut(SSI0_BASE, ((uint32_t) 0x05));
SSIDataPut(SSI0_BASE, ((uint32_t) 0x07));
SSIDataPut(SSI0_BASE, ((uint32_t) 0x00));
SSIDataPut(SSI0_BASE, ((uint32_t) 0x1f));
SSIDataPut(SSI0_BASE, ((uint32_t) 0x04));
SSIDataPut(SSI0_BASE, ((uint32_t) 0x1f));

//Selects command mode
GPIOPinWrite(GPIO_PORTA_BASE, LCD_PIN_DnC, LCD_PIN_LOW);
//Sets inverse video mode
SSIDataPut(SSI0_BASE, ((uint32_t) 0x0d));
//Set X address to 0000000
SSIDataPut(SSI0_BASE, ((uint32_t) 0x80));
//Data write
SSIDataPut(SSI0_BASE, ((uint32_t) 0x00));

while(1)
{

}
}

  • Hi,
    Please elaborate what is not working. I don't spot anything wrong with your code. As a matter of fact, I can run your code and see SPICLK and TX toggling. Therefore, from the MCU side the SSI is operating according to your commands.

    If the problem is that your external SPI device is not receiving the proper commands then you need to use the scope to capture the waveform and debug if the MCU is meeting the timing (baud rate, , setup/hold time) and protocol (polarity, phase, chip select and etc) as expected by the slave.
  • Hi,
    I have not heard back from you. As I mentioned earlier, I don't spot anything wrong with your code and i was able to run your code as is and see the the SPI transactions on the board. This is proving that the MCU is working as is. On the system side, you will need to debug if your slave is properly receiving the data from the master and if all timing (baud rate, setup/hold time) and protocol (polarity, phase, chip select and etc) are met to your slave. I will close the thread for now. If you have new questions you can open a new thread or reply back to this if you have some updates to share.
  • thank you charles .