I am new at this. I am trying to interfacing 1602A LCD display with MSP430G2553 via PCF8574. When I run the code, nothing happens:

#include <msp430.h>

unsigned int *ptxData;
unsigned int count = 0;
// [0..3] -> power on, [4..5] -> function set, [6..7] -> display off, cursor off, blink off
// [8..9] -> clear screen, [10..11] -> right, do not shift, [12..13] -> display on, cursor on
// [14..15] -> write char 'B'
unsigned int txData[] = {0x03, 0x03, 0x03, 0x02, 0x02, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x06, 0x00, 0x0F, 0x24, 0x22};

void main() {

    // for i2c pins
    P1SEL = 0xC0;
    P1SEL2 = 0xC0;

    // i2c config
    UCB0CTL1 = UCSSEL_3;
    UCB0BR0 = 12;
    UCB0BR1 = 0;
    UCB0I2CSA = 0x27;   // slave address

    // enable tx interrupt
    IE2 |= UCB0TXIE;

    // start to transmit data
    ptxData = txData;

    while (1);

#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void){
    // send txData elements one by one
    UCB0TXBUF = *ptxData;

    // if txData ends, start from beginning
    if (count == 16) {
        count = 0;
        ptxData -= 16;

What am I missing, can you help me?


1 Answer 1


The code is obviously missing comments what it does. If it did have comments what it does or what it is supposed to do, it would be more clear to find out what's wrong.

First of all the transmit data pointer is initialized to null, so it is sending garbage data instead of data from the transmit data array.

Second problem is that the array contains only command nybbles that must be sent to LCD. They are just loaded to GPIO expander data pins, but the LCD RS, RW and E lines are not set at any point for each command nybble, so the commands are not strobed to the LCD.

  • \$\begingroup\$ Right, I should have added comments, my mistake. I fixed the data pointer. But I2C bus is 8-bit. If I add RW, E, RS bits, data length will be 10-bits. How can I send 10-bits? \$\endgroup\$
    – Jan Franco
    Jul 24, 2020 at 22:08
  • \$\begingroup\$ The LCD is connected with 4 data bits to the expander. Three other expander bits are the LCD control bits. There is one bit left which is either not used or is controlling the backlight. Just see the expander module schematics. \$\endgroup\$
    – Justme
    Jul 24, 2020 at 22:10
  • \$\begingroup\$ I edited and added comments. Now, I am sending data by RS + R/W + DB7/4 then RS + R/W + DB3/0. But nothing happends except the screen goes on and off at uncertain times. \$\endgroup\$
    – Jan Franco
    Jul 25, 2020 at 9:14
  • \$\begingroup\$ At least it does something. Maybe you are not toggling E correctly? \$\endgroup\$
    – Justme
    Jul 25, 2020 at 11:39
  • \$\begingroup\$ Toggling E? How can I toggle E? Sorry, I am new at these. \$\endgroup\$
    – Jan Franco
    Jul 25, 2020 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.