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.

CCS/TMS570LS3137-EP: TMS570LS3137 -EP I2C communication is not working

Other Parts Discussed in Thread: TMS570LS3137-EP, HALCOGEN

rt Number: TMS570LS3137-EP

Tool/software: Code Composer Studio

Hi,

i have configured I2C . i have followed example code C:\ti\Hercules\HALCoGen\v04.07.01\examples\TMS570LS31x_21x.

i am trying to communicate with PCA9654EDTR2. IO-Expander.

after start condition code is getting stuck at  while ((i2c->STR & (uint32)I2C_TX_INT) == 0U);

if i enable FDF as 1 , it is not getting stuck but we are writing to IO configuration register 0xa5, while read back the same register 0xFF.

i am calling IOExpTest(); function to test that.3835.IO_Expander.h

0564.IO_Expander.c3644.i2c.ci have attached code ,pl guide me to solve this issue.

this is my I2C configuration below, 


/** - i2c Enter reset */
i2cREG1->MDR = (uint32)((uint32)0U << 5U);

/** - set i2c mode */
i2cREG1->MDR = (uint32)((uint32)0U << 15U) /* nack mode */
| (uint32)((uint32)0U << 14U) /* free running */
| (uint32)(0U) /* start condition - master only */
| (uint32)((uint32)1U <<11U) /* stop condition */
| (uint32)((uint32)1U <<10U) /* Master/Slave mode */
| (uint32)((uint32)I2C_TRANSMITTER) /* Transmitter/receiver */
| (uint32)((uint32)I2C_7BIT_AMODE) /* xpanded address */
| (uint32)((uint32)0U << 7U) /* repeat mode */
| (uint32)((uint32)0U << 6U) /* digital loop back */
| (uint32)((uint32)0U << 4U) /* start byte - master only */
| (uint32)((uint32)0U << 3U) /* free data format */
| (uint32)(I2C_8_BIT); /* bit count */


/** - set i2c Backward Compatibility mode */
i2cREG1->EMDR = 0U;

/** - Disable DMA */
i2cREG1->DMACR = 0x00U;

/** - set i2c data count */
i2cREG1->CNT = 8U;

/** - disable all interrupts */
i2cREG1->IMR = 0x00U;

/** - set prescale */
i2cREG1->PSC = 10U;

/** - set clock rate */
i2cREG1->CKH = 5U;
i2cREG1->CKL = 5U;

/** - set i2c pins functional mode */
i2cREG1->PFNC = (0U);

/** - set i2c pins default output value */
i2cREG1->DOUT = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin */

/** - set i2c pins output direction */
i2cREG1->DIR = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin *//** - set i2c pins open drain enable */

i2cREG1->PDR = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin */

/** - set i2c pins pullup/pulldown enable */
i2cREG1->PDIS = (uint32)((uint32)0U << 1U) /* sda pin */
| (uint32)(0U); /* scl pin */

/** - set i2c pins pullup/pulldown select */
i2cREG1->PSEL = (uint32)((uint32)1U << 1U) /* sda pin */
| (uint32)(1U); /* scl pin */

/** - set interrupt enable */
i2cREG1->IMR = (uint32)((uint32)0U << 6U) /* Address as slave interrupt */
| (uint32)((uint32)0U << 5U) /* Stop Condition detect interrupt */
| (uint32)((uint32)0U << 4U) /* Transmit data ready interrupt */
| (uint32)((uint32)0U << 3U) /* Receive data ready interrupt */
| (uint32)((uint32)0U << 2U) /* Register Access ready interrupt */
| (uint32)((uint32)0U << 1U) /* No Acknowledgement interrupt */
| (uint32)((uint32)0U); /* Arbitration Lost interrupt */

please guide me to solve this issue.

Thanks and Regards,

Anand Kumar

  • Hi,

      Do you have the pullup resistor on the SCL and SDA buses? Do you have the scope capture of the bus?

  • Hi Charles,

    we have pull up resistor of 10KE on the SDA and SCL line. Below i have attached screenshot of SDA and SCL line.

    please check the code which i have sent and some times stop condition is not generating...and sometime after start condition SDA and SCK are low.

    pl guide me to solve this issue ,

    Thanks and Regards,

    Anand Kumar

  • Hi Anand,

      As much as I wanted to help you, I myself is not proficient with the Hercules I2C. I'm more familiar with the TM4C12x product line. With that said, I find this app note which should help you. Although the app note is for the DSP processor but the I2C is pretty much identical to the Hercules. There are flowcharts in the app note describing the proper sequence for correct operation. I will suggest you take a look. 

    I will suggest you start with simple I2C operation. Perhaps start with a loopback mode to make sure everything is fine. Afterward, just add one slave I2C to the bus and check if the slave is correctly receiving the command from the master and reply the acknowledge. From your scope the bus is just high. It means there is pullup but there is nothing I can tell if the master is sending the command (e.g. slave address) and data correctly and if the slave is replying the acknowledge or not.

  • Hi Charles,

    Thanks for document and  i will follow the procedure and let u know.

    previous status after send the start bit both the SDA and SCK lines are become low....

    i will go through document and i will update the status...

    Thanks and Regards,

    Anand Kumar

  • Hi Charles,

    I have gone through the document and i made code as per document transmit and receive section of code without enabling  FDF(Free data format). i have configured slave address as 0x4A and set count value is equal to 1.

    After the start condition , slave address which i have set in SAR is 0x4A is not coming out followed by send register address as 0x03. we are able to see 0x03 at oscilloscope after start condition.

    in my IO expander(PCA9654EDTR2G) slave address is 0X4A.

    But in FDF format code is working for transmit section . that we have verified by configurating IO expander I/O dir as output and toggled some I/O. so we have confirmed that communication is working for transmit but for reading we followed procedure like below,

    DIR-->(I2C_Transmit).

    1. start condition---->slave adress -0x4a-----> register address(0x03)------->stop condition.  

    case 1:

    DIR-->(I2C_Receiver)

    2. start condition----->slave adress -0x4a+ 1(read bit)------->read data it get stuck in RXRDY data. see figure 2.

    DIR-->(I2C_Transmit).

    2. start condition----->slave adress -0x4a+ 1(read bit)

    DIR-->(I2C_Receiver).------->read data it get stuck in RXRDY data. During this time in oscilloscope, 0x4b is not going out it is coming 0xff.

    pl guide me to solve this problem.

    Thanks and regards,

    Anand Kumar

  • Hi Anand,

      Can you show your updated code again? I don't know what you have changed since last time. There are several HalCogen I2C examples. Here is one of them with the I2C master talking to a Philips PCF8570 device. Please also take a look. 2474.example_i2c_pcf8570.c

    so we have confirmed that communication is working for transmit but for reading we followed procedure like below,

    DIR-->(I2C_Transmit).

    1. start condition---->slave adress -0x4a-----> register address(0x03)------->stop condition.  

    Do you see the slave address come out on the bus in this case. Can you show the waveform? You only show figure 2 in the last reply. Did you have a figure 1 to send? Please send you waveform with the SCL on top and SDA on bottom. The waveform you send is too small for me especially they are superimposed on top of another. 

  • Hi Charles,

    I2C problem is solved by normal method, the issue was SAR = (0x4a)>>1;  we have to do right shift. after that it works thanks for great support. remaning thing as per the document i followed it just works fine.

    Thanks & Regards,

    Anand Kumar.