Jump to content
43oh

ILI9341 Display on MSP432 with SPI


Recommended Posts

Hi,
 
I'm struggling to get the the ILI9341 display to work on a MSP432.
 
I've used it on an arduino with this display driver, so I figured that would be a good start for the porting.
 
This display is setup to use SPI (SCK,MISO,MOSI, CS,DC). I understand this is called 4 wire SPI?
 
The following is the code used to init the SPI is this correct?
 
 

    GPIO_setAsOutputPin(LCD_RESET_PORT,
                        LCD_RESET_PIN);

    GPIO_setOutputLowOnPin(LCD_RESET_PORT,
                           LCD_RESET_PIN);

    GPIO_setAsOutputPin(LCD_DC_PORT,
                        LCD_DC_PIN);

    GPIO_setOutputLowOnPin(LCD_DC_PORT,
                           LCD_DC_PIN);

    GPIO_setAsOutputPin(LCD_SPI_CS_PORT,
                        LCD_SPI_CS_PIN);

    GPIO_setOutputLowOnPin(LCD_SPI_CS_PORT,
                           LCD_SPI_CS_PIN);

    //
    // Configure SPI peripheral.
    //
	GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SPI_MOSI_PORT,
                                                LCD_SPI_MOSI_PIN,
                                                LCD_SPI_MOSI_PIN_FUNCTION);

	GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SPI_MISO_PORT,
                                                LCD_SPI_MISO_PIN,
                                                LCD_SPI_MISO_PIN_FUNCTION);

	GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SPI_CLK_PORT,
    											LCD_SPI_CLK_PIN,
                                                LCD_SPI_CLK_PIN_FUNCTION);

    eUSCI_SPI_MasterConfig spiMasterConfig =
    {
        EUSCI_B_SPI_CLOCKSOURCE_SMCLK,                      // SMCLK Clock Source
        CS_getSMCLK(),                                  // Get SMCLK frequency
        15000000,                                                // SPICLK = 15 MHz
        EUSCI_B_SPI_MSB_FIRST,                             // MSB First
        EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,         // Phase
        EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW,         // Low polarity
	EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH                                   // SPI Mode
    };

    //EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH
    //EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_LOW

    SPI_initMaster(LCD_EUSCI_MODULE, &spiMasterConfig);
    SPI_enableModule(LCD_EUSCI_MODULE);

    SPI_clearInterruptFlag(LCD_EUSCI_MODULE,  EUSCI_B_SPI_RECEIVE_INTERRUPT);

The code i'm unsure about is:

- GPIO_setAsPeripheralModuleFunctionOutputPin

Should SCK, MOSI, MISO all be set as output or input?

 

- EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW

Not really sure what this means is it correct?

 

- EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT

Not really sure what this means is it correct?

 

-EUSCI_B_SPI_4PIN_UCxSTE_ACTIVE_HIGH

Not really sure what this means is it correct?

 

- SPI_clearInterruptFlag(LCD_EUSCI_MODULE, EUSCI_B_SPI_RECEIVE_INTERRUPT);

I'm not using interrupts should I remove this line?

 
Board: MSP432 Launchpad
 
Datasheet:
http://www.adafruit.com/datasheets/ILI9341.pdf

Link to post
Share on other sites

If you've already used this display with Arduino, why don't you give Energia a try?

 

Energia is a fork of Arduino for the LaunchPads. As long as the code calls the Arduino libraries as SPI, Wire, Serial et al, all Arduino sketches run on Energia.

 

What is the exact reference of your screen? There are many libraries available here: see RobG's (Universal) Coluor LCD graphics library and my LCD_screen Library Suite.

 

Link to post
Share on other sites

I worked it out,

 

This display uses 4 wires, although its a 3 wire SPI, 4 wire SPI is for 2 masters in the SPI system. This Display has an extra wire for Data or Command, this is not part of the SPI just a switch for the Display. In the Datasheet its called 4 waire SPI this is not correct!

 

I also had the Phase of the SPI incorrect.

 

SPI code for anyone with this issue.

    //
    // Configure SPI peripheral.
    //
	GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SPI_MOSI_PORT,
                                                LCD_SPI_MOSI_PIN,
                                                LCD_SPI_MOSI_PIN_FUNCTION);

	GPIO_setAsPeripheralModuleFunctionInputPin(LCD_SPI_MISO_PORT,
                                                LCD_SPI_MISO_PIN,
                                                LCD_SPI_MISO_PIN_FUNCTION);

	GPIO_setAsPeripheralModuleFunctionOutputPin(LCD_SPI_CLK_PORT,
    											LCD_SPI_CLK_PIN,
                                                LCD_SPI_CLK_PIN_FUNCTION);

    eUSCI_SPI_MasterConfig spiMasterConfig =
    {
        EUSCI_B_SPI_CLOCKSOURCE_SMCLK,                      		// SMCLK Clock Source
        CS_getSMCLK(),                                  			// Get SMCLK frequency
        15000000,                                                	// SPICLK = 15 MHz
        EUSCI_B_SPI_MSB_FIRST,                             			// MSB First
		EUSCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT, 	// Phase //  EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT
        EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW,         			// Low polarity
		EUSCI_B_SPI_3PIN                                   			// SPI Mode
    };

    SPI_initMaster(LCD_EUSCI_MODULE, &spiMasterConfig);
    SPI_enableModule(LCD_EUSCI_MODULE);

    SPI_clearInterruptFlag(LCD_EUSCI_MODULE,  EUSCI_B_SPI_RECEIVE_INTERRUPT);

P.S The reason I don't want to use Energia is I don't like the IDE!

Link to post
Share on other sites

P.S The reason I don't want to use Energia is I don't like the IDE!

 

Neither do I  :) 

 

Another solution is to keep the Energia framework and to use a better IDE, with all the modern amenities.

 

I'm using and I recommend

Both comes with two versions: one free with all the standard features, one paid for more advanced features like debugging. You'll find pointers at Looking for a Better IDE.

 

Other solutions include

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...