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.

TMP513 I2C Code Example

Other Parts Discussed in Thread: TMP513

Hi,

Could anyone point me to a C or C++ example for TMP513 I2C ? 

Thanks!

  • Andres,

    I am currently looking into this and will get back to you shortly. 

  • Hi Chris, thanks for your message. Did you have a chance to look into it ?

     

    Thanks,

    Andres

  • Andres,

    The TMP513 is an I2C device. I wasn't able to find C code specific to the TMP513 however we do have I2C C code examples that you can use. The only parameters you will have to change will be the device address as well as register pointer address. You can find I2C C code examples under the following link.

    Launchpad Link:  http://www.ti.com/tool/msp-exp430g2     

    After clicking on the Launchpad link scroll down on the page and you will see under related products a TI Software tab as shown below. Here you will find an example code folder that you can download.


    In this folder you see a read me file that describes all the different examples contained within this folder. Scroll through this and you will find I2C example code as shown below.

  • Hi Chris,

    Thanks for your response and for the information provided.  I looked at the examles you suggested, but they are very specific to the MSP430. However, at this point I have written the I2C interface for my specific device, but still looking for a code example to read and write data to the TMP513. Are you aware of any SPI examples to do this? How did Engineers at TI test reading and writing to TMP513 before releasing the product ?

    Thanks for your help. Any information you can share will be appreciated.

    Andres

  • Andres,

    Unfortunately we don't have C I2C source code for the TMP513. We have only written software for this product in LabView. This source code can be downloaded from the TMP513 page (http://www.ti.com/product/tmp513). This software accompanies our evaluation module which can be found on the same web page. 

    Since I2C is a strict standard you can use any I2C read and write commands as an example for your platform. SPI however is not a strict standard so it will be more difficult to follow examples from platform to platform.

    What micro-controller are you using? I may have better luck searching based on the micro-controller you will be using.

  • Hi Chris,

    I wrote the I2C code to communicate with another sensor. Now, I need to make it work with the TMP513. I will let you know if I have specific questions about TMP513.

    Thanks,

    Andres

  • Hi Chris,

    I'm trying to write to Write and Read from the Configuration Register 1. Having some issues with the reading part as the MSByte is returned but not the LSByte.

    On the TMP513 datasheet, page17, the figure shows for a read I should send a Two Wire Slave address byte, then read the MSByte and then the LSByte. On the I2C code, I'm attempting to read the MSB and then the LSB. However it seems as if the is not read. If I write a value of 0x0107 and I try to read it back twice expecting the MSB and LSB, I will get 01 twice but not the 07.

    Do you have any suggestions?

    Thanks!

  • Andres,

    To write to and read from the configuration register you can follow the timing diagram on page 17 as you said. One catch is that in doing so you will write and read from the last register that was pointed to. If a new register is desired, the register pointer must be updated. In other words you must point to the new register that you would like to write and read from.

    It looks like you may not be sending the data correctly. Let me provide an example of writing to and reading back from Configuration Register 1.

    Example:

    Let's say we are interested in adjusting the PGA settings. We will modify bit D12 in Configuration Register 1 to be zero. You send the data with the MSB first followed by the LSB. Below this is done as follows:

                      0x29 (TMP513_Acknowledges) 0x9F (TMP513_Acknowledges)

    Here is the process I used:

    Write 0x29 for the high byte and 0x9F for the low byte as follows:

    1)  Master starts communication

    2)  Master sends Two-Wire 7bit Slave Address

    3)  Master sends R/W bit low (I include the read and write bit into the TMP513 address, 0xB8 above)

    4)  Master waits for TMP513 to acknowledge

    5)  Master sends Register Pointer Address Byte

    6)  Master waits for TMP513 to acknowledge

    7)  Master sends Data MSB 0x29

    8)  Master waits for TMP513 to acknowledge

    9)  Master sends Data LSB 0x9F

    10) Master waits for TMP513 to acknowledge

    11) Master stops communication

    Read back what was written from Configuration Register as follows:

    1)  Master starts communication

    2)  Master sends Two-Wire 7bit Slave Address

    3)  Master sends R/W bit low (I include the read and write bit into the TMP513 address, 0xB8 above)

    4)  Master waits for TMP513 to acknowledge

    5)  Master sends Register Pointer Address Byte

    6)  Master waits for TMP513 to acknowledge

    7)  Master starts communication again

    8)  Master sends Two-Wire 7bit Slave Address

    9)  Master sends R/W bit high (I include the read and write bit into the TMP513 address, 0xB9 above)

    10) Master waits for TMP513 to acknowledge

    11) Master reads first byte MSB and acknowledges

    12) Master reads second byte LSB and acknowledges

    13) Master stops communication

  • Andres,

    Please provide your code. I should be able to identify the issue.

  • Andres,

    I would like to also provide visually my process that I have written above.Please note that I am counting clock pulses and looking at the corresponding data that is written and read. If the below images are difficult to see please click on the attached power point I have put together.

    TMP513 Commincation.ppt
  • Chris,

    Thank you very much for your help and all the excellent information provided. I'm attaching the code snippet (I2C) that is attempting to read the values back (after writing 0x0107 value to config register1.)
     
    2313.TMP513_Read_Data.txt
        unsigned int lsb = 0;
        unsigned int msb = 0;
    
       *pTWIMITR = 20 | TWIEN;
      
       *pTWIDIV = 0x0000C0D;
       
       *pTWIFIFOCTL = TWIBHD;	
    		
        *pTWIMADDR = device_address;
      
        *pTXTWI8 = register_address;
        
        *pTWIMCTL = TWIDCNT1|TWIFAST|TWIMEN;
        while(*pTWIFIFOSTAT & TWITXS) 
        {
    	   enable_mode_loop_counter++;
    	   if (enable_mode_loop_counter >= TWI_LOOP_LIMIT)
    	   {
    	   	  break;
    	   }
        }	
    	
        
        *pTWIMCTL = TWIDCNT1|TWIMEN|TWIMDIR;
        while((*pTWIFIFOSTAT & TWIRXS) == 0) 
        {
    	   enable_mode_data_loop_counter++;
    	   if (enable_mode_data_loop_counter >= TWI_LOOP_LIMIT)
    	   {
    	   	  break;
    	   }
        }	
    
        msb = *pRXTWI8;
        *data = msb;
        
        *pTWIMCTL = TWIDCNT1|TWIMEN|TWIMDIR;
        while((*pTWIFIFOSTAT & TWIRXS) == 0) 
        {
    	   enable_mode_data_loop_counter++;
    	   if (enable_mode_data_loop_counter >= TWI_LOOP_LIMIT)
    	   {
    	   	  break;
    	   }
        }	
    
        lsb = *pRXTWI8;
        
        *data = lsb|(msb<<8);
            
        while(*pTWIMSTAT & TWIMPROG) 
        {
    	   transfer_complete_loop_counter++;
    	   if (transfer_complete_loop_counter >= TWI_LOOP_LIMIT)
    	   {
    	   	  break;
    	   }
        }			

    Let me know if you have any suggestions.

    Thanks!