Jump to content
43oh

Reading / writing on I2C protocol


Recommended Posts

Hello,

 

I am trying to Interface my temperature sensor MLX90620(16*4 IR array) with TIVA 

 

microcontroller(tm4c123gxl).The Serial communication used here is i2c(just the wire library) and the 

 

platform used is Energia.The first part of the process is to obtain the EEPROM values,which has been 

 

completed successfully.

 

Now I have to write the oscillator trimming value,obtained from a particular location in 

 

EEPROM(0xF7),into the register(0x93).This is the place where Iam stuck.

 

I have written the oscillator trimming value according to the protocol,but when I read the location to 

 

check whether I am on the right track, I am receiving -1.

 

I had read in a forum that -1 is predefined value which signifies buffer empty, which means I am not 

 

receiving anything and I am not able to figure out where I am going wrong. Is it the read or the write 

 

section. 

 

Please help. Thank you in advance.

 

I am attaching the datasheet of the sensor.

 

Code:

/* MLX90620 interfaced with tiva microcontroller TM4C123 with I2C */

 

 

#include <Wire.h>

TwoWire Wire1(0);

byte button ;

int8_t data_EEPROM;

int8_t d;

int8_t y;

int8_t data_osc;

int state;

int location = 0;

int8_t val_2,val_3;

 

void setup()

{

Wire1.begin();

Serial.begin(9600);

main_2();

}

 

/* reading calibration data from EEPROM */

/* receiver buffer is of 32 bytes therefore transmitting the read command for 8 times */

 

void main_2()

{

Serial.println("Start");

 

Wire1.beginTransmission(80); // slave address EEPROM(0x50)

state = Wire1.endTransmission(); // read the acknowledgement

state = 5; // modify the state value

for(i=0;i<256;)

{

Wire1.write(location);

state = Wire1.endTransmission();

 

Wire1.requestFrom(80, 32);//(uint8_t)32); // requesting the 32 bytes from EEPROM

state = Wire1.endTransmission();

 

while(!Wire1.available()){}; // waiting period till slave device send some data

 

while(Wire1.available()) // reading the data available on SDA pin

{

data_EEPROM = Wire1.read();

if(location==247)

{ // reading oscillator trimming value from location 0xF7(247 in dec)

data_osc = data_EEPROM;

Serial.print("location value is ");

Serial.print(location);

Serial.print(":");

Serial.println(data_osc); // Oscillator trimming value is 87

}

 

location++;

 

state = Wire1.endTransmission(true); // sending the stop condition after every 32bytes read

 

}

 

readoscillator_trimming(z);

 

while(1);

 

}

 

 

void readoscillator_trimming(int8_t val)

{

val_2 = val - 170;

 

 

Wire1.beginTransmission(96); // slave address of ram(0x60)

y = Wire1.endTransmission();

 

 

Wire1.write(4); // command to write osc trimming value

y = Wire1.endTransmission();

 

Wire1.write(val_2); // LSB check byte (refer datasheet)

y = Wire1.endTransmission();

 

 

Wire1.write(val); // LSB byte

y = Wire1.endTransmission();

 

val_3 = 0 - 170;

 

Wire1.write(val_3); // MSB check byte

y = Wire1.endTransmission();

 

 

Wire1.write(0); // MSB data

y = Wire1.endTransmission(true); // stop bit

Serial.println(y);

 

//Reading the oscillator trimming value register

 

Wire1.beginTransmission(96); // slave address

y = Wire1.endTransmission();

 

Wire1.write(2); // command for reading RAM data

y = Wire1.endTransmission();

 

Wire1.write(147); // address of OSC trimming register

y = Wire1.endTransmission();

 

Wire1.write(0); // address step

y = Wire1.endTransmission();

 

Wire1.write(1); // no. of bytes to be read

y = Wire1.endTransmission();

 

Wire1.requestFrom(96,2); // requesting 2 bytes (LSB and MSB)

y = Wire1.endTransmission();

 

while(!Wire1.available()){}; // additional delay for slave to respond

 

while(Wire1.available()) // reading the data

{

 

d = Wire1.read(); //reading the data

while(d == -1)

{

d = Wire1.read();

}

 

Serial.println(d);

 

}

 

y = Wire1.endTransmission(true);

Serial.println(y);

}

 

 

void loop()

{

// put your main code here, to run repeatedly:

 

}pdf.gif Datasheet_90620.pdf   1.67MB  0 downloadspdf.gif Datasheet_90620.pdf   1.67MB  0 downloadspdf.gif Datasheet_90620.pdf   1.67MB  0 downloads

 

View the full article on Stellarisiti. 43oh pulls Stellarisiti Energia posts, so that members do not miss out questions. Please bear with this arrangement for now. Thanks!

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...