Hello,
I'm writing a program for interfacing a 1602 LCD (equipped with I2C backpack, works in Energia) to MSP42 with the use of I2C protocol. I'm not writing my own routines, so I decided to go with DriverLib ones in CCS. LCD successfully initializes (powered, cursor blinking and ready to go) and after I try with different combinations of signals to get different characters, only some seem to appear.
I initialize the LCD to 4 bit mode with the code below:
void lcdInit(void){ I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x30); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x30); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x30); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x20); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x28); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x08); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x01); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x06); __delay_cycles(10000); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x0C); }
After it exectues, the LCD is lit on and the cursor blinks. Now, in 4 bit operation we have to send data in 2 chunks. Each chunk is 6 bits, 4 data + 2 for RS and RW.
Going by the LCD reference (http://www.tme.eu/en...02b-biw-esx.pdf), I thought I could write a character "A" with two successive commands, like:
I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x9); I2C_masterSendSingleByte(EUSCI_B0_MODULE, 0x21); // 0x9 = 0b001001 // last 2 bits are RW and RS // 0x21 = 0b100001 //
However, nothing usually happens, and if I'm lucky with the combinations, the characters from last row (LCD reference, page 11) are printed (?, /, O, _, ..) and no others.
I can't seem to figure out what is going on exactly to try to get a pattern of errors being made. I'm almost sure I'm sending the wrong commands and not bit shifting properly. I also suspect I'm somehow sending the bits in the wrong order or shifted, because SendSingleByte adds two 0's in front of the desired 6 bit sequence. And ideas?
Thanks!