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.

TMS570LC4357: Inability to repeat transmission of I2C messages.

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

Hello, I've created a simple program to send messages to a Temperature sensor (I'm not now using the I2C2 port for acknowledges):

CCS 7.0.0.00042

HALCoGen 04.07.01

void start(void) {

unsigned char data[8];
unsigned slave_address;
slave_address = 0x48;
unsigned char num_bytes = 1;
unsigned char num_count = 1;
unsigned char modifier = 0x80;
unsigned char set_stop = 1;
sciInit();
i2cInit();
i2cSetOwnAdd(i2cREG1, 1); //Own address
i2cSetSlaveAdd(i2cREG1, slave_address); // Slave address
i2cSetOwnAdd(i2cREG2, 2); //Own address
i2cSetSlaveAdd(i2cREG2, 1); // Slave address

do
{

sciReceive(sciREG1, 1, data); // poll for command to be received
data[0] = data[0] | modifier;
i2cSetCount(i2cREG1, num_count);
i2cSetStart(i2cREG1);
i2cSend(i2cREG1, num_bytes, data);
if (set_stop == 1) i2cSetStop(i2cREG1);
i2cSetMode(i2cREG1,I2C_MASTER);
}
while (TRUE);

} // end main()

The calls may not be in strict accordance wit the user guide but it was the only way I could get repeatable operation.

With the values as initialised, I can send repeated single byte messages (when the sensor command expects it) via keyboard entry.

If I use debug to modify the num_bytes and num_count to 3, I can send one string of the correct command byte for a 3-byte message - this is with set_stop set to 1 or zero.

It appears to terminate correctly but I cannot then get any activity on either line for a further command, unlike the single command mode.

Any suggestions appreciated.

Thanks

  • Hi King,

    Here is an example to send data repeatedly.

    /** @example example_i2cMaster_TX_RX.c
    *   This is an example which contains a sample I2C Master Transmit and 
    *   receive functionality. This example can be used to talk to any 
    *   I2C Slave at address 0x8 and Baud rate as configured in the HALCoGen 
    *   GUI which is by default 100KHz
    *
    */
    
    /* 
    * Copyright (C) 2009-2015 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 "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "HL_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++);
    
    	}
    
    	///////////////////////////////////////////////////////////////
    	//        Master Receive Functionality                      //
    	///////////////////////////////////////////////////////////////
    
    	/* Configure address of Slave to talk to */
    	i2cSetSlaveAdd(i2cREG1, Slave_Address);
    
    	/* Set direction to receiver */
    	i2cSetDirection(i2cREG1, I2C_RECEIVER);
    
    	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 */
    		i2cReceive(i2cREG1, DATA_COUNT, RX_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++);
    
    	}
    
    	asm(" nop");
    	asm(" nop");
    	asm(" nop");
    
    	while(1);
    
    /* USER CODE END */
    }
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    

  • Many thanks.