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.

TMS570LS0714: I2C infinite loop

Part Number: TMS570LS0714

I am trying to communicate with I2C communication a PCB with a TMS570LS0714 with an arduino. The arduino is the slave and my PCB is the master. 

I wrote a function to write into the slave (arduino):

void write_slave(int address, int buffer){
    /* Configure address of Slave to talk to */
    i2cSetSlaveAdd(i2cREG1, address);

   /* Configure Data count */
           /* Note: Optional - It is done in Init, unless user want to change */
           //i2cSetCount(i2cREG1, DATA_COUNT_I2C);

           /* Set mode as Master */
           i2cSetMode(i2cREG1, I2C_MASTER);

           /* Set Stop after programmed Count */
           i2cSetStop(i2cREG1);

           /* Transmit Start Condition */
           i2cSetStart(i2cREG1);

           /* Tranmit DATA_COUNT number of data in Polling mode */
           i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>24);
           i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>16);
           i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>8);
           i2cSend(i2cREG1, DATA_COUNT_I2C, buffer);


           /* Wait until Bus Busy is cleared */
           while(i2cIsBusBusy(i2cREG1) == true);

           /* Wait until Stop is detected */
           while(i2cIsStopDetected(i2cREG1) == 0);

           /* Clear the Stop condition */
           i2cClearSCD(i2cREG1);
}

Where:

//PINOUT I2C
#define SLAVE_WRITE_ADDR 0xA0 
#define SLAVE_READ_ADDR 0xA1 
#define DATA_COUNT_I2C 8

And the code in arduino is just to send data into a Labviw interface:

#include <Wire.h>

uint8_t data;
int nByte = 0;
byte lectura[4];
unsigned long valor = 0;


void setup()
{
  Wire.begin(0x50);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while (Wire.available() > 0){ // loop through all but the last
    data = Wire.read(); // receive byte as a character
    lectura[nByte]=data;
    nByte++;
    if(nByte % 4 == 0){
      nByte = 0;
      valor = (unsigned long)lectura[3] + ((unsigned long)lectura[2]<<8) + ((unsigned long)lectura[1]<<16) + ((unsigned long)lectura[0]<<24);
      Serial.println(valor);
    }
  }
  
}

When I call the function "write_slave" the code jump into a i2c.c function with an infinite loop. Why is this happening? It does not find the slave (arduino)?




  • Hello,

    It means that no data is copied from the data transmit register (I2CDXR) into the transmit-shift register (I2CXSR). When the code gets stuck at the while() loop, what is the value of length? 

    The slave address written to I2CSAR should not include the W/R bit. 

  • If you mean the length shown in the figure it is 7 as I set #define DATA_COUNT_I2C  8. In addition I have a warning on the line i2cSend(i2cREG1, DATA_COUNT_I2C, buffer>>24);
    It says:

    Description Resource Path Location Type
    #169-D argument of type "int" is incompatible with parameter of type "uint8 *" sys_main.c 

  • Is bit 1 of STR register set? 

    I guess that the I2C slave doesn't generate ACK. Did you check the data on I2C data line?

  • Do you mean with an oscilloscope for example? I don't get any signal on the line. 

  • I2C is an open-drain/open-collector communication standard, and the pullup resistors need to be connected from the I2C lines (SCL, SDA) to the supply to enable the communication.

    Please use the following appnote to calculate the pullup resistor value:

    Didn't you see the start bit and slave address on the data line using the oscilloscope? 

  • Yes, I am using two pullup resistors of 950 ohms connected to arduino (slave) 3.3V. SDA and SCL are directly connected from arduino to the microcontroller. I can see using the oscilloscope that the two lines are always at 3.3V. Doing debugging I can see that I always go into the infinite loop of before. Now I am using a sample example code with arduino and with TMS750 but never changes. Here are the codes I am using:
    Could it be a register problem? Where can I find information about how to configure the registers for the i2c?

    Arduino:

    // Wire Slave Receiver
    // by Nicholas Zambetti <http://www.zambetti.com>
    
    // Demonstrates use of the Wire library
    // Receives data as an I2C/TWI slave device
    // Refer to the "Wire Master Writer" example for use with this
    
    // Created 29 March 2006
    
    // This example code is in the public domain.
    
    
    #include <Wire.h>
    
    void setup()
    {
      Wire.begin(4);                // join i2c bus with address #4
      Wire.onReceive(receiveEvent); // register event
      Serial.begin(9600);           // start serial for output
    }
    
    void loop()
    {
      delay(100);
    }
    
    // function that executes whenever data is received from master
    // this function is registered as an event, see setup()
    void receiveEvent(int howMany)
    {
      while(1 < Wire.available()) // loop through all but the last
      {
        char c = Wire.read(); // receive byte as a character
        Serial.print(c);         // print the character
      }
      int x = Wire.read();    // receive byte as an integer
      Serial.println(x);         // print the integer
    }

    TMS570:

    /** @file sys_main.c 
    *   @brief Application main file
    *   @date 17.Nov.2014
    *   @version 04.02.00
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2014 Texas Instruments Incorporated - http://www.ti.com/ 
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "i2c.h"
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    #define DATA_COUNT  10
    
    #define Master_Address 0x26
    #define Slave_Address  0x8
    
    uint8_t TX_Data_Master[10] = { 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19};
    uint8_t RX_Data_Master[10] = { 0 };
    
    uint8_t TX_Data_Slave[10] = { 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29};
    uint8_t RX_Data_Slave[10] = { 0 };
    
    /* USER CODE END */
    
    void main(void)
    {
    /* USER CODE BEGIN (3) */
    
    	int repeat = 0; int delay =0;
    
    ///////////////////////////////////////////////////////////////
    //        Master Transfer Functionality                      //
    ///////////////////////////////////////////////////////////////
    	/* I2C Init as per GUI
    	 *  Mode = Master - Transmitter
    	 *  baud rate = 100KHz
    	 *  Count = 10
    	 *  Bit Count = 8bit
    	 */
    	i2cInit();
    
    	/* Configure address of Slave to talk to */
    	i2cSetSlaveAdd(i2cREG1, Slave_Address);
    
    	/* Set direction to Transmitter */
    	/* Note: Optional - It is done in Init */
    	i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
    
    
    	for(repeat = 0; repeat < 2; repeat++)
    	{
    		/* Configure Data count */
    		/* Note: Optional - It is done in Init, unless user want to change */
    		i2cSetCount(i2cREG1, DATA_COUNT);
    
    		/* Set mode as Master */
    		i2cSetMode(i2cREG1, I2C_MASTER);
    
    		/* Set Stop after programmed Count */
    		i2cSetStop(i2cREG1);
    
    		/* Transmit Start Condition */
    		i2cSetStart(i2cREG1);
    
    		/* Tranmit DATA_COUNT number of data in Polling mode */
    		i2cSend(i2cREG1, DATA_COUNT, TX_Data_Master);
    
    		/* Wait until Bus Busy is cleared */
    		while(i2cIsBusBusy(i2cREG1) == true);
    
    		/* Wait until Stop is detected */
    		while(i2cIsStopDetected(i2cREG1) == 0);
    
    		/* Clear the Stop condition */
    		i2cClearSCD(i2cREG1);
    
    		/* Simple Dealya before starting Next Block */
    		/* Depends on how quick the Slave gets ready */
    		for(delay=0;delay<1000000;delay++);
    
    	}

  • I am even trying with a launchpad TMS570LS12x as a master and arduino as a slave with the same issue. I am using the same code of before and pin 9 and 10 of J6 of the launchpad for I2C communication. In addition I would like to ask if I should select wich I2C port I have to use in launchpad as there are 2 I2c port, and how I do it. Should I define come register for I2C? What could be the problem on having always high signal on I2C line and going in an infinite loop?

  • You opened another thread for the same issue. I will close this one.