Other Parts Discussed in Thread: MIDAS
Hi everyone,
I am trying to get a Midas 20x4 LCD Display to work over I2C, until now without success. After several fruitless attempts of writing a library for the LCD, all I am trying to achieve now is powering the module up. To this point I have not seen any sign of life on the display itself which makes me doubt that it is still OK, so it might just be broken.
The only life sign i get is what I think is an Acknowledge after sending some data. The Display needs a control byte after the address which defines if the following information is a command or display data.
The picture shows what i captured with an oscilloscope. The MSP432 sends the address (0x3c) which gets acknowledged. The next byte is just 0x00 ( the control byte for a command) which gets acknowledged too. The next byte is the command 0x3A (as advised in the datasheet of the LCD). Then the communication suddenly stops and restarts while transmitting the next byte.
The LCD has 13 pins which are connected as mentioned on page 7 in the datasheet http://www.farnell.com/datasheets/1663648.pdf
This is my first attempt in using I2C so I am not experienced enough to see why this is happening and if my code is correct. I would appreciate if you could have a look on the code (which is modified from a driverlib example).
/* DriverLib Includes */
#include "driverlib.h"
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
/* Slave Address for I2C Slave */
#define SLAVE_ADDRESS 0x3c
/* Statics */
static uint8_t TXData[10] = {0x00, 0x3A, 0x1E, 0x39, 0x1C, 0x79, 0x5D, 0x6C, 0x0C, 0x01};
static uint8_t TXByteCtr = 1;
static uint8_t sent = 0;
/* I2C Master Configuration Parameter */
const eUSCI_I2C_MasterConfig i2cConfig =
{
EUSCI_B_I2C_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
3000000, // SMCLK = 3MHz
EUSCI_B_I2C_SET_DATA_RATE_100KBPS, // Desired I2C Clock of 100khz
0, // No byte counter threshold
EUSCI_B_I2C_NO_AUTO_STOP // No Autostop
};
int main(void)
{
volatile uint32_t ii;
/* Disabling the Watchdog */
MAP_WDT_A_holdTimer();
P1DIR |= BIT0;
P1OUT &= ~(BIT0);
P3DIR |= BIT7;
/* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function,
* (UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
*/
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6 + GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
/* Initializing I2C Master to SMCLK at 100kbs with no autostop */
MAP_I2C_initMaster(EUSCI_B0_MODULE, &i2cConfig);
/* Specify slave address */
MAP_I2C_setSlaveAddress(EUSCI_B0_MODULE, SLAVE_ADDRESS);
/* Set Master in receive mode */
MAP_I2C_setMode(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_MODE);
/* Enable I2C Module to start operations */
MAP_I2C_enableModule(EUSCI_B0_MODULE);
/* Enable and clear the interrupt flag */
MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
//Enable master Receive interrupt
MAP_I2C_enableInterrupt(EUSCI_B0_MODULE,EUSCI_B_I2C_TRANSMIT_INTERRUPT0 + EUSCI_B_I2C_NAK_INTERRUPT);
MAP_Interrupt_enableInterrupt(INT_EUSCIB0);
uint32_t i;
P3OUT &= ~(BIT7);
//for(i=0;i<36000;i++); //Delay > 10ms.
P3OUT |= BIT7;
//for(i=0;i<3000;i++); //Delay > 1ms
while (1)
{
//Delay between Transmissions
//for (ii = 0; ii < 4000; ii++);
// Making sure the last transaction has been completely sent out
while (MAP_I2C_masterIsStopSent(EUSCI_B0_MODULE) == EUSCI_B_I2C_SENDING_STOP);
// Sending the initial start condition
MAP_I2C_masterSendMultiByteStart(EUSCI_B0_MODULE, TXData[0]);
MAP_Interrupt_enableSleepOnIsrExit();
MAP_PCM_gotoLPM0InterruptSafe();
}
}
void euscib0_isr(void)
{
uint_fast16_t status;
status = MAP_I2C_getEnabledInterruptStatus(EUSCI_B0_MODULE);
MAP_I2C_clearInterruptFlag(EUSCI_B0_MODULE, status);
if (status & EUSCI_B_I2C_NAK_INTERRUPT)
{
MAP_I2C_masterSendStart(EUSCI_B0_MODULE);
P1OUT |= BIT0;
}
if (status & EUSCI_B_I2C_TRANSMIT_INTERRUPT0)
{
// Check the byte counter
if (!sent)
{
// Send the next data and decrement the byte counter
MAP_I2C_masterSendMultiByteNext(EUSCI_B0_MODULE, TXData[TXByteCtr]);
sent = 1;
} else
{
MAP_I2C_masterSendMultiByteStop(EUSCI_B0_MODULE);
MAP_Interrupt_disableSleepOnIsrExit();
TXByteCtr++;
sent = 0;
}
}
if (TXByteCtr > 10)
{
MAP_Interrupt_disableInterrupt(INT_EUSCIB0);
}
}
The acknowledge of the LCD did send is the only reason I have to hope that the display is still working. Sadly, it did never light up or show me anything.
Would be nice if somebody gave the code a look.
Jonathan
