CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

tmp102

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Linuxbuilders



Joined: 20 Mar 2010
Posts: 193
Location: Auckland NZ

View user's profile Send private message

tmp102
PostPosted: Sat May 16, 2015 3:23 am     Reply with quote

Just in case if anybody is having problems with a code for tmp102 and negative values here I put mine:

Code:


long tmptt;
float tmptf;
int tmp01;
int tmp02;
short neg; 

         //read temperature 12 bit value

         i2c_start();
         i2c_write(0x90);
         i2c_write(0x00);
         i2c_start();       
         i2c_write(0x91);
         tmp01 = i2c_read();
         tmp02 = i2c_read();
         i2c_Stop();             
         
         tmptt = make16(tmp01,tmp02);
         tmptt = tmptt >> 4;
         if (tmptt > 0x7FF)
         {
            tmptt = ~tmptt+1;
            neg = 0; //negative value                                                         
         }
         else
         {
            neg = 1; //positive value
         }
         tmptt =  tmptt * 0.0625;       
         tmptf = tmptt;

_________________
Help "d" others and then you shell receive some help from "d" others.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 16, 2015 11:05 am     Reply with quote

Quote:
i2c_start();
i2c_write(0x90);
i2c_write(0x00);
i2c_start();
i2c_write(0x91);
tmp01 = i2c_read();
tmp02 = i2c_read();
i2c_Stop();

You are missing the NACK on the last read, and that is part of the TMP102
specification. See page 12 in the TMP102 data sheet, and look at this
diagram: Figure 9. Two-Wire Timing Diagram for Read Word Format
http://www.ti.com/lit/ds/symlink/tmp102.pdf
The data sheet is poorly written in this area. It shows an ACK by the
master (the PIC) on the last read. But then down in notes 2 and 3,
it says the master (the PIC) should leave SDA high to terminate a one
or two-byte read operation. This is a NACK !

The Philips i2c specification says on page 10, in section 3.16:
Quote:

When SDA remains HIGH during this ninth clock pulse, this is defined as
the Not Acknowledge signal.

http://www.nxp.com/documents/user_manual/UM10204.pdf

So you should do a NACK on the last i2c_read(). This is done by giving
the function a parameter of 0.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group