View previous topic :: View next topic |
Author |
Message |
syeda amna
Joined: 28 Dec 2012 Posts: 21
|
TC74 Interfacing with PIC18F452 |
Posted: Fri Dec 28, 2012 3:39 am |
|
|
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
|
|
Posted: Fri Dec 28, 2012 4:13 am |
|
|
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: 19504
|
|
Posted: Fri Dec 28, 2012 4:20 am |
|
|
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
|
|
Posted: Fri Dec 28, 2012 5:07 am |
|
|
Ttelmah, I used pull up resistors. Is there any thing wrong with the code. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: TC74 Interfacing with PIC18F452 |
Posted: Fri Dec 28, 2012 5:21 am |
|
|
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
|
|
Posted: Fri Dec 28, 2012 5:39 am |
|
|
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
|
|
Posted: Fri Dec 28, 2012 5:47 am |
|
|
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
|
|
Posted: Fri Dec 28, 2012 5:50 am |
|
|
so what to do?? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Fri Dec 28, 2012 6:34 am |
|
|
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: 19504
|
Re: TC74 Interfacing with PIC18F452 |
Posted: Fri Dec 28, 2012 10:45 am |
|
|
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
|
|
Posted: Fri Dec 28, 2012 12:26 pm |
|
|
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
|
|
Posted: Fri Dec 28, 2012 11:33 pm |
|
|
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: 19504
|
|
Posted: Sat Dec 29, 2012 2:19 am |
|
|
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
|
|
Posted: Sat Dec 29, 2012 3:17 am |
|
|
Ttelmah Great
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.
|
|
|
|