TransWikia.com

MSP430 LCD Interfacing via I2C

Electrical Engineering Asked by Jan Franco on January 4, 2022

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() {
    WDTCTL = WDTPW | WDTHOLD;

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

    // i2c config
    UCB0CTL1 |= UCSWRST;
    UCB0CTL0 = UCMST | UCMODE_3 | UCSYNC;
    UCB0CTL1 = UCSSEL_3;
    UCB0BR0 = 12;
    UCB0BR1 = 0;
    UCB0I2CSA = 0x27;   // slave address
    UCB0CTL1 &= ~UCSWRST;

    // enable tx interrupt
    IE2 |= UCB0TXIE;
    _enable_interrupts();

    // start to transmit data
    ptxData = txData;
    UCB0CTL1 |= UCTR + UCTXSTT;

    while (1);
}

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

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

What am I missing, can you help me?

One Answer

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.

Answered by Justme on January 4, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP