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.

TM4C1292NCPDT: unable to send multiple I2C data to TCA9555PWR

Part Number: TM4C1292NCPDT
Other Parts Discussed in Thread: TCA6416, TCA9555

Hi,

In my schematic, I'm connecting TM4C1292NCPDT to the IO expander IC TCA9555PWR through the I2C clock and data lines, SCL, and SDA. 

I'm trying to run the following code with all 3 address lines as HIGH which means address is 0x27:

#include <stdarg.h>

#include <stdbool.h>

#include <stdint.h>

#include "inc/hw_i2c.h"

#include "inc/hw_memmap.h"

#include "inc/hw_types.h"

#include "inc/hw_gpio.h"

#include "driverlib/i2c.h"

#include "driverlib/sysctl.h"

#include "driverlib/gpio.h"

#include "driverlib/pin_map.h"

#include "xdc/std.h"

#include <ti/drivers/I2C.h>

uint32_t g_ui32SysClock;

bool  bDiInitialized = FALSE;

 

#define DI_SLAVEADDRESS          0x27

 

//initialize I2C module 0

void InitI2C0(void)

{

   //enable I2C module 0

    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    //reset module

    SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);

 

    //enable GPIO peripheral that contains I2C 0

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

 

    // Configure the pin muxing for I2C0 functions on port B2 and B3.

    GPIOPinConfigure(GPIO_PB2_I2C0SCL);

    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

 

    // Select the I2C function for these pins.

    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

 

    // Enable and initialize the I2C0 master module.  Use the system clock for the I2C0 module.  The last parameter sets the I2C data transfer rate.

    // If false the data rate is set to 100kbps and if true the data rate will be set to 400kbps.

    //I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), true);//for 400kbps tm4c123

    I2CMasterInitExpClk(I2C0_BASE,  SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000), true);//for 400kbps tm4c129

 

    //clear I2C FIFOs

    //HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;

}

 

//I2C Send Function

//sends an I2C command to the specified slave

void I2CSend(uint8_t slave_addr, uint8_t num_of_args, ...)

{

    uint8_t i ;

    // Tell the master module what address it will place on the bus when

    // communicating with the slave.

    I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);

 

    //stores list of variable number of arguments

    va_list vargs;

 

    //specifies the va_list to "open" and the last fixed argument so vargs knows where to start looking

    va_start(vargs, num_of_args);

 

    //put data to be sent into FIFO

    I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint32_t));

    //if there is only one argument, we only need to use the single send I2C function

    if(num_of_args == 1)

    {

        //Initiate send of data from the MCU

        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

        // Wait until MCU is done transferring.

        while(!(I2CMasterBusy(I2C0_BASE)));

        while(I2CMasterBusy(I2C0_BASE));

        //"close" variable argument list

        va_end(vargs);

    }

    //otherwise, we start transmission of multiple bytes on the I2C bus

    else

    {

        //Initiate send of data from the MCU

        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

        // Wait until MCU is done transferring.

        while(!(I2CMasterBusy(I2C0_BASE)));

        while(I2CMasterBusy(I2C0_BASE));

        //send num_of_args-2 pieces of data, using the

        //BURST_SEND_CONT command of the I2C module

        for( i = 1; i < (num_of_args - 1); i++)

        {     //put next piece of data into I2C FIFO

            I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint32_t));

            //send next data that was just placed into FIFO

            I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);

            // Wait until MCU is done transferring.

            while(!(I2CMasterBusy(I2C0_BASE)));

            while(I2CMasterBusy(I2C0_BASE));

        }

        //put last piece of data into I2C FIFO

        I2CMasterDataPut(I2C0_BASE, va_arg(vargs, uint32_t));

        //send next data that was just placed into FIFO

        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

        // Wait until MCU is done transferring.

        while(!(I2CMasterBusy(I2C0_BASE)));

        while(I2CMasterBusy(I2C0_BASE));

        //"close" variable args list

        va_end(vargs);

    } }

//sends an array of data via I2C to the specified slave

void I2CSendString(uint32_t slave_addr, char array[])

    // Tell the master module what address it will place on the bus when communicating with the slave.

    I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);

     //put data to be sent into FIFO

    I2CMasterDataPut(I2C0_BASE, array[0]);

     //if there is only one argument, we only need to use the

    //single send I2C function

    if(array[1] == '\0')

    {

        //Initiate send of data from the MCU

        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);

 

        // Wait until MCU is done transferring.

        while(!(I2CMasterBusy(I2C0_BASE)));

        while(I2CMasterBusy(I2C0_BASE));

    }

     //otherwise, we start transmission of multiple bytes on the I2C bus

    else

    {         //Initiate send of data from the MCU

        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

         // Wait until MCU is done transferring.

        while(!(I2CMasterBusy(I2C0_BASE)));

        while(I2CMasterBusy(I2C0_BASE));

         //initialize index into array

        uint8_t i = 1;

         //send num_of_args-2 pieces of data, using the

        //BURST_SEND_CONT command of the I2C module

        while(array[i + 1] != '\0')

        {            //put next piece of data into I2C FIFO

            I2CMasterDataPut(I2C0_BASE, array[i++]);

             //send next data that was just placed into FIFO

            I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);

             // Wait until MCU is done transferring.

            while(!(I2CMasterBusy(I2C0_BASE)));

            while(I2CMasterBusy(I2C0_BASE));

        }

         //put last piece of data into I2C FIFO

        I2CMasterDataPut(I2C0_BASE, array[i]);

         //send next data that was just placed into FIFO

        I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

         // Wait until MCU is done transferring.

        while(!(I2CMasterBusy(I2C0_BASE)));

        while(I2CMasterBusy(I2C0_BASE));

    }   }

 //I2C Receive Function

//read specified register on slave device

uint32_t I2CReceive(uint32_t slave_addr, uint8_t reg)

{    //specify that we are writing (a register address) to the

    //slave device

    I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, false);

    //specify register to be read

    I2CMasterDataPut(I2C0_BASE, reg);

    //send control byte and register address byte to slave device

    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

    //wait for MCU to finish transaction

    while(I2CMasterBusy(I2C0_BASE));

    //specify that we are going to read from slave device

    I2CMasterSlaveAddrSet(I2C0_BASE, slave_addr, true);

    //send control byte and read from the register we specified

    I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

    //wait for MCU to finish transaction

    while(!(I2CMasterBusy(I2C0_BASE)));

    while(I2CMasterBusy(I2C0_BASE));

    //return data pulled from the specified register

    return I2CMasterDataGet(I2C0_BASE);

}  }

void main(void)

{     // Set the clocking to run directly from the external crystal/oscillator.

   g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |

                                       SYSCTL_OSC_MAIN |

                                       SYSCTL_USE_PLL |

                                       SYSCTL_CFG_VCO_480),120000000);

   //initialize I2C module 0

  InitI2C0();

  I2CSend(DI_SLAVEADDRESS, 3, 0, 0, 0x01);

  I2CSend(DI_SLAVEADDRESS, 3, 0x06, 0x01, 0);//configuration port 0

    while(1){};

}

 But from the scope capture, only single I2C send command seems to be working not multiple.

 

 Please guide for the same.

Best Regards,

Kiranjit

  • Hi,

      Please look at your scope where I circle the ACK/NACK bit. SCL shows 0x27 is put out as the slave address followed by R/W bit equal to 0 which is a command to write to the slave. However,lLooks like the slave is not returning an ACK to the master and hence the SCL is pulled high during the ACK/NACK phase. You need to investigate why the slave is not driving the ACK when it receives the command from the master. When the master is not getting an ACK from the slave, it is not able to proceed further. You can check the DATACK and ERROR bit in the I2CMCS register and I believe they are set high. 

  • Hi Charles,

    I checked the status register, I2C0MCS in debug mode of CCS. The DATACK and ERROR bits are set to LOW.

    The scope capture shows the following image sometimes:

    Thanks,

    Kiran

  • Hi Kiran,

      The ACK bit is half high. What is the pullup you resistor you have? It seems like the slave device is barely able to overcome the pullup when it tries to drive it low. Do you have any scope cap that shows the ACK is low?

      Can you call I2CSend(DI_SLAVEADDRESS, 0, 0, 0, 0x01) so only one word is written to the slave? I want to see how a simple one word write is shown on the scope. 

  • Hi Charles,

    The pull-up resistors being used are 2K each. There's no scope captur showing ACK as LOW.

    So,I used just one I2C write to the slave this time as suggested by you,i.e. I2CSend(DI_SLAVEADDRESS, 0, 0, 0, 0x01) but the scope capture remains the same.

    What could be the reason?

    Please guide.

    Best Regards,

    Kiran

  • Hi,

    Additionally I tried the function I2CSend(DI_SLAVEADDRESS, 1, 0, 0, 0x01) for transmitting one bit and the scope capture was as below

    Best Regards,

    Kiran

  • Hi,

      Sorry, I really don't know what is the problem.  

      - Can you try on the LaunchPad? Please show waveforms when connecting LaunchPad to your IO expander. 

      - Do you have another custom board(s) to try? Can you replicate on different boards?

      - Can you try to make your example as simple as possible. Perhaps, first reference the simple example at C:\ti\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl-boostxl-senshub\humidity_sht21_simple. 

  • Hi,

    To run the sample code in in my I'd need to understand this example first, I don't know where should I give the address of IO expander IC?

    Also, I'm testing using Launchpad and EV-Boards of ADUM3151 isolator and IO-Expander EVM (setup shown below). I'm giving I2C SCL, SDA signals from Launchpad to IO Expander EVM via isolator.

    For the IO-Expander I'm using slave address as 0x27(screenshot of schematic given below), since all three address lines (Pins 2,3,21) in the EV-Board are pulled up (we've replaced the IC TCA6416 and soldered TCA9555PWR in the evaluation board)..

    If you've any suggestions, please let me know.

    Best Regards,

    Kiran

  • Hi,

      I look at one of your earlier scope cap and you show. See below. In this cap, the slave is not replying ACK. As you can see, without the ACK, the master terminates. I'm not familiar with TCA9555 device. You need to consult with TCA9555 forum support so they can assist and help you debug better. Somehow, TCA9555 does not recognize 0x27 as the address. 

  • Hi Charles,

    Thank you for your help. I'll put a post in TCA9555 forum.

    Best Regards,

    Kiran

  • Hi Charles,

    What modification do I need to do in the code so as to take care of the synchronization between SDA and SCL, i.e., set up time, hold time and start/stop condition?

    Thanks,

    Kiran

  • Thread in the interface forum: Unable to send multiple I2C data to TCA9555PWR But as far as I can see, the problem is not caused to the TCA9555.

    The captured SDA waveforms show overshoots on the rising edge, which indicates that the SDA pin is not configured as open-drain, but as push/pull. This means that the call to GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3) did not work, or was overridden later.

    (I do not know anything about the TM4C; how would one read back and check the GPIO configuration?)

  • Hi,

      There is nothing in the code that you need to take care for synchronization between SDA and SCL. It is supposed to be handled by the hardware. Can you run I2C at 100kHz? I want to see how the bit timing behaves compared to 400kHz.

  • Hi Charles,

    I did the following changes in the code.

    Please see scope capture for 100kHz and 400kHz in case of 2k and 4k7 pull up.

    100kHz (2K pull up)

    400kHz (2k pull up)

    100kHz (4k7 pull up)

    400 kHz (4k7 pull up)

    Please give your suggestions.

    Best Regards,

    Kiranjit

  • Hi,

      I don't know how to make out this myself. Normally I will expect a lower pullup resistance to be used for higher I2C baudrate. However, on your scope, it seems 4k7 for 400KHz has better waveform than 2k. Regardless of what resistor to use, you seem to still have problem on NACK on both 100kHz and 400kHz. Do you have another LaunchPad to try? Can you repeat the same thing?

        Also to give you a heads-up. I'm on vacation until next Wednesday and my response will be delayed.