This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280049C: i2c driverlib examples for repeated transmission mode

Part Number: TMS320F280049C


I need to configure an i2c lcd unit using a repeated start procedure in a non interrupt mode.

I have looked at the i2c driverlib examples and still do not have a clear direction 

On the MSP432P401R processor, i used the following driverlib code.

void LCDinit(void)
{

// Put the Slave Address on the bus for Write
MAP_I2CMasterSlaveAddrSet(I2C2_BASE, SlaveAddress, false);
// Set Master to transmit mode
MAP_I2C_setMode(EUSCI_B1_BASE, EUSCI_B_I2C_TRANSMIT_MODE);

my48Mdelayms(40); // Delay for 40ms upon power up or reset
MAP_I2C_masterSendMultiByteStart(EUSCI_B1_BASE, 0x00); // Send start, address and Command mode byte (0x40)
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x38); //Function set - 8 bit, 2 line display 5x8, inst table 0
my48Mdelayms(10);
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x39); //Function set - 8 bit, 2 line display 5x8, inst table 1
my48Mdelayms(10);
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x14); // Set bias - 1/5
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x78); // Set contrast low
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x5E); // ICON disp on, Contrast high byte
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x6D); // Follower circuit (internal), amp ratio (6)
my48Mdelayms(300);
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, LCDDISP_ON); // Display on, cursor on 0x0E
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, CLEAR_DISPLAY); // Clear display
my48Mdelayms(2);
MAP_I2C_masterSendMultiByteNext(EUSCI_B1_BASE, 0x06); // Entry mode set - increment
my48Mdelayms(2);
MAP_I2C_masterSendMultiByteStop(EUSCI_B1_BASE); // End Transmission
}

Without using the FIFO 

Can i implement it as follows?

DEVICE_DELAY_US(40000);  // 40000us = 40ms

 I2C_setSlaveAddress(I2CA_BASE, LCD_SLAVE_ADDRESS);     // Setup slave address: LCD_SLAVE_ADDRESS defined as 0x78

 I2C_setDataCount(I2CA_BASE, 1); // Setup number of bytes to send msgBuffer and address
 I2C_putData(I2CA_BASE, 0x00); // Send start, address and Command mode byte (0x00)
 I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE | I2C_REPEAT_MODE); 

I2C_sendStartCondition(I2CA_BASE);

- Will the following automatically complete the process:

I2C_putData(I2CA_BASE, 0x38); //Function set - 8 bit, 2 line display 5x8, inst table 0
while(I2C_isBusBusy(I2CA_BASE)); // Wait until transfer done

        DEVICE_DELAY_US(10000);  // Delay 10000us = 10ms

I2C_putData(I2CA_BASE, 0x39); //Function set - 8 bit, 2 line display 5x8, inst table 1
while(I2C_isBusBusy(I2CA_BASE)); // Wait until transfer done
DEVICE_DELAY_US(10000); // Delay 10000us = 10ms

        ............................

and finally:

I2C_putData(I2CA_BASE, 0x06); // Entry mode set - increment
while(I2C_isBusBusy(I2CA_BASE)); // Wait until transfer done
DEVICE_DELAY_US(2000); // Delay 2000us = 2ms
I2C_sendStopCondition(I2CA_BASE);

OR i have to be using " I2C_sendStartCondition(I2CA_BASE);"  after each "I2C_putData(I2CA_BASE, ...) 

function call.

 

Thanks

David Nyarko

  • David,

    How does your LCD I2C unit expect the message frame?

    From the above MSP432 code, it looks like this is the message frame expected by LCD screen. Is this correct?

    1) START condition + Transmit Slave address + Transmit command mode byte 0 + STOP condition
    2) START condition + Transmit Slave address + Transmit 0x38 + STOP condition

    3) delay 10 us

    4) START condition + Transmit Slave address + Transmit 0x39 + STOP condition

    5) delay 10 us

    6) and so on...

    (or) Can I transmit more than one byte in a message frame as shown below?

    START condition + Transmit Slave address + Transmit command byte 0 + Transmit 0x38 + Transmit 0x39 + STOP condition

    You can achieve both using the I2C driverlib example provided. Depending upon the your requirement, I can tell how you need to modify the code.

    Regards,

    Manoj

  • Please provide which LCD unit you are trying to interface to.

    Regards,

    Manoj

  • Hi,

    Regarding the previous post, i dont think either of the 2 options is being used. I might be wrong, but i think the "stop" is only sent after all the bytes are transmitted. The MSP432P401R code is what i have working with this LCD unit now and i currently want to setup this display to work with the F280049C launchpad . 

    The LCD unit is :  the Newhaven  "NHD-C0220BiZ-FSW-FBW-3V3M"

    We use this character display since it is a 3.3V part.

    The data sheet is at : https://www.newhavendisplay.com/specs/NHD-C0220BiZ-FSW-FBW-3V3M.pdf

    The example initialization program is on pages 12-13.

    Thanks

    David Nyarko

  • David,

    If 10ms delay is mandatory requirement then you can't use either of the methods I proposed.

     In repeat mode, I2CCNT register doesn't need to set I2CCNT register value is ignored in repeat mode. I have modified the code similar to what is found in LCD unit DS.

     DEVICE_DELAY_US(40000);  // 40000us = 40ms

     I2C_setSlaveAddress(I2CA_BASE, LCD_SLAVE_ADDRESS);     // Setup slave address: LCD_SLAVE_ADDRESS defined as 0x78
     I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE | I2C_REPEAT_MODE);  // Master Transmit with repeat mode enable
     
     I2C_sendStartCondition(I2CA_BASE);                                    // Generate START condition
     I2C_putData(I2CA_BASE, 0x00);                                          // Transmit Command mode byte (0x00)
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     
     I2C_putData(I2CA_BASE, 0x38);                                          // Function set - 8 bit, 2 line display 5x8, inst table 0
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete

     DEVICE_DELAY_US(10000);  // Delay 10000us = 10ms
     
     I2C_putData(I2CA_BASE, 0x39);                                          // Function set - 8 bit, 2 line display 5x8, inst table 1
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     
     DEVICE_DELAY_US(10000);  // Delay 10000us = 10ms
     
     I2C_putData(I2CA_BASE, 0x14);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     I2C_putData(I2CA_BASE, 0x78);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     I2C_putData(I2CA_BASE, 0x5E);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     I2C_putData(I2CA_BASE, 0x6D);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     I2C_putData(I2CA_BASE, 0x0C);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     I2C_putData(I2CA_BASE, 0x01);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete
     I2C_putData(I2CA_BASE, 0x06);
     while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));            // Wait for I2C transmit to complete

     DEVICE_DELAY_US(10000);  // Delay 10000us = 10ms
     
     I2C_sendStopCondition(I2CA_BASE);                                    // Generate Stop condition

    Regards,

    Manoj

  • Thanks,

    The LCD is working correctly with the board. Your code also served as a template for me to create a string display function

    which works well.

    The only modification was to replace "base" in "while(!(I2C_getStatus(base) & I2C_STS_REG_ACCESS_RDY));"

    with "I2A_BASE".

    David