![background image](http://html1.mh-extra.com/html/omron/d6t-series/d6t-series_user-manual_740813015.webp)
D6T MEMS Thermal Sensors User’s Manual (A284)
14
6.4 Example Temperature Value Retrieval Program
(16-channel D6T-44L-06 / 1024ch D6T-32L-01A)
// I2C communication functions
extern void I2C_start();
extern void I2C_repeatstart();
extern void I2C_stop();
extern void I2C_send1( char addr8 , char cmd );
extern void I2C_getx( char addr8 , char buff[] , int length );
extern int D6T_checkPEC( char buf , int pPEC );
// Global var.
extern char readbuff[35];
extern int tPTAT;
extern int tP[16];
extern int tPEC;
int D6T_getvalue()
{
I2C_start();
I2C_send1( 0x14 , 0x4C ); // 14h = { 0Ah(Addr7) : Write(0b) }
I2C_repeatstart();
I2C_getx( 0x15 , readbuff , 35 ); // 15h = { 0Ah(Addr7):Read },35 = 2*(1+16)+1
I2C_stop();
If( !D6T_checkPEC(readbuff,34)){
return -1; // error
}
tPTAT = 256*readbuff[1] + readbuff[0];
tP[0] = 256*readbuff[3] + readbuff[2];
tP[1] = 256*readbuff[5] + readbuff[4];
tP[2] = 256*readbuff[7] + readbuff[6];
tP[3] = 256*readbuff[9] + readbuff[8];
tP[4] = 256*readbuff[11] + readbuff[10];
tP[5] = 256*readbuff[13] + readbuff[12];
tP[6] = 256*readbuff[15] + readbuff[14];
tP[7] = 256*readbuff[17] + readbuff[16];
tP[8] = 256*readbuff[19] + readbuff[18];
tP[9] = 256*readbuff[21] + readbuff[20];
tP[10] = 256*readbuff[23] + readbuff[22];
tP[11] = 256*readbuff[25] + readbuff[24];
tP[12] = 256*readbuff[27] + readbuff[26];
tP[13] = 256*readbuff[29] + readbuff[28];
tP[14] = 256*readbuff[31] + readbuff[30];
tP[15] = 256*readbuff[33] + readbuff[32];
tPEC = readbuff[34];
return 1;
}
measure()
{
n = 0;
do{
status = D6T_getvalue();
n++;
}while(status < 0 && n < LOOPLIMIT);
If(status < 0){
// error operation.
}
printf(“%d, %d,%d,%d,%d,%d,%d,%d,%d ,%d,%d,%d,%d,%d,%d,%d,%d ,%d\n”,
tPTAT,tP[0],tP[1],tP[2],tP[3],tP[4],tP[5],tP[6],tP[7]
,tP[8],tP[9],tP[10],tP[11],tP[12],tP[13],tP[14],tP[15],tPEC);
}
* For the D6T-32L-01A, add tP[xx] up to 1023.
* This example program is configured only with functions from the standard I2C operations library.
Replace library functions with similar ones available in the microcontroller used in your system
when testing this program.