# Interfacing IR temperature Sensor (MLX 90615) with PIC

#### M11

Joined Dec 27, 2010
18
Hi,

I am trying to read temperature from MLX90615ssg-daa infra red temperature sensor using PIC18F4550. The Sensor uses SMBus, and I am using the I2C library of the mikroC compiler (http://www.mikroe.com/download/eng/...krobasic/pro/pic/help/i2c_library.htm#i2c1_rd).

I came across this thread : http://www.ccsinfo.com/forum/viewtopic.php?t=45147
where a similar question was asked. I tried to use the same code, but it did not work.

This is the code I have written:
Rich (BB code):
     while (1)
{

I2C1_Init(50000);
I2C1_Start();                 // Issue start signal
I2C1_Wr(0x07);              // address of  To Register
I2C1_Repeated_Start();               // Issue repeated start signal

DATA1 = I2C1_Rd(1);   //
DATA2 = I2C1_Rd(0);   //PCE Byte (You need to _NACK_ the last byte)

IntToStr(DATA,y);
Glcd_Write_text(y,0,3,1 );
delay_ms(500);
IntToStr(DATA1,y);
Glcd_Write_text(y,0,4,1 );
delay_ms(500);
IntToStr(DATA2,y);
Glcd_Write_text(y,0,5,1 );
delay_ms(500);
Glcd_fill(0);
delay_ms(100);
}
Nothing is displayed on the screen, which indicates that there is no communication between the two devices.

The problem is not from the display code, because I have tested it and it is working.

I connected the sensor as suggested in the data sheet (available here).

The PIC is powered using 5v, then I use a voltage divider to get 3.3v which powers the IR sensor. The SDA and SCL are connected through a bidirectional voltage translator (using mosfet and 2 resistors).

I would really appreciate it if someone can help me figuring out what is wrong.

Thanks

Last edited:

#### M11

Joined Dec 27, 2010
18
I added 20ms delay after I2C initialization, still not working.

Last edited:

#### M11

Joined Dec 27, 2010
18
Update:

I changed the voltage divider to 3 diodes in series to get 3.3v which powers the sensor. I also found that one of the MOSFETs (logic translator) is not working properly.

I fixed those problems, and I can see the values on the GLCD.

The problem is that I don't understand what these values are. I only want the temperature.
The values I get are:
170 ==> result of second read
111 ==> result of third read

I also added this line to the code after initializing the I2C.

SSPSTAT.CKE=1; // Enable SMBus specific inputs

The problem is that I don't understand what these values represent. It seems that non of them represent the temperature, because I tried to place hot and cold objects above the sensor but non of the values changed.
I can't think of any solution. I thinks it is most likely that the sensor is damaged (although it is new).
What do you think guys ?

Last edited:

#### ErnieM

Joined Apr 24, 2011
8,132
I used this device (or a similar one) a few years ago. The hard part was computing the "Packet Error Code" byte which is a CRC-8 check sum. If this check sum is not correct for the data you are sending the transmission is ignored. That makes any set-up instructions hard to do.