Hello folks,
I would like to dump EEPROM data over I2C from MLX90614 using the I2CMaster library.
I need to change Config Register1 with faster FIR and IIR filter settings. Before I do that I need to be confident that I have saved old data, and that I am accessing correct data.
There are a few posts on this forum which describe something like my problem. If I don't understand the answer, then excuse me. I am having a fever right now, and I might not be thinking strait.
The truncated code below (full code too long to be posted on forum)
// Read and Write to Melexis MLX90614 over SMBus
// http://www.MKRD.info/
// 8April2015
// Revision 8
#include <i2cmaster.h> //For Melexis SMBus communication
////////////////////////////////Thermal Infrared sensor variables and constants/////////
int thermal_dev = 0x5A << 1; //Default MLX90614 address in Hex, shifted left by one bit due to I2C protocol
int Emissivity_correction_coefficient_low = 0; //Initializing low byte of Emissivity_correction_coefficient data
int Emissivity_correction_coefficient_high = 0; //Initializing high byte of Emissivity_correction_coefficient data
int Emissivity_correction_coefficient = 0;
Config_Register1 decimal: 834
Config_Register1 hex: 342
Config_Register1 binary: 1101000010
int thermal_pec = 0; //Initializing PEC. TODO check that this is calculated properly, or at least ignored properly
////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
////////////////////Initialize I2C ////////////////////
i2c_init(); //Initialise the I2C bus
PORTC = (1 << PORTC4) | (1 << PORTC5); //enable pullups, but this is not necessary as I am using external resistors
////////////////////////////////////////////////////////
Serial.begin(9600);
//////////////// Read Melexis EEPROM Emissivity_correction_coefficient over SMBUS to obtain default values ////////////////
/*
Tomax 0x00
Tomin 0x01
PWMCTRL 0x02
Ta range 0x03
Emissivity correction coefficient 0x04
Config Register1 0x05
SMBus address (LSByte only) 0x0E
ID number 0x1C
ID number 0x1D
ID number 0x1E
ID number 0x1F
*/
i2c_start_wait(thermal_dev + I2C_WRITE);
i2c_write(0b00100000 | 0x04); //0b00100000 for EEPROM ACCESS
// read
i2c_rep_start(thermal_dev + I2C_READ);
Emissivity_correction_coefficient_low = i2c_readAck(); //Read 1 byte and then send ack
Emissivity_correction_coefficient_high = i2c_readAck(); //Read 1 byte and then send ack
thermal_pec = i2c_readNak();
i2c_stop();
//This converts high and low bytes together - moves it left 8 bits and adds the low byte.
Emissivity_correction_coefficient = ((Emissivity_correction_coefficient_high << 8) | Emissivity_correction_coefficient_low);
Serial.println();
Serial.print("Emissivity_correction_coefficient decimal: ");
Serial.print(Emissivity_correction_coefficient, DEC);
Serial.println();
Serial.print("Emissivity_correction_coefficient hex: ");
Serial.print(Emissivity_correction_coefficient, HEX);
Serial.println();
Serial.print("Emissivity_correction_coefficient binary: ");
Serial.print(Emissivity_correction_coefficient, BIN);
Serial.println();
// printf("Printf: %x", Emissivity_correction_coefficient);
/////////////////END of Read Melexis EEPROM over SMBUS to obtain default values/////////////////////////////////////////////
//////////////// Read Melexis EEPROM Config_Register1 over SMBUS to obtain default values ////////////////
/*
Tomax 0x00
Tomin 0x01
PWMCTRL 0x02
Ta range 0x03
Emissivity correction coefficient 0x04
Config Register1 0x05
SMBus address (LSByte only) 0x0E
ID number 0x1C
ID number 0x1D
ID number 0x1E
ID number 0x1F
*/
i2c_start_wait(thermal_dev + I2C_WRITE);
i2c_write(0b00100000 | 0x05); //0b00100000 for EEPROM ACCESS
// read
i2c_rep_start(thermal_dev + I2C_READ);
Config_Register1_low = i2c_readAck(); //Read 1 byte and then send ack
Config_Register1_high = i2c_readAck(); //Read 1 byte and then send ack
thermal_pec = i2c_readNak();
i2c_stop();
//This converts high and low bytes together - moves it left 8 bits and adds the low byte.
Config_Register1 = (Config_Register1_high << 8) | Config_Register1_low;
Serial.println();
Serial.print("Config_Register1 decimal: ");
Serial.print(Config_Register1, DEC);
Serial.println();
Serial.print("Config_Register1 hex: ");
Serial.print(Config_Register1, HEX);
Serial.println();
Serial.print("Config_Register1 binary: ");
Serial.print(Config_Register1, BIN);
Serial.println();
/////////////////END of Read Melexis EEPROM over SMBUS to obtain default values/////////////////////////////////////////////
}
void loop() //MAIN LOOP
{
}//LOOPING
Produces this output:
Tomax decimal: -26221
Tomax hex: FFFF9993
Tomax binary: 11111111111111111001100110010011
Tomin decimal: 25315
Tomin hex: 62E3
Tomin binary: 110001011100011
PWMCTRL decimal: 513
PWMCTRL hex: 201
PWMCTRL binary: 1000000001
Ta_range decimal: -2276
Ta_range hex: FFFFF71C
Ta_range binary: 11111111111111111111011100011100
Emissivity_correction_coefficient decimal: -1
Emissivity_correction_coefficient hex: FFFFFFFF
Emissivity_correction_coefficient binary: 11111111111111111111111111111111
Config_Register1 decimal: -24652
Config_Register1 hex: FFFF9FB4
Config_Register1 binary: 11111111111111111001111110110100
SMBus_address_LSByte_only decimal: -16806
SMBus_address_LSByte_only hex: FFFFBE5A
SMBus_address_LSByte_only binary: 11111111111111111011111001011010
ID_number_C decimal: 12
ID_number_C hex: C
ID_number_C binary: 1100
ID_number_D decimal: 19171
ID_number_D hex: 4AE3
ID_number_D binary: 100101011100011
ID_number_E decimal: 29064
ID_number_E hex: 7188
ID_number_E binary: 111000110001000
ID_number_F decimal: -20280
ID_number_F hex: FFFFB0C8
ID_number_F binary: 11111111111111111011000011001000
What I don't understand is how can I have a 32-bit long output from Serial.print() if I am reading two bytes, and combining them into an integer???
For reference, I am expecting Emissivity_correction_coefficient hex: to be FFFF
Some other posts which talk about a similar issue:
http://forum.arduino.cc/index.php?topic=55524.0
http://forum.arduino.cc/index.php?topic=138271.0
http://forum.arduino.cc/index.php?topic=162324.0
http://forum.arduino.cc/index.php?topic=297725.15
I would like to understand what's going on, instead of copy-pasting someone else's code.