Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: October 30, 2010, 09:44:39 pm
Ahh, this is frustrating. I've searched all over the net for information to help me out. So far everything I've tried has failed. What am I doing wrong?

Shouldn't this code work too?

#include <Wire.h>

void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("Hello!");
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data )
{
  int rdata = data;
  Wire.beginTransmission(deviceaddress);
  Wire.send((int)(eeaddress >> smiley-cool); // MSB
  Wire.send((int)(eeaddress & 0xFF)); // LSB
  Wire.send(rdata);
  Wire.endTransmission();
  delay(5);
}

void loop()
{
   i2c_eeprom_write_byte(0x5A, 0x24, 0x0000); //Erase (write 0)
   Serial.println("Write Done");
   delay(5000);
}


I think my problem is not properly writing to the MSB and LSB. Any feedback at all would be much appreciated. I'm just spinning my wheels right now. This shouldn't be that hard!   >smiley-sad
2  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: October 30, 2010, 12:38:00 pm
I'm making some progress. Slowing understanding more how this I2C communication works. I figured out that the addresses shown in table 5 on page 11, must have 20 added to them. So 0x004 becomes 0x024x. Someone can probably explain the reason why better.

So I can now read the existing emissivity coefficient correctly. High & low byte = 255, which gives you 65535 combined. Exactly what the data sheet says.

In order to write a new value you must first erase (write 0) to the cell, and then proceed to write your value. This is where I am having problems. Take a look at my code.

#include <i2cmaster.h>

void setup()
{
Serial.begin(9600);
Serial.println("Hello!");
i2c_init(); //Initialise the i2c bus
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}

void loop()
{
int dev = 0x5A<<1;
unsigned int data_low = 0;
unsigned int data_high = 0;
int pec = 0;

unsigned short data_temp = 0x0000;
double emissivity = 0x0000;

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24); //Register Address
i2c_write(0x0000); //Erase (write 0)
i2c_write(0x5999); //Write Data
i2c_stop();

Serial.println("Write Done.");
delay(100);

i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x24);

i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();

Serial.print("Data Low: ");
Serial.println(data_low);

Serial.print("Data High: ");
Serial.println(data_high);

Serial.print("Data: ");
data_temp = (((data_high) << smiley-cool + data_low);
Serial.println(data_temp);

Serial.print("Emissivity Coefficient: ");
emissivity = (data_temp/65535);
Serial.println(emissivity);

Serial.println("");
delay(5000);
}



Do I need to make seperate writes to the MSB and LSB? As of now I am not even able to erase the cell.

Thanks!
3  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: October 26, 2010, 08:43:04 pm
Any suggestions?
4  Forum 2005-2010 (read only) / Interfacing / Re: Melexis SMBus IR Thermometer - NFI on: October 24, 2010, 09:54:05 pm
Hello,

I have purchased one of these sensors and with the help of this thread I was able to get it up and running rather quickly. Per the data sheet, changing the read address from 0x007 to 0x006 will give you the temperature of the internal device (Ta). This works great.

I'm using this sensor to measure the temperature of a steel surface, which has an emissivity of 0.35. These sensors are set at a default emissivity of 1.0. This is giving me large errors in measuring my surface.

The data sheet lists the EEPROM address for several objects that can be customized, page 11. The 0x004 address corresponds to the emissivity constant. Equal to 65535 * E.

My question is, how do I access the EEPROM on this device? Page 18 of the data sheet lists some Opcode's for certain commands. (what is an “Opcode” anyway?) 000x xxxx = RAM Access and 001x xxx is EEPROM Access.

I'm confused on how to implement the switch to EEPROM access. Could someone help me out on how to modify the code to read and write to the 0x004 address on the EEPROM?

Thanks for your help!
Steven
Pages: [1]