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.

Check my SMBus protocol code for MLX90615

Status
Not open for further replies.

member_tdh

Member level 5
Joined
Feb 6, 2006
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,187
mlx90615

Hi everybody!

At the moment, I'm studying the SMBUS protocol. I'm making a project that use IR temperature ( MLX90615 ).

The result that i've receied alway is:
Tobj=382.19C
Tobj=382.19C
Tobj=382.19C
...

My code can wrong, could anybody help me...!!?

Thanks very very much!!!

This is my code:

"SMBus.h"

Code:
#ifndef __SMBUS_INCLUDE__
#define __SMBUS_INCLUDE__

#define     _SDA            7   //PORTD.7
#define     _SCL            6   //PORTD.6

#define     _SDA_OUTPUT     DDRD |= (1<<_SDA);
#define     _SDA_INPUT      DDRD &= ~(1<<_SDA);
#define     _SCL_OUTPUT     DDRD |= (1<<_SCL);

#define     mSDA_IN	        PIND.7

#define     mSDA_HIGH	    PORTD |= (1<<_SDA);
#define     mSDA_LOW        PORTD &= ~(1<<_SDA);
#define     mSCL_HIGH	    PORTD |= (1<<_SCL);
#define     mSCL_LOW        PORTD &=~ (1<<_SCL);


#define     TBUF            5
#define     HIGHLEV	        3
#define     LOWLEV	        1

#define     ACK	            0
#define	    NACK            1

#define     WRITE           0x00    // SMBus WRITE command
#define     READ            0x01    // SMBus READ command

#define     SA		        0x00	// SMBus Slave address
#define     DEFAULT_SA      0x5B	// Factory Default SMBus Slave address (MLX90615)
#define     RAM_Access	    0x00	// RAM access command
#define     RAM_Tobj1	    0x07	// To1 address in the eeprom
#define     EEPROM_Access   0x20	// EEPROM access command
#define     Read_Flags		0xF0
#define     SLEEP_mode		0xFF

extern void MLX90615_init(void);
extern void START_bit(void);
extern void STOP_bit(void);
extern void SendRequest(void);
extern void DummyCommand(BYTE);
extern float CalcTemp(WORD);
extern WORD read_RAM(BYTE slaveADDR, BYTE ADDR);
extern WORD read_EEPROM(BYTE slaveADDR, BYTE ADDR);
extern void Object_Temperature(void);
extern void Ambient_Temperature(void);
extern void TruyenByte(BYTE x);
extern BYTE NhanByte(BYTE ack_nack);

#endif


"SMBus.c"


Code:
void MLX90615_init(void)
{
        _SDA_OUTPUT;            // Set SDA as Output
        _SCL_OUTPUT;            // Set SCL as Output
        mSDA_HIGH;              // bus free
        mSCL_HIGH;
}


void START_bit(void)
{
        _SDA_OUTPUT;            // Set SDA as Output
        mSDA_HIGH;		        // Set SDA line
        mSCL_HIGH;		        // Set SCL line
        delay_us(TBUF);	        // Generate bus free time between Stop
                                // and Start condition (Tbuf=4.7us min)
        mSDA_LOW;		        // Clear SDA line
        delay_us(TBUF);	        // Hold time after (Repeated) Start
                                // Condition. After this period, the first clock is generated.
                                // (Thd:sta=4.0us min)
        mSCL_LOW;		        // Clear SCL line
}


void STOP_bit(void)
{
        _SDA_OUTPUT;            // Set SDA as Output
        mSDA_LOW;		        // Clear SDA line
        mSCL_HIGH;	            // Set SCL line
        delay_us(TBUF);	        // Wait a few microseconds
        mSDA_HIGH;		        // Set SDA line
        mSCL_LOW;        
}


void TruyenByte(BYTE x)
{
BYTE  i;
        
        _SDA_OUTPUT;                                // Set SDA as Output
        for(i=0;i<8;i++)
        {
            mSCL_LOW;
            if(x&0x80) mSDA_HIGH;
            else  mSDA_LOW;
            x<<=1;
            mSCL_HIGH;
            delay_us(20);
        }
        _SDA_INPUT;                 //SDA line as Input
        mSDA_LOW;                   //ack tai clock thu 9
        mSCL_LOW;
        mSCL_HIGH;
        if(mSDA_IN & 0x80) printf("MLX90615 writed error...ACK!\n\r");
        mSCL_LOW;
}

BYTE NhanByte(BYTE ack_nack)
{
BYTE i;
WORD byte=0;

        _SDA_INPUT;
        mSCL_LOW;
        for(i=0;i<8;i++)
        {
            byte<<=1;
            mSCL_HIGH;
            byte|=mSDA_IN;
            mSCL_LOW;
            delay_us(20);
        }
        _SDA_OUTPUT;                              //DATA-line in output
        PORTD.7=!ack_nack;                          //"ack==1" pull down DATA-Line
        mSCL_HIGH;
        delay_us(20);
        mSCL_LOW;
        //_SDA_INPUT;                            //DATA-line in input
        //mSDA_HIGH;
        return byte;
}

WORD read_RAM(BYTE slaveADDR, BYTE ADDR)
{
BYTE data_4lsb;
BYTE data_4msb;
BYTE data_crc;
WORD data;
        
        START_bit();
        TruyenByte(slaveADDR);
        TruyenByte(ADDR|RAM_Access);
        START_bit();
        TruyenByte(slaveADDR|0x01);
        data_4lsb = NhanByte(ACK);
        data_4msb = NhanByte(ACK);
        data_crc  = NhanByte(ACK);
        STOP_bit();
        
        data=(WORD)data_4msb<<8|data_4lsb;
        return data; 
}

"main.c"


Code:
/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.8d Professional
Automatic Program Generator
© Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
[url]http://www.hpinfotech.com[/url]

Project : 
Version : 
Date    : 7/20/2009
Author  : F4CG                            
Company : F4CG                            
Comments: 

Chip type           : ATmega32
Program type        : Application
Clock frequency     : 8.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 512
*****************************************************/

#include "mega32.h"
#include "global.h"
#include "SMBus.c"


void main(void)
{
delay_ms(100);      //Power Startup Stable

PORTA=0x00;
DDRA=0xFF;

PORTB=0x00;
DDRB=0xFF;

PORTC=0x00;
DDRC=0xFF;

PORTD=0x00;
DDRD=0xFE;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// Global enable interrupts
//#asm("sei")


printf(" --------------------------------------- \n\r");
printf(" ------------ IR TEMPERATUR ------------ \n\r");
printf(" ------------    MLX90615   ------------ \n\r");
printf(" --------------------------------------- \n\r");

MLX90615_init();
delay_ms(200);		                //Wait after POR,Tvalid=0.15s 

    while (1)
    {
        
            Object_Temperature();
            delay_ms(1000);        
        
        
        
        
        
        
    };//end while
}//end main

void Object_Temperature(void)
{
WORD temperature;

        temperature = read_RAM(0x00, 0x07);
        printf("Tobj=%d.%dßC \n\r", ((temperature*2)-27315)/100, ((WORD)((temperature*2)-27315))%100);
}
 
Last edited by a moderator:

mlx90615 smbus

what the heck is SMBus ?? Post some details about this
 

    member_tdh

    Points: 2
    Helpful Answer Positive Rating
smbus ack

Hi!

SMBus (sensor MLX90615) similar I2C but difference the fomat data.

You can find the doccuments on : www.melexis.com

:D

and help me...pls!?
 

mlx90615

Have you resolved this yet?
I think that your command bytes for RAM and EEPROM are wrong. From the table in section 8.4.6 of the datasheet I think they should be:
#define RAM_Access 0x20 // RAM access command
#define EEPROM_Access 0x10 // EEPROM access command

However, i must admit that I've not got it to work either yet... If anyone has any example code that is working please help us out.
 

smbus+mlx90615

Hurray!! - It is now working properly with the RAM address that I quoted above (having enabled PIC option for SMBus compatible voltage levels). Getting the CRC code to generate the correct values for the PEC byte took a bit of effort but all OK. If anyone else is still struggling with this please let me know as I'm happy to share code/experience.
 

Re: SMBus with MLX90615

Hello ,

I am also doing IR sensor MLX90615 using with PIC16F.
Now i am facing the problem. The result is always same when reading several times. I used the assembly language.


Please help to me! :D
Thanks
 

Re: SMBus with MLX90615

I am facing the same problem with PIC32 board. Would you send the properly working code to wzxfn_116@hotmail.com. Thank you very much:D
 

SMBus with MLX90615

i use 89c4051 to control MLX90615, but i only received low data byte, the high, REC data was disappear in my Logic Analyzers. some one could help me!
 

SMBus with MLX90615

Hi,I am using the sensor for a project as well.I am however using i2c.I am yet to get it working though.Have you any success with this sensor?
 

Re: SMBus with MLX90615

I made sensor's array with MLX90615 controlled with PIC18F13K50, with no additional parts like switches, MUX, etc... Work perfect. PEC control not requires with correct layout design. In the first version used table based PEC. The final version doesn’t implement PEC. My design support up to 24 MLX90615 devices simultaneously with no address changes (5Bh factory address used).
Read/Write SMB clock about 30 KHz (read) 35 KHz (write) with 16 MHz internal PIC18F13K50 oscillator.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top