Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

TC74 interfacing problem with PIC18

Status
Not open for further replies.

ALIARIF93

Junior Member level 1
Joined
Jun 24, 2012
Messages
15
Helped
0
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
1,421
Hello,
please help me out
I'm interfacing TC74 with PIC18f4520 using I2C.But I'm unable to get temperature reading form TC74.
Can anyone check my error..
Thnx:-?
View attachment TC74 TESTING.rar
 

Hello jayanth.devarayanadurga
Im not using i2c.h header file..
I've made my functions BY consulting datasheet..
So my master side funtions are working(If i'm right)
TC74 is not sending data to PIC MCU
My read a byte function is below:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
void I2C_DATA_READ()
{ 
 SSPCON1bits.SSPOV=0;
I2C_IDLE();
SSPCON2bits.RCEN = 1;   ///ENABLE RECIEVE MODE  
 
while(!SSPSTATbits.BF);  //while recieve not complete
 //SSPCON2bits.RCEN = 0;   ///DISABLE RECIEVE MODE
 PORTB  =TEMP_READING;; 
 
}

 
Last edited by a moderator:

How do you know that TC74 is not sending data? How are you seeing the output? Are you displaying it on led or lcd?

What is the address you are using for TC74? Is it 0x9A?
 
Last edited:

Kindly Check my .C code file
 

Attachments

  • TC74_main.txt
    4.2 KB · Views: 123

ALIARIF93 : just found out that you are doing the same project as me. but i cant get my project to work as well...

- - - Updated - - -

is this the board you are using ?
 

Attachments

  • IMG_0085[1].JPG
    IMG_0085[1].JPG
    295.2 KB · Views: 86

how to do that? im not very good at programming
 

Just take the i2c code and see if any statement has to written according to C18. I think most or all of the i2c code doesn't need any changes. you just have to take the code of i2c_wait(), i2c_Read(), i2c_write(), etc...

The address of TC74 is 0x9A
 
Last edited:

jayanth.devarayanadurga: I've written new code..But it also not working.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<p18f4520.h>
#pragma config LVP = OFF
#pragma config OSC = HS
#include<i2c.h>
#include<delays.h>
 
void main()
{
while(1){
unsigned char  LastTemp;
DDRCbits.RC3 = 1;                 //Configure SCL 
                                    //as Input 
  DDRCbits.RC4 = 1;                 //Configure SDA 
                                    //as Input 
  SSPSTAT = 0x80;                   //Disable SMBus & 
                                    //Slew Rate Control 
  SSPCON1 = 0x28;                   //Enable MSSP Master 
  SSPADD = 119;                    //Fosc = 48MHs HS+PLL 
                                    //for 100kHz 
 // SSPCON2 = 0x00;                   //Clear MSSP Conrol Bits 
             
  IdleI2C();                      // ensure module is idle 
  StartI2C();                     // initiate START condition 
  while ( SSPCON2bits.SEN );      // wait until start condition is over 
 
 Delay10TCYx(10);
  WriteI2C( 0b10011011 );         // write Address 
  IdleI2C();                      // ensure module is idle 
  WriteI2C( 0 );                  // Select Temperature Register 
  IdleI2C();                      // ensure module is idle 
  RestartI2C();                   // generate I2C bus restart condition 
  while ( SSPCON2bits.RSEN );     // wait until re-start condition is over 
  WriteI2C( 0b10011011);          // WRITE Address 
  IdleI2C();                      // ensure module is idle 
  ReadI2C();                      // read in the temp 
  NotAckI2C();                    // send not ACK condition 
  while ( SSPCON2bits.ACKEN );    // wait until ACK sequence is over 
  StopI2C();                      // send STOP condition 
  while ( SSPCON2bits.PEN );      // wait until stop condition is over 
  
  LastTemp = SSPBUF;              // LastTemp is a Global unsigned char 
}  }

 
Last edited by a moderator:

You said that you are not using library functions then why have you included i2c.h?

And where did you get DDRx in PIC? DDRx are registers of AVR microcontrollers.

Code:
DDRCbits.RC3 = 1; //Configure SCL 
//as Input 
DDRCbits.RC4 = 1; //Configure SDA

This code is working. I put an led on RB0 and tried to check if(LastTemp != 0) then RB0 = 1 and led is lighting. So, LastTemp holds some value. You have to print the value of LastTemp on lcd and see what value it holds.

Code:
#include<p18f4520.h>
#pragma config LVP = OFF
#pragma config OSC = HS

#include<i2c.h>
#include<delays.h>

void main()
{
	unsigned int LastTemp = 0;
	TRISB = 0x00;
	PORTB = 0x00;
	SSPSTAT = 0x80; //Disable SMBus & 
	//Slew Rate Control 
	SSPCON1 = 0x28; //Enable MSSP Master 
	SSPADD = 119; //Fosc = 48MHs HS+PLL 
	//for 100kHz 
	// SSPCON2 = 0x00; //Clear MSSP Conrol Bits 
	
	while(1){

		IdleI2C(); // ensure module is idle 
		StartI2C(); // initiate START condition 
		while ( SSPCON2bits.SEN ); // wait until start condition is over 
		Delay10TCYx(10);
		WriteI2C( 0b10011010 ); // write Address 
		IdleI2C(); // ensure module is idle 
		WriteI2C( 0 ); // Select Temperature Register 
		IdleI2C(); // ensure module is idle 
		RestartI2C(); // generate I2C bus restart condition 
		while ( SSPCON2bits.RSEN ); // wait until re-start condition is over 
		WriteI2C( 0b10011011); // WRITE Address 
		IdleI2C(); // ensure module is idle 
		ReadI2C(); // read in the temp 
		NotAckI2C(); // send not ACK condition 
		while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over 
		StopI2C(); // send STOP condition 
		while ( SSPCON2bits.PEN ); // wait until stop condition is over 
		LastTemp = SSPBUF; // LastTemp is a Global unsigned char
		if(LastTemp != 0) {
			PORTBbits.RB0 = 1;
		} 
	} 
}

See the attached image. I have assigned the decimal value of TC74 reading to PORTD.

For temperature 27 degree C it is displaying 11011 which is equal to 0x1B and d27 which is right.

So, It is working.

Code:
#include<p18f4520.h>
#pragma config LVP = OFF
#pragma config OSC = HS

#include<i2c.h>
#include<delays.h>

void main()
{
	unsigned int LastTemp = 0;
	TRISB = 0x00;
	PORTB = 0x00;
	TRISD = 0x00;
	PORTD = 0x00;
	SSPSTAT = 0x80; //Disable SMBus & 
	//Slew Rate Control 
	SSPCON1 = 0x28; //Enable MSSP Master 
	SSPADD = 119; //Fosc = 48MHs HS+PLL 
	//for 100kHz 
	// SSPCON2 = 0x00; //Clear MSSP Conrol Bits 
	
	while(1){

		IdleI2C(); // ensure module is idle 
		StartI2C(); // initiate START condition 
		while ( SSPCON2bits.SEN ); // wait until start condition is over 
		Delay10TCYx(10);
		WriteI2C( 0b10011010 ); // write Address 
		IdleI2C(); // ensure module is idle 
		WriteI2C( 0 ); // Select Temperature Register 
		IdleI2C(); // ensure module is idle 
		RestartI2C(); // generate I2C bus restart condition 
		while ( SSPCON2bits.RSEN ); // wait until re-start condition is over 
		WriteI2C( 0b10011011); // WRITE Address 
		IdleI2C(); // ensure module is idle 
		ReadI2C(); // read in the temp 
		NotAckI2C(); // send not ACK condition 
		while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over 
		StopI2C(); // send STOP condition 
		while ( SSPCON2bits.PEN ); // wait until stop condition is over 
		LastTemp = SSPBUF; // LastTemp is a Global unsigned char
		if(LastTemp != 0) {
			PORTBbits.RB0 = 1;
			PORTD = LastTemp;
		} 
	} 
}
 

Attachments

  • aliarif i2c.rar
    27.8 KB · Views: 63
  • sim ss 25.jpg
    sim ss 25.jpg
    235 KB · Views: 91
Last edited:

jayanth.devarayanadurga : I was not using the right value for SSPADD...By setting Crystal frequency My code works..Thanks for help:|
 

:jayanth , how to trigger TC74 to display the temperature to LCD?
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
IdleI2C(); // ensure module is idle 
        StartI2C(); // initiate START condition 
        while ( SSPCON2bits.SEN ); // wait until start condition is over 
        Delay10TCYx(10);
        WriteI2C( 0b10011010 ); // write Address 
        IdleI2C(); // ensure module is idle 
        WriteI2C( 0 ); // Select Temperature Register 
        IdleI2C(); // ensure module is idle 
        RestartI2C(); // generate I2C bus restart condition 
        while ( SSPCON2bits.RSEN ); // wait until re-start condition is over 
        WriteI2C( 0b10011011); // WRITE Address 
        IdleI2C(); // ensure module is idle 
        ReadI2C(); // read in the temp 
        NotAckI2C(); // send not ACK condition 
        while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over 
        StopI2C(); // send STOP condition 
        while ( SSPCON2bits.PEN ); // wait until stop condition is over 
        LastTemp = SSPBUF; // LastTemp is a Global unsigned char
        if(LastTemp != 0) {
            PORTBbits.RB0 = 1;
            PORTD = LastTemp;



this one ?
 
Last edited by a moderator:

SSPADD = 119; //Fosc = 48MHs HS+PLL
//for 100kHz

what does this mean?

Fosc is the crystal frequency of the circuit..?
 

Fosc is the oscillator frequency, not the crystal frequency.

The 48MHz is achieved through the use of a Phase Lock Loop (PLL) which essentially multiplies the crystal frequency by a set rate.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top