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) <<
+ 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!