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 CCS Technical Support

TC74A0 Temperature sensor giving me constant 255 ???

 
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

TC74A0 Temperature sensor giving me constant 255 ???
PostPosted: Thu Jul 10, 2008 8:44 pm     Reply with quote

Hello Folk,

I have been having this problem with TC74 temperature sensor. No matter what I do its always giving me constant 255?? Why is it?

I had this problem long ago and I couldnt fix it. So I thought the TC74 I had was bad. Today I bought another one, and it does the same thing.

I have TC74A0 and according to the data sheet I should use 0x90 and 0x91 for read and write address. But it is still giving me constant 255.


Yes I have searched and read a lot in this forum but I couldnt fix it. So desperately seeking for help.

Here is my sample code:


Code:
#include <18F4685.h>
#device ICD=TRUE
#device HIGH_INTS=true
#device ADC=10

#fuses HS,NOLVP,NOWDT
#use delay(clock=40,000,000)
#use rs232(stream=LCD, baud=9600, xmit=Pin_C6)
#use rs232(stream=debug, DEBUGGER)
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3)
#include <stdlib.h>
#include <math.h>

int temp=0;

void main()
{
While(TRUE)
   {
      i2c_Start();
      i2c_Write(0x90);
      i2c_Write(0x00);

      i2c_Start();
      i2c_Write(0x91);
      temp = i2c_Read(0);
      i2c_stop();

            fprintf(debug, "Temp = %u\n",temp);
            delay_ms(100);
   }
}






ANY help will be greatly appreciated!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 10, 2008 9:13 pm     Reply with quote

Typically, you will read 0xFF if the i2c slave is not responding.
This could be caused by leaving off the pull-up resistors, or
using the wrong slave address, or swapping the sda and scl lines,
or something else.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 4:40 am     Reply with quote

Hello PCM Programmer,
Thanks for your reply.

I have checked the connections and they are not swapped. I have 3.3k pullup resistor on both I2C lines. And I have checked the addresses too. But it is still giving me constant 255?? Why?

According to data sheet I am suppsed to use 0x90 and 0x91 for read and write addresses right? I have also tried 0x9A and 0x9B.

On page 13:
http://ww1.microchip.com/downloads/en/devicedoc/21462c.pdf


Any clue?


Last edited by Izzy on Fri Jul 11, 2008 5:32 am; edited 1 time in total
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 4:49 am     Reply with quote

Infact I have checked all the possible addresses now. And still no luck.

Voltage measurement at PINs:

VDD = 4.95V
SCLK = 4.85V
GND = 0V
SDA = 4.85V

Incase if it helps..here is the picture of the breadboarded circuit:
http://img363.imageshack.us/img363/2861/dsc00684zi4.jpg




Thanks
Ttelmah
Guest







PostPosted: Fri Jul 11, 2008 8:47 am     Reply with quote

Some small comments.
Add decoupling close to the PIC. You should get into the 'habit' of this, especially if working on a setup like a breadboard. 0.1uF, right close to the supply pins. Do the same close to the temperature sensor, and the LCD.
Try setting an I2C clock rate. The TC74, supports 100K _max_. I don't know what the default I2C rate will be from the compiler, but it might well be selecting a faster rate than this.
90, and 91, should be correct for the address.
Try adding an I2C stop, rather then using the restart. So:
Code:

      i2c_Start();
      i2c_Write(0x90);
      i2c_Write(0x00);
      i2C_stop();
      i2c_Start();
      i2c_Write(0x91);
      temp = i2c_Read(0);
      i2c_stop();

There is a problem on some PICs, when using hardware I2C, with the restart, not working quite properly.

Best Wishes
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 4:32 pm     Reply with quote

Thanks for your reply.

I tried adding an I2C stop, rather then using the restart. But still its giving me 255.
I have also tried adding SLOW :

#use i2c(Master,SDA=PIN_C4, SCL=PIN_C3, Force_HW, Slow)

Still same problem.


How do I set I2c clock rate? I am using 40Mhz oscillator.

Thanks
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 4:49 pm     Reply with quote

OK now this is very WEIRD!

I am getting the reading, but only If I touch pin C4 (i.e. SDI/SDA pin) with a metal or my skin. I touched it with the probe of my DMM. Just 1 probe. It started giving me

25
25
(I warmed up the sensor)
26
26
27
28..

So its working, BUT only if I keep touching that C4 pin with a my skin or metal. If I leave, it goes back to 255??


WHY is it Shocked ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 8:10 pm     Reply with quote

You have found the problem to be related to the voltage levels on the I2C lines. Touching the lines with your hand or a probe will add extra capacitance.

Do you have by any chance a series resistor on the I2C lines? If yes, than this resistor in combination with the pull-up resistor would create a voltage divider and the voltage wouldn't go low enough.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 9:22 pm     Reply with quote

Hmm..As far as I know, I dont have a voltage divider on I2c lines. Confused


Please take a look at the circuit, incase if I am not seeing one.

http://img363.imageshack.us/img363/2861/dsc00684zi4.jpg
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 11, 2008 10:30 pm     Reply with quote

What is the MCLR pin connected to ? This is pin 1 on the PIC.
It looks like there is a yellow wire that goes up to the LCD.
If you are using pin1 as an input (RE3), then you need to add
the NOMCLR fuse to your #fuses statement. If you are using
it as a MCLR pin, then you should have a 10K pull-up on it, and
don't connect it to anything else.

Also, add 100 nF (0.1uF) ceramic capacitors between the Vdd and Vss
pins on each side of the PIC. Your photo doesn't show any caps.

Also, the way you did this breadboard is not the best. I would have
put the PIC in the middle of one of the breadboard sections. You have
it straddling the power and GND bus. If you had put it in the middle
of a breadboard section, then there would be only a short distance
between the Vdd and Vss pins on each side of the PIC, and the busses
on the breadboard. That would be a much cleaner layout, and much
better electrically. With your existing layout, you have snaked the
+5v and Gnd wires around the bottom of the PIC, to connect to the
Vdd and Vss pins on the top side. That's not the best way.

Also, I would have used one color (Red) for +5v and black for GND.
Then use another color for signal wires (white or something).
Then it's very clear where the power and Gnd wires are going.
Ttelmah
Guest







PostPosted: Sat Jul 12, 2008 2:24 am     Reply with quote

For the I2C 'speed', you can set what 'slow', and 'fast', actually give (in compilers for the last couple of years), using (for example):

SLOW=60000

I'd rewire the whole of this section of the layout. Add the capacitors both PCM, and myself mentioned, replace the actual wires used, and improve the ground run to both the PIC, and the chip. You may have something as 'simple', as a resistive connection on the C4 pin, or the connection at the TC that goes to this.

Best Wishes
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Jul 12, 2008 3:11 pm     Reply with quote

Thanks a lot guys for your advices! I really appreciate them.

Quote:
What is the MCLR pin connected to ? This is pin 1 on the PIC.
It looks like there is a yellow wire that goes up to the LCD.
If you are using pin1 as an input (RE3), then you need to add
the NOMCLR fuse to your #fuses statement. If you are using
it as a MCLR pin, then you should have a 10K pull-up on it, and
don't connect it to anything else.


The MCLR is connected to the RJ11 jack. Yes there is a 47k pull up resistor. Its underneath the LCD, so it might looks like the wire is going to the LCD but its not. That is a serial LCD, I only have 3 wires on the right of the picture.


Quote:
Also, the way you did this breadboard is not the best. I would have
put the PIC in the middle of one of the breadboard sections. You have
it straddling the power and GND bus. If you had put it in the middle
of a breadboard section, then there would be only a short distance
between the Vdd and Vss pins on each side of the PIC, and the busses
on the breadboard


Yes I agree, but for some reason I didnt think about it before. Confused



As Ttelmah and PCM programmer has suggested, I have added capacitor on both Vcc and Vss side of the PIC. But I am still facing the same problem.


@ ckielstra
Quote:
Touching the lines with your hand or a probe will add extra capacitance


If you dont mind can you please explain a lil more in detail?



I am still trying, anyone's feedback would be greatly appreciated.
Izzy



Joined: 27 May 2007
Posts: 106

View user's profile Send private message

PostPosted: Sat Jul 12, 2008 4:57 pm     Reply with quote

Phew!

Finally a 10K resistor instead of 3.3K in the SDA line solved the problem.

Thanks a lot guys!
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