Application Note MLX90614 SMBus implementation in PIC MCU Scope This application note describes how to implement SMBus communication with MLX90614 Infra-Red thermometers. Code is for Microchip’s PIC®18. The example is a read from MLX90614’s RAM. The software implementation of the SMBus communication is used so that the source code can be migrated for other families 8 bits PIC MCU with small changes. The development tools used are MPLAB IDE and MPASM (microchip assembler) which are free to use from www.microchip.com. Applications ■ High precision non-contact temperature measurements; ■ Thermal Comfort sensor for Mobile Air Conditioning control system; ■ Temperature sensing element for residential, commercial and industrial building air conditioning; ■ Windshield defogging; ■ Automotive blind angle detection; ■ Industrial temperature control of moving parts; ■ Temperature control in printers and copiers; ■ Home appliances with temperature control; ■ Healthcare; ■ Livestock monitoring; ■ Movement detection; ■ Multiple zone temperature control – up to 100 sensors can be read via common 2 wires ■ Thermal relay/alert ■ Body temperature measurement Related Melexis Products EVB90614 is the evaluation board which supports the MLX90614 devices. Other Components Needed Elements used in the schematics within current application note include: SMD ceramic capacitors C1 and C2 100nF 16V or higher. SMD ceramic capacitors C3 and C4 22pF 16V or higher. SMD Resistors R1 and R2 22 kOhm 5%. SMD Resistor R3 47 Ohm 5%. Quarz resonator Y1 8.00MHz PIC18F4320 microcontroller or other from the Microchip’s PIC18 family. Accompanying files: 1. MPASM files to include in existing project, “SMBusFiles” 2. MPLAB project, “SMBusProject” Project is build, file “main.hex” can be programmed in a PIC18F4320. Also, project can be used as a “start with” base. As provided the project will read Tobj,1 from MLX90614 (power supply control is not included), and transmit it via UART (ASCII coded, CR (0x0D) after each value, 8 bit data, one stop bit, no parity bit, 19 200 baud if a 11.0592 MHz crystal is used). Format is 15 bit unsigned integer, rightjustified. Resolution is 0.02 degrees Kelvin / LSB. Refer to explanation of the routines below for examples on the temperature format. 390119061403 Rev 001 Page 1 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU Typical Circuit Explanation Vdd R1 22k Vdd R2 22k U1 SCL SDA Vdd Vss U2 1 2 3 4 MLX90614 RC3/SCL Vdd RC4/SDA C1 100n C2 100n Vss OSC1 OSC2 PIC18Fmicro Y1 8MHz R3 47 C3 22p C4 22p The connection of MLX90614 to MCU is very simple. Two general purpose pins RC3 and RC4 of the PIC18 are used. Two pull up resistors R1 and R2 are connected to Vdd and to SCL and SDA lines respectively. C1 is the local power supply bypass decoupling capacitor. The MLX90614 needs that for bypassing of the on-chip digital circuitry switching noise. C2 has the same function for the microcontroller. The well known value 100nF (SMD ceramic type) is typically adequate for these components. Note that the power supply typically needs more capacitors (like 100µF on voltage regulator input and output), not shown on the schematic. The components R1, C3, C4 and Y1 are used for the MCU oscillator. On-chip RC oscillators can also be used. For example, with a PIC18F4320 internal RC oscillator set to 8 MHz can be used without problem. SMBus is synchronous communication and therefore is not critical to timings. With 8 MHz crystal (2 MIPs) the SMBus clock is 54 kHz and one read frame takes 1 ms. On a test setup the SMBus was working with PIC clock from 2 MHz to 11.0592 MHz. Refer to MLX90614 datasheets, Application Note 390119061402, “SMBus communication with MLX90614” and SMBus standard for details. MLX90614 comes in 5V and 3V versions. PIC18LF4320 could be used with the 3V version (MLX90614Bxx) and both PIC18F4320 and PIC18LF4320 – with the 5V version (MLX90614Axx). Below is the assembly language code. It consists of: - definition of the RAM usage (as well as PIC I/Os) - subroutines ;Name: START_bit ;Function: Generate START condition on SMBus ;Name: STOP_bit ;Function: Generate STOP condition on SMBus ;Name: TX_byte ;Function: Send a byte on SMBus ;Name: RX_byte ;Function: Receive a byte on SMBus ;Name: delay ;Function: Produces time delay depending on the value in counterL ;Name: PEC_calculation ;Function: Calculates the PEC of received bytes - Macros definitions - “Asembly of everything together” – main program Code ends with waveforms that the firmware generates. 390119061403 Rev 001 Page 2 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU Build and use What is needed to read the object temperature (refer to MLX90614 Data Sheet available at www.melexis.com for details): - use the accompanying MPLAB project, make a new one, or use existing one - “main.asm” file in both ZIPs: “SMBus files” and “SMBus project” that come with the current Application note is enough for full configuration of the PIC MCU, and it also contains the “include” directives for the other files used. Code that reads MLX90614 then consist of: MOVLW SA MOVWF SlaveAddress MOVLW RAM_Address|RAM_Access MOVWF command Readloop CALL MemRead Result will be in DataH:DataL. ; ; SA -> SlaveAddress ; Form RAM access command + RAM ; address ; Read RAM address Factory default SMBus Slave Address (SA) for all MLX90614 is 0x5A. The most important RAM addresses of MLX90614 are: RAM_Address Temperature read 0x06 Ta – die temperature 0x07 Tobj,1 – object temperature (MLX90614xAx) zone 1 object temperature (MLX90614xBx) 0x08 zone 2 object temperature (MLX90614xBx only). To read the die temperature (RAM address 0x06) of MLX90614 with slave address 0x5A (factory default) the code would be: MOVLW 0x5A MOVWF SlaveAddress MOVLW 0x06 MOVWF command Readloop CALL MemRead ; ; SA -> SlaveAddress ; Form RAM access command + RAM ; address ; Read RAM address DataH:DataL will consist of 15 bit temperature in unsigned integer, right-justified format. Resolution is 0.02 degrees Kelvin / LSB. For example, 0°K would be represented as 0x0000 0.02°K – 0x0001 0.04°K – 0x0002 Ta minimum for MLX90614 -40°C = 233.15°K – 0x2D8A Ta of +25°C = 298.15°K – 0x3A3C Ta maximum for MLX90614 +125°C = 398.15°K – 0x4DC4 To read Tobj,1 temperature: MOVLW 0x5A MOVWF SlaveAddress MOVLW 0x07 MOVWF command Readloop CALL 390119061403 Rev 001 MemRead ; ; SA -> SlaveAddress ; Form RAM access command + RAM ; address ; Read RAM address Page 3 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU Output temperature format will be the same, for example, DataH:DataL would be 0x3C94 for Tobj,1 = +37°C = 310.15°K. Note that the calibration ranges for MLX90614 are Ta -40…+125°C To -70…+382°C All MLX90614 accept SA=0x00. There are two important consequences of that: - any MLX90614 can be both read and written without knowing what SA is programmed in the EEPROM (if a single MLX90614 is present on the SMBus) - communication with more than one MLX90614 on an SMBus at SA 0x00 would not work For example, read of SA from a single MLX90614 on a SMBus would be: MOVLW 0x00 MOVWF SlaveAddress MOVLW 0x2E MOVWF command Readloop CALL MemRead ; ; SA -> SlaveAddress ; Form EEPROM access command + EEPROM ; address ; Read RAM address The Slave Address (read from EEPROM) would be on DataH:DataL. In this case the SA for the SMBus will be the right 7 bits. ERROR HANDLING: SMBus provides two general error indication mechanisms: - PEC, Packet Error Code, a CRC-based check of the entire communication frame - Acknowledge of each byte Code given with this Application Note handles these in the following manner: When a module returns “not acknowledge” then the firmware is trying to retransmit the byte again. The value in register Nack_Counter defines how many time the byte to be retransmitted in case that a module returns “not acknowledge”. Register PEC contains CRC calculated for the entire communication SMBus frame. This value is compared with the received value in the last byte of the message, which represents the CRC returned by the module. If they are not equal the entire message is retransmitted again. 390119061403 Rev 001 Page 4 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU SMBus subroutines used for communication with MLX90614 ;************************************************************************************************************ ; DEFINE GPR AND CONSTANT ;************************************************************************************************************ CBLOCK H' 00' TX_buffer TX_temp Bit_counter RX_buffer flagreg0 counterL DataL DataH PecReg SlaveAddress command Nack_Counter PEC4 PEC3 PEC2 PEC1 PEC0 PEC CRC4 CRC3 CRC2 CRC1 CRC0 CRC BitPosition shift ENDC ;delay constants #define TBUF d' 2' ;SMBus control signals #define _SCL_IO #define _SDA_IO #define _SCL #define _SDA TRISC,3 TRISC,4 PORTC,3 PORTC,4 ; ; ; RC3 is defined as SCL line ; RC4 is defined as SDA line #define bit_out #define bit_in flagreg0,0 flagreg0,1 ; Define the bit sent on SDA line in transmit mode ; Define the bit received from SDA in received mode #define RAM_Access 0x00 #define RAM_Address 0x07 #define SA 0x00 390119061403 Rev 001 ; Define the MLX90614 command RAM_Accsess ; Define address from MLX90614 RAM memory ; Define SMBus device address Page 5 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; START CONDITION ON SMBus ;************************************************************************************************************ ;Name: START_bit ;Function: Generate START condition on SMBus ;Input: No ;Output: No ;Comments: Refer to "System Management BUS(SMBus) specification Version 2.0" or ; 390119061402 application note for more information about SMBus ; comunication with a MLX90614 module ************************************************************************************************************ START_bit _SDA_HIGH MOVLW TBUF CALL delay _SCL_HIGH ;Set SDA line ; ; Wait a few microseconds ;Set SCL line MOVLW CALL ;Generate bus free time between Stop ;and Start condition (Tbuf=4.7us min) _SDA_LOW MOVLW CALL TBUF delay TBUF delay ;Clear SDA line ;Hold time after (Repeated) Start ;Condition. After this period, the first clock is generated. ;(Thd:sta=4.0us min) ;Clear SCL line _SCL_LOW MOVLW d' 5' CALL delay ;Wait RETURN ; End of “START_bit 390119061403 Rev 001 Page 6 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; STOP CONDITION ON SMBus ;************************************************************************************************************ ;Name: STOP_bit ;Function: Generate STOP condition on SMBus ;Input: No ;Output: No ;Comments: Refer to "System Management BUS(SMBus) specification Version 2.0" or ; 390119061402 application note for more information about SMBus ; comunication with a MLX90614 module ;************************************************************************************************************ STOP_bit _SCL_LOW MOVLW CALL _SDA_LOW TBUF delay MOVLW CALL TBUF delay ;Clear SCL line ; ; Wait a few microseconds ;Clear SDA line ;Wait _SCL_HIGH MOVLW TBUF CALL delay _SDA_HIGH ;Set SCL line ;Stop condition setup time ;(Tsu:sto=4.0us min) ;Set SDA line RETURN ; End of “STOP_bit” 390119061403 Rev 001 Page 7 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; TRANSMIT DATA ON SMBus ;************************************************************************************************************ ;Name: TX_byte ;Function: Send a byte on SMBus ;Input: TX_buffer ;Output: No ;Comments: If receiver don’t answer with ACK, the number of the attempts to be send will be ; equal of the value in Nack_Counter ;************************************************************************************************************ TX_byte LoadNACKcounter ; Set time out value MOVF TX_buffer,W ; MOVWF TX_temp ; Tx_buffer -> Tx_temp TX_again MOVLW MOVWF tx_loop BCF RLCF BTFSC BSF CALL DECFSZ Repeat D' 8' Bit_counter bit_out TX_buffer,F STATUS,C bit_out Send_bit Bit_counter,F ; 0 -> bit_out ; Tx_buffer<MSb> -> C ; C is 0 or 1? If C=0 don’t set bit_out ; 1 -> bit_out ;Send bit_out on SDA line ; All 8th bits are sent? If not, send next bit ,else check for ; acknowledgement from the receiver ; Send next bir ; Check for acknowledgement from the receiver ; If receiver has sent NACK stops the transmission ; End of “Tx_byte” GOTO CALL BTFSS RETURN tx_loop Receive_bit bit_in CALL DECFSZ GOTO RETURN STOP_bit ; Stops transmission Nack_Counter,F ; Repeat transmission till Nack_Counter become 0 Repeat ; The receiver don’t answer, stop the repeating CALL MOVF MOVWF GOTO START_bit TX_temp,W TX_buffer TX_again Send_bit BTFSC bit_out GOTO bit_high _SDA_LOW GOTO clock bit_high _SDA_HIGH NOP clock ; Load Bit_counter _SCL_HIGH 390119061403 Rev 001 ; Start transmission again ; ; Reload the sending byte in Tx_buffer again ; Send byte again ; If bit_out=0 send 0 on SDA line ; else send 1 on SDA line ; Clear SDA line ;Set SDA line ; Set SLC line Page 8 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP _SCL_LOW NOP NOP NOP RETURN 390119061403 Rev 001 ;| ;| ;| ;| ;| ;| ; > This defines the high level of clock pulse!!!!!!! ;| ;| ;| ;| ;| ;| ; Clear SCL line ;| ; > This defines the low level of clock pulse!!!!!!!! ;| ; End of “Tx_byte” Page 9 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; RECEIVE DATA ON SMBus ;************************************************************************************************************ ;Name: RX_byte ;Function: Receive a byte on SMBus ;Input: No ;Output: RX_buffer(Received byte),bit_in(acknowledge bit) ;Comments: ;************************************************************************************************************ RX_byte CLRF RX_buffer ; Clear the receiving buffer MOVLW D' 8' ; MOVWF Bit_counter ; Load Bit_counter BCF STATUS,C ;C=0 RX_again RLCF RX_buffer,F ; RX_buffer< MSb> -> C CALL Receive_bit ; Check bit on SDA line BTFSC bit_in ; If received bit is ‘1’ set RX_buffer<LSb> BSF RX_buffer,0 ; Set RX_buffer<LSb> DECFSZ Bit_counter,F ; ALL 8th bis are received? If no receive next bit GOTO RX_again ; Receive next bit CALL Send_bit ;Send NACK or ACK RETURN ; End of “RX_byte” Receive_bit BSF BSF _SCL_HIGH NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP BTFSS BCF _SCL_LOW NOP NOP NOP RETURN 390119061403 Rev 001 bit_in _SDA_IO _SDA bit_in ; Set bit_in ; Make SDA-input ; Set SCL line ;| ;| ;| ;| ;| ;| ; > This defines the high level of clock pulse!!!!!!! ;| ;| ;| ;| ;| ;| ; Read SDA line, if SDA=0 clear bit_in ; Clear bit_in ; Clear SCL line ;| ; > This defines the low level of clock pulse!!!!!!! ;| ; Bit is received Page 10 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; DELAY SUBROUTINE ;************************************************************************************************************ ;Name: delay ;Function: Produces time delay depending on the value in counterL ;Input: WREG ;Output: No ;Comments: ;************************************************************************************************************ delay MOVWF counterL ; WREG -> counterL counterL,f ; If (counerL=counterL-1) =0 go out DECFSZ BRA $-2 ; else decrement counterL again RETURN ; End of “delay” 390119061403 Rev 001 Page 11 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; CALCULATION CRC8 ;************************************************************************************************************ ;Name: PEC_calculation ;Function: Calculates the PEC of received bytes ;Input: PEC4:PEC3:PEC2:PEC1:PEC0:PEC- data registers ; CRC4:CRC3:CRC2:CRC1:CRC0:CRC- CRC value=00000107h ;Output: PEC ;Comments: Refer to 390119061402 application note for more information about SMBus ; comunication with a MLX90614 module ;************************************************************************************************************ PEC_calculation MOVLW 0x07 ;| MOVWF CRC ;| MOVLW 0x01 ;| MOVWF CRC0 ; > Load CRC value 0x0107 CLRF CRC1 ;| CLRF CRC2 ;| CLRF CRC3 ;| CLRF CRC4 ;| MOVLW MOVWF ;chech PEC4 for ' 1' BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA d' 47' BitPosition PEC4,7 shift_CRC BitPosition PEC4,6 shift_CRC BitPosition PEC4,5 shift_CRC BitPosition PEC4,4 shift_CRC BitPosition PEC4,3 shift_CRC BitPosition PEC4,2 shift_CRC BitPosition PEC4,1 shift_CRC BitPosition PEC4,0 shift_CRC ;check PEC3 for ' 1' DECF BitPosition BTFSC PEC3,7 390119061403 Rev 001 Page 12 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA ;check PEC2 for ' 1' DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA shift_CRC BitPosition PEC3,6 shift_CRC BitPosition PEC3,5 shift_CRC BitPosition PEC3,4 shift_CRC BitPosition PEC3,3 shift_CRC BitPosition PEC3,2 shift_CRC BitPosition PEC3,1 shift_CRC BitPosition PEC3,0 shift_CRC BitPosition PEC2,7 shift_CRC BitPosition PEC2,6 shift_CRC BitPosition PEC2,5 shift_CRC BitPosition PEC2,4 shift_CRC BitPosition PEC2,3 shift_CRC BitPosition PEC2,2 shift_CRC BitPosition PEC2,1 shift_CRC BitPosition PEC2,0 shift_CRC ;check PEC1 for ' 1' DECF BitPosition BTFSC PEC1,7 390119061403 Rev 001 Page 13 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA ;check PEC0 for ' 1' DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA DECF BTFSC BRA CLRF CLRF CLRF 390119061403 Rev 001 shift_CRC BitPosition PEC1,6 shift_CRC BitPosition PEC1,5 shift_CRC BitPosition PEC1,4 shift_CRC BitPosition PEC1,3 shift_CRC BitPosition PEC1,2 shift_CRC BitPosition PEC1,1 shift_CRC BitPosition PEC1,0 shift_CRC BitPosition PEC0,7 shift_CRC BitPosition PEC0,6 shift_CRC BitPosition PEC0,5 shift_CRC BitPosition PEC0,4 shift_CRC BitPosition PEC0,3 shift_CRC BitPosition PEC0,2 shift_CRC BitPosition PEC0,1 shift_CRC BitPosition PEC0,0 shift_CRC PEC4 PEC3 PEC2 Page 14 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU CLRF CLRF RETURN PEC1 PEC0 shift_CRC MOVLW SUBWF MOVWF BCF d' 8' BitPosition,W shift STATUS,C shift_loop MOVF BZ RLCF RLCF RLCF RLCF RLCF RLCF DECFSZ BRA shift,F xor CRC,F CRC0,F CRC1,F CRC2,F CRC3,F CRC4,F shift,F shift_loop xor MOVF XORWF MOVF XORWF MOVF XORWF MOVF XORWF MOVF XORWF MOVF XORWF BRA 390119061403 Rev 001 ; BitPosition-8 ->W ; Get shift value for CRC registers ; Read shift to force flag Z CRC4,W PEC4,F CRC3,W PEC3,F CRC2,W PEC2,F CRC1,W PEC1,F CRC0,W PEC0,F CRC,W PEC,F PEC_calculation Page 15 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU ;************************************************************************************************************ ; MACROS ;************************************************************************************************************ LoadNACKcounter MACRO MOVLW D' 255' ; The value in Nack_Counter defines MOVWF Nack_Counter ; time out if a device doesn’t send ACK bit ENDM ;-----------------------------------------------------------------------------------------------------------------------------_SDA_HIGH MACRO BSF _SDA_IO ; _SDA-input, SDA line is high from pull up ENDM ;------------------------------------------------------------------------------------------------------------------------------_SCL_HIGH MACRO BSF _SCL_IO ;_SCL-input, SCL line is high from pull up ENDM ;------------------------------------------------------------------------------------------------------------------------------_SDA_LOW MACRO BCF _SDA ; BCF _SDA_IO ; Clear SDA line ENDM ;------------------------------------------------------------------------------------------------------------------------------_SCL_LOW MACRO BCF _SCL ; BCF _SCL_IO ;Clear SCL line ENDM 390119061403 Rev 001 Page 16 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU Asembly of everything together ;************************************************************************************************************ ; Read MLX90614 RAM or EEPROM address subroutine ;************************************************************************************************************ ;Name: MemRead ;Function: Read specified RAM or EEPROM address of a MLX90614 module ;Input: SlaveAddress, command=RAM_Address(EE_Address) | ; RAM_Access(EE_Accsess) ;Output: DataH:DataL ;Comments: Refer to 390119061402 application note for more information about SMBus ; comunication with a MLX90614 module ;************************************************************************************************************ MemRead CALL START_bit ; Start condition MOVF MOVWF CALL SlaveAddress,W TX_buffer TX_byte ;| ; > Send SlaveAddress ;| MOVF MOVWF CALL command,W TX_buffer TX_byte ;| ; > Send command ;| CALL START_bit ; Repeat start condition MOVF MOVWF CALL SlaveAddress,W TX_buffer TX_byte ;| ; > Send Slave address ;| BCF CALL MOVFF bit_out RX_byte RX_buffer,DataL ; bit_out=0 ( master will send ACK) ; Receive low data byte ; Save it in DataL BCF CALL MOVFF bit_out RX_byte RX_buffer,DataH ; bit_out=0 ( master will send ACK) ; Receivehigh data byte ; Save it in DataH BSF CALL MOVFF bit_out RX_byte RX_buffer,PecReg ; bit_out=1 ( master will send NACK) ; Receivehigh PEC ; Save it in PecReg CALL STOP_bit ; Stop condition MOVF MOVWF MOVFF MOVF MOVWF MOVFF MOVFF SlaveAddress,W PEC4 command,PEC3 SlaveAddress,W PEC2 DataL,PEC1 DataH,PEC0 ;| ;| ;| ; > Load PEC3:PEC2:PEC1:PEC0:PEC ;| ;| ;| 390119061403 Rev 001 Page 17 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU CLRF PEC CALL MOVF XORWF BTFSS GOTO PEC_calculation ; Calculate CRC8, result is in PEC PecReg,W ; PEC,W ; PEC xor PecReg ->WREG STATUS,Z ; If PEC=PecReg go out MemRead ; Else repaet all transmission RETURN ;| ; End of RamMemRead ;************************************************************************************************************ ; MAIN PROGRAM ;************************************************************************************************************ ;Name: MAIN ;Function: Demonstrates the steps for implementation of a full SMBus frame :Input: ;Output: ;Comments: ;************************************************************************************************************ MAIN MOVLW MOVWF MOVLW MOVWF Readloop CALL BRA SA SlaveAddress RAM_Address|RAM_Access command ; ; SA -> SlaveAddress ; Form RAM access command + RAM ; address MemRead Readloop ; Read RAM address ; Read RAM address again END 390119061403 Rev 001 Page 18 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU Oscilograms Start Condition on SMBus (START_bit) Stop Condition on SMBus (STOP_bit) Full frame on SMBus (MemRead) Above each oscilogram is described what it is and in the parenthesis the subroutine which produces this oscilogram. 390119061403 Rev 001 Page 19 of 20 Dec-2006 Application Note MLX90614 SMBus implementation in PIC MCU Conclusion The example of this application note demonstrates reading of RAM memory of a MLX90614 module but it can be used for EEPROM reading if instead RAM_Access command is used EEPROM_Access command (refer to 390119061402 application note). ♦APPENDIX – RAM memory map Melexis reserved name address Melexis reserved Ambient sensor data IR sensor 1 data IR sensor 2 data Linearized ambient temperature Ta Linearized object temperature (IR1) TOBJ1 Linearized object temperature (IR2) TOBJ2 Melexis reserved TA1 (PKI) TA2 (PKI) Melexis reserved Temporary register Temporary register Temporary register Temporary register Temporary register Temporary register Scale for ratio alpha ROM alpha real Scale for alpha’s slope versus object temperature IIR filter TA1 (PKI) fraction TA2 (PKI) fraction Temporary register Temporary register Temporary register FIR filter Temporary register 390119061403 Rev 001 Page 20 of 20 0x00h … 0x02h 0x03h 0x04h 0x05h 0x06h 0x07h 0x08h 0x09h 0x0Ah 0x0Bh 0x0Ch 0x0Dh 0x0Eh 0x0Fh 0x10h 0x11h 0x12h 0x13h 0x14h 0x15h 0x16h 0x17h 0x18h 0x19h 0x1Ah 0x1Bh 0x1Ch Dec-2006