Raspberry PI – MSP 430 – LCD

DEM16101 LCD unusable

No matter how hard I tried, I couldn't figure out how to use it.

I think I managed to talk to the KS066 controller correctly (I reliably reset the controller using the initialization sequence) but I could not figure out the voltage required to power the LCD.

It looks like the LCD might require negative voltage (it's the only way I managed to have the LCD show some character blocks) but I did not find working setting.

In the end I replaced it with a HD44780 LCD and things went fairly smoothly.

Raspberry PI - MSP 430 - LCD

MSP430 __delay_cycles

As part of trying to figure out why I could not initialize the DEM16101 I timed, using a scope, delays produced using __delay_cycles vs delays produced by using a timer interrupt.

Clock Method Time (expected) Time (measured)
1 MHz __delay_cycles(1) 1 us 2.2 us
8 MHz __delay_cycles(8) 1 us 1.1 us
1 MHz Timer_A interrupt 1 us 1.1 us

Since the LCD controller is not that sensitive to the delay's length (it requires minimum values) in the end i used __delay_cycles and did not bother with timer interrupts.

MSP430 to LCD HD44780

I've used the code here to get started: Interface MSP430 Launchpad with LCD Module (LCM) in 4 bit mode. However, since I had 3 P1 pins busy for the SPI serial connection, I had to use a different pinout.

Although P2.0 was free, the voltage it yields when set to high is only 2.2-2.3V (the rest of the ports yield around 3V when high) so I switched to P1.7 for the register select RS pin. This makes the MSP code messier as two ports are in use – both P1 and P2.

I had to change the initialization a bit and add the 8 bit initialization before the 4 bit part, i.e. my working init routine is:

#define     LCM_DIR               P2DIR
#define     LCM_OUT               P2OUT

#define     LCM_PIN_RS            BIT7          // P1.7 -> on P1!
#define     LCM_PIN_EN            BIT1          // P2.1
#define     LCM_PIN_D7            BIT5          // P2.5
#define     LCM_PIN_D6            BIT4          // P2.4
#define     LCM_PIN_D5            BIT3          // P2.3
#define     LCM_PIN_D4            BIT2          // P2.2

void InitializeLcm(void){        // P1 bit 7 is used for RS
        P1DIR |= BIT7;        //        // set the MSP pin configurations
        // and bring them to low        //
        LCM_DIR |= LCM_PIN_MASK;        LCM_OUT &= ~(LCM_PIN_MASK);
        // wait for the LCM to warm up and reach
        // active regions. Remember MSPs can power
        // up much faster than the LCM.
        //
        __delay_cycles(80000);
        P1OUT |= (LED_0 + LED_1); // turn LEDs on
        //
        // initialize the LCM module
        //
        P1OUT &= ~BIT7;
        LCM_OUT &= ~LCM_PIN_EN;
        // init (part of 8 bit mode)
        LCM_OUT = LCM_PIN_D4 | LCM_PIN_D5;
        PulseLcm();
        __delay_cycles(40000); // at least 4.1 ms
        LCM_OUT = LCM_PIN_D4 | LCM_PIN_D5;
        PulseLcm();
        __delay_cycles(200);
        LCM_OUT = LCM_PIN_D4 | LCM_PIN_D5;
        PulseLcm();

        // 4 bit mode
        // function set
        LCM_OUT = LCM_PIN_D5;
        PulseLcm();
        SendByte(0x28, FALSE);
        __delay_cycles(40000); //to check in datasheet

        // clear display
        SendByte(0x1, FALSE);
        __delay_cycles(40000); //to check in datasheet

        // entry mode set
        SendByte(0x6, FALSE);
        __delay_cycles(40000); //to check in datasheet

        SendByte(0xC, FALSE);
        __delay_cycles(40000); //to check in datasheet

        P1OUT &= ~(LED_0 + LED_1); // init complete, turn LEDs off
}

Rasperry PI to MSP430 via SPI

References:

My code is an awful hack using code from both references.

If you use the MSP430 board with the jumpers in their default position the maximum speed you can us is 9600. So you need to set the speed on the Raspberry Pi at 9600 and use the “-H” option (clock phase).

 


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top