Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 00002 #include "mbed.h" 00003 00004 I2C i2c(p28,p27); //sda,scl 00005 Serial pc(USBTX,USBRX); //serial usb config 00006 00007 char a[5]; 00008 00009 int main() 00010 { 00011 int p1,p2,p3; //to store adc high and low and PEC(packet error correction) 00012 int ch=0,temp_val; //to store temparature value 00013 i2c.frequency(20000); //I2C frequency 20000hz (20khz) 00014 00015 00016 while(1){ 00017 00018 do{ //loop repeat if repeated start codition is not acknowledge 00019 00020 do{ //loop repeat if device ram address(reg address where the Tobj value present) condition is not acknowledge 00021 00022 00023 00024 do{ //loop repeat if device address acdition is not acknowledge 00025 pc.printf("add\t"); 00026 i2c.stop(); //stop i2c if not ack 00027 00028 wait(0.2); 00029 i2c.start(); //start I2C 00030 ch=i2c.write(0x00); //device address of mlxIRtemprature sensorwith write condition 00031 } while(ch==0); //wait for ack 00032 pc.printf("ACK1\t"); 00033 00034 ch=i2c.write(0x07); //device ram address where Tobj value is present 00035 } while(ch==0); //wait for ack 00036 pc.printf("ACK2\t"); 00037 00038 00039 00040 i2c.start(); //repeat start 00041 ch=i2c.write(0x01); //device address with read condition 00042 }while(ch==0); //wait for ack 00043 pc.printf("ACK3\t"); 00044 p1=i2c.read(1); //Tobj low byte 00045 p2=i2c.read(1); //Tobj heigh byte 00046 p3=i2c.read(0); //PEC 00047 i2c.stop(); //stop condition 00048 00049 //degree centigrate conversion 00050 temp_val=((((p2&0x007f)<<8)+p1)*0.02)-0.01; 00051 temp_val=temp_val-273; 00052 00053 00054 00055 wait(1.0); 00056 00057 00058 pc.printf("rx val1 is %d\n",p1); 00059 pc.printf("rx val2 is %d\n",p2); 00060 pc.printf("rx val3 is %d\n",p3); 00061 pc.printf("temp val is %d\n",temp_val); 00062 00063 00064 wait(2.0); 00065 00066 00067 00068 } 00069 00070 00071 00072 return 0; 00073 }
Generated on Tue Jul 19 2022 07:12:45 by
1.7.2