Interfacing IR temperature Sensor (MLX 90615) with PIC

Discussion in 'Embedded Systems and Microcontrollers' started by M11, Jan 1, 2012.

  1. M11

    Thread Starter New Member

    Dec 27, 2010

    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 (

    I came across this thread :
    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:
    Code ( (Unknown Language)):
    1.      while (1)
    2.    {
    4.      I2C1_Init(50000);
    5.      I2C1_Start();                 // Issue start signal
    6.      I2C1_Wr(0xB6);             // Write Address
    7.      I2C1_Wr(0x07);              // address of  To Register
    8.      I2C1_Repeated_Start();               // Issue repeated start signal
    9.      I2C1_Wr(0xB7);             // Read Address  
    11.      DATA = I2C1_Rd(1);     //Read first byte (device Address)
    12.      DATA1 = I2C1_Rd(1);   //
    13.      DATA2 = I2C1_Rd(0);   //PCE Byte (You need to _NACK_ the last byte)
    15.      IntToStr(DATA,y);
    16.      Glcd_Write_text(y,0,3,1 );
    17.      delay_ms(500);
    18.      IntToStr(DATA1,y);
    19.      Glcd_Write_text(y,0,4,1 );
    20.      delay_ms(500);
    21.      IntToStr(DATA2,y);
    22.      Glcd_Write_text(y,0,5,1 );
    23.      delay_ms(500);
    24.      Glcd_fill(0);
    25.      delay_ms(100);
    26.     }
    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.

    Last edited: Jan 1, 2012
  2. M11

    Thread Starter New Member

    Dec 27, 2010
    I added 20ms delay after I2C initialization, still not working.
    Last edited: Jan 1, 2012
  3. M11

    Thread Starter New Member

    Dec 27, 2010

    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:
    183 ==> result of first read = 0xB7 which is the read address
    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: Jan 1, 2012
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    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.

    Sorry I no longer have access to that work.