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

TC74 Interfacing with PIC18F452

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



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

TC74 Interfacing with PIC18F452
PostPosted: Fri Dec 28, 2012 3:39 am     Reply with quote

hi

I am trying to interface TC74 with pic18. The temperature reading appeared in proteus is 0. what is wrong with the code?
Code:

#include <18F452.h>   
#device ADC=10
#use delay (clock=4M)
#include <flex_for_test_lcd.c>  //LCD driver
#fuses HS,NOLVP,NOWDT,BROWNOUT,NOPROTECT,NOWRT
#fuses XT                     //for crystal
#use I2C(MASTER, scl=PIN_C3, sda=PIN_C4,FORCE_HW,slow )



void main(){

int8 temp;

//LCD

output_low(PIN_E2);
lcd_init();
lcd_putc("Temperature:");
   

//I2C

i2c_start();    // Start condition
i2c_write(0x9A); //device Address 0x9A
i2c_write(0x00); //temperature command

i2c_start();
i2c_Write(0x9B); 
temp = i2c_Read(0);
i2c_stop();     // Stop condition

printf(lcd_putc, "%u" temp);

}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 4:13 am     Reply with quote

Quote:

I am trying to interface TC74 with pic18. The temperature reading appeared in proteus is 0. what is wrong with the code?

Could be anything or nothing.

Proteus is your big mistake.

This is CCS forum, not Proteus.

Use REAL hardware. then see what happens.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 4:20 am     Reply with quote

Commonest mistake on I2C, is forgetting the pull up resistors.

Then the comments about Proteus....

Best Wishes
syeda amna



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 5:07 am     Reply with quote

Ttelmah, I used pull up resistors. Is there any thing wrong with the code.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: TC74 Interfacing with PIC18F452
PostPosted: Fri Dec 28, 2012 5:21 am     Reply with quote

syeda amna wrote:
hi

I am trying to interface TC74 with pic18. The temperature reading appeared in proteus is 0. what is wrong with the code?
Code:

#include <18F452.h>   
#device ADC=10
#use delay (clock=4M)
#include <flex_for_test_lcd.c>  //LCD driver
#fuses HS,NOLVP,NOWDT,BROWNOUT,NOPROTECT,NOWRT
#fuses XT                     //for crystal
#use I2C(MASTER, scl=PIN_C3, sda=PIN_C4,FORCE_HW,slow )



void main(){

int8 temp;

//LCD

output_low(PIN_E2);
lcd_init();
lcd_putc("Temperature:");
   

//I2C

i2c_start();    // Start condition
i2c_write(0x9A); //device Address 0x9A
i2c_write(0x00); //temperature command

i2c_start();
i2c_Write(0x9B); 
temp = i2c_Read(0);
i2c_stop();     // Stop condition

printf(lcd_putc, "%u" temp);

}


From a protocol perspective, your second i2c_start should be an i2c_restart
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
syeda amna



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 5:39 am     Reply with quote

Quote:
From a protocol perspective, your second i2c_start should be an i2c_restart


There is no such command i2c_restart();
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Dec 28, 2012 5:47 am     Reply with quote

syeda amna wrote:
Quote:
From a protocol perspective, your second i2c_start should be an i2c_restart


There is no such command i2c_restart();


That is an implementation issue. From a protocol perspective, it should be an I2C restart.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
syeda amna



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 5:50 am     Reply with quote

so what to do??
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 6:34 am     Reply with quote

1) get rid of Proteus..you'll waste half your life 'knowing' it has to be right, but it isn't!!

2) copy and run the I2C diagnostic program that's on this forum.I think the author is PCMprogrammer or Ttelmah...

3) search the library of this forum, someone may have posted their working driver...

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

Re: TC74 Interfacing with PIC18F452
PostPosted: Fri Dec 28, 2012 10:45 am     Reply with quote

asmallri wrote:

From a protocol perspective, your second i2c_start should be an i2c_restart

An I2C_START, issued when the bus is not stopped, _is_ a restart. Read the PIC data sheet.

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 12:26 pm     Reply with quote

I assume the code to work, if your TC74 device is default address option -A5.

In addition you should verify the LCD driver is not erroneously manipulating pin C3 and C4 settings.
syeda amna



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

PostPosted: Fri Dec 28, 2012 11:33 pm     Reply with quote

Thanks FvM. address option is A5. I have checked the code. This code is similar to other codes present in this forum. I dont know where is the problem. I also checked the LCD driver.
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Sat Dec 29, 2012 2:19 am     Reply with quote

Step through things in sequence:
1) Since you talk about the chip ID, hopefully you are testing with a real chip, not Proteus. The big problem with Proteus, is that almost every emulation in it has small errors, and unfortunately, it therefore does not always reflect the real world, implying you either waste time chasing these errors, or test something, think it'll work, and only then have to start chasing the differences on the 'real' chip.....

2) I'd specify a clock rate for the I2C. 'Slow' implies 100K communication. This is the absolute _maximum_ for the TC74. It should work, but try something like 25K.

3) What values are you using for the resistors, and how long are your lines?. There is a tendency for people to run with rather larger resistors than is really optimal, especially once wires start to get longer. Start with something under 4K7R.

4) On your code, you have both HS, and XT selected. Get rid of the HS selection.....

5) The actual part you need to have, is TC74A5-5.0VCT or TC74A5-5.0VAT

6) Test the bit value returned from i2c_write(0x9A). This will be the ACK from the chip. If it is not acknowledging, then it is not seeing the bus or responding. Another poster has mentioned the I2C bus scanner program, and this will also tell you if the chip is acknowledging.

Best Wishes
syeda amna



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

PostPosted: Sat Dec 29, 2012 3:17 am     Reply with quote

Ttelmah Great Exclamation

Quote:
2) I'd specify a clock rate for the I2C. 'Slow' implies 100K communication. This is the absolute _maximum_ for the TC74. It should work, but try something like 25K.


This solves my problem. I dont have hardware setup.
As I changed the frequency (25KHz) in proteus and CCS, it starts working.
Thanks to all.
Very Happy
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