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

I2C - TC74 giving me constant ...-1?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

I2C - TC74 giving me constant ...-1?
PostPosted: Sat Apr 12, 2008 10:07 am     Reply with quote

Hello guys,

I am trying to get the data from TC74 temperature sensor and it is giving me constant -1 ? Why is it?

Code:

#include <18F4685.h>
#device ICD=TRUE
#device ADC=10
#fuses HS,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=LCD, baud=9600, xmit=Pin_C6)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW)
#include <stdlib.h>


int temp=0;

void main()
{

   While(TRUE)
   {
      i2c_start();
      i2c_write(0x96);       //TC74A3
      i2c_write(0x00);

      i2c_start();
      i2c_write(0x97);
      temp = i2c_read(0);
      i2c_stop();


      fprintf(LCD, "%d",temp);
      delay_ms(500);
      fputc(0xFE, LCD);
      fputc(0x01, LCD);
      delay_ms(500);

   }
}


Last edited by Izzy on Sat Apr 12, 2008 11:15 am; edited 1 time in total
Ttelmah
Guest







PostPosted: Sat Apr 12, 2008 10:15 am     Reply with quote

Have you got the pull-up resistors on the two I2C lines?.
Double check the chip address. The default for the TC74, is 0x9A. Other addresses are special order parts.

Best Wishes
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 10:21 am     Reply with quote

Thanks for your reply.
Yes I have a 3.3k pull up resistor on SCL and SDA pin. I have also tried replacing 0x96 and 0x97 with 0x9A and 0x9B. But it gives me the same results.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 11:01 am     Reply with quote

I had an odd experience with the TC74A0. It had been running fine during the tests but accidentally
we leave it close to the hot air for a short time. For sure the internal analog module of the device
go away and after this, it output only -1ÂșC even at ambient temperature. May be the case?
Two comments:
1) Did you try with another device?
2) The TC74 MAXIMUM bus speed is 100KHz, try adding SLOW in the #use i2c parameters.


Humberto
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 11:09 am     Reply with quote

Hello,
Thanks for the reply. I really appreciate it.

I just bought that device from mouser couple days ago and I havent left it at any extreme temperature. I dont have another device to try it.

I tried using this, but it is still the same.
Code:
#use i2c(Master, Slow, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 11:21 am     Reply with quote

1. Do you for sure that you have a TC74A3 ? The data sheet says
on page 9 that the i2c address is 0x96 for that version of the chip.
http://ww1.microchip.com/downloads/en/DeviceDoc/21462c.pdf

2. Are you using a 40 MHz external oscillator (not a crystal) ?

3. Your i2c_read() statement is incorrect. The last i2c read operation
must do a "Not acknowledge" (NACK). This is part of the i2c spec.
In CCS, this is done by giving the function a 0x00 parameter.
Change your code so it looks like this:
Code:
temp = i2c_read(0);


4. If you still have problem, then remove the FORCE_HW parameter.
See if that helps.

5. Are you running this program in Debug mode, and trying to single-
step through it ? I advise that you remove Debug mode and run it as
a stand-alone normal program.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 11:36 am     Reply with quote

1. Do you for sure that you have a TC74A3 ? The data sheet says
on page 9 that the i2c address is 0x96 for that version of the chip.
http://ww1.microchip.com/downloads/en/DeviceDoc/21462c.pdf


Yes TC74A3 is written in the device. And yes I am using 0x96 and 0x97.




2. Are you using a 40 MHz external oscillator (not a crystal) ?

Yes I am using a 40mhz external oscillator (powered).



3. Your i2c_read() statement is incorrect. The last i2c read operation
must do a "Not acknowledge" (NACK). This is part of the i2c spec.
In CCS, this is done by giving the function a 0x00 parameter.
Change your code so it looks like this:
Code:
temp = i2c_read(0);


Sorry, I forgot to include that in this code, but yes I have tried with
temp = i2c_read(0);



4. If you still have problem, then remove the FORCE_HW parameter.
See if that helps.

I have tried removing the Force_HW. But it is still giving me -1.



5. Are you running this program in Debug mode, and trying to single-
step through it ? I advise that you remove Debug mode and run it as
a stand-alone normal program.


Yes, I was running in debug mode but not using single steps. I tried as a stand alone but it is still giving me -1
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 11:41 am     Reply with quote

I would carefully check all the connections. You will get 0xFF if the
i2c slave is not responding. What package are you using ? Is it
the SOT-23 or the TO-220 ? Verify that you understand the pinout.
Verify that SCL and SDA are not accidently swapped. SCL on the PIC
must go to SCL on the TC74, and SDA must go to SDA.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 1:06 pm     Reply with quote

PCM programmer wrote:
I would carefully check all the connections. You will get 0xFF if the
i2c slave is not responding. What package are you using ? Is it
the SOT-23 or the TO-220 ? Verify that you understand the pinout.
Verify that SCL and SDA are not accidently swapped. SCL on the PIC
must go to SCL on the TC74, and SDA must go to SDA.


I checked it again.


I have T220 Package.

Looking at the front side of the package.

From left to right:

pin 1 - no connection
pin 2 - Pin 23 of PIC (RC4/SDI/SDA)
Pin 3 - Gnd
Pin 4 - Pin 18 of PIC (RC3/SCK/SCL)
Pin 5 - 5v


Still I get -1.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 2:22 pm     Reply with quote

1. Is the PIC also running at +5v ?

2. Post your compiler version.

3. Post your latest test program.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 2:41 pm     Reply with quote

I appreciate all of your help!

Yes Pic is running at 5v (~4.95) through a voltage regulator.

Compiler Version 4.013

Here is my latest code:
Code:

#include <18F4685.h>
#device ICD=TRUE
#device ADC=10
#fuses HS,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)
#include <stdlib.h>
#include <math.h>


signed int temp=0;

void main()
{

   While(TRUE)
   {
      i2c_start();
      i2c_write(0x96);
      i2c_write(0x00);

      i2c_start();
      i2c_write(0x97);
      temp = i2c_read(0);
      i2c_stop();


      fprintf(LCD, "%d",temp);

      read_analog_pin();
      delay_ms(500);
      fputc(0xFE, LCD);
      fputc(0x01, LCD);
      delay_ms(500);

   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 2:53 pm     Reply with quote

Quote:
read_analog_pin();

What's this function ?
Is this your real test program ? If you're running a program
that's different from what you're posting here, then something
that we can't see could easily be causing the problem. You
have to post exactly what you're running.

Quote:
Compiler Version 4.013

That's a very early version in vs. 4. There could easily be problems
with it. I can look at the .LST file tomorrow. I could also try and
test it in hardware. I can't do very much more today.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Apr 12, 2008 3:06 pm     Reply with quote

Once again thanks for your help.

Sorry that function was for another test. I removed that and tried it again. It is still givng me -1.

This EXACTLY what I am running now.


Code:
#include <18F4685.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=LCD, baud=9600, xmit=Pin_C6)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)
#include <stdlib.h>

signed int temp=0;


void main()
{
   While(TRUE)
      {
         i2c_start();
         i2c_write(0x96);
         i2c_write(0x00);
   
         i2c_start();
         i2c_write(0x97);
         temp = i2c_read(0);
         i2c_stop();
   
   
         fprintf(LCD, "%d",temp);

         delay_ms(500);
         fputc(0xFE, LCD);
         fputc(0x01, LCD);
         delay_ms(500);
   
      }
}



I would really appreciate if you could take a look on LST files.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sun Apr 13, 2008 8:57 am     Reply with quote

Has anyone experienced such problem?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 13, 2008 11:52 am     Reply with quote

Quote:
Compiler Version 4.013

#include <18F4685.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT

I don't have vs. 4.013. I do have 4.011 and 4.014. I tried to compile
your latest program with both those versions and it won't compile.
It gives me this error message:
Quote:

Error 164 Line 2(9,18): Selected part does not have ICD debug capability
1 Errors, 0 Warnings.

I don't get this error if I compile it with vs. 4.071.


So I wonder how you are able to compile it with vs. 4.013.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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