CPC314
C P C 3 1 4 U s e r M a n u a l
53
© 2 0 2 1 F a s t w e l V e r . 0 0 1
Example of working with the TMP75 digital temperature sensor (Texas Instruments)
Address of the TMP75 chip is set on the I2C bus
#define TMP75_WR_ADDR
0x90
First, the bus is configured
I2C_SetBase( I2C_DEF_BASE_ADDR );
I2C_Init( I2C_CHANNEL0 );
Next, the
chip’s identifier is read
timeout = I2C_ReadWordReg( I2C_CHANNEL0, TMP75_WR_ADDR, 0x07, &id, DEF_TIMEOUT );
If the identifier is correct, the temperature will be read
timeout = I2C_ReadWordReg( I2C_CHANNEL0, TMP75_WR_ADDR, 0x00, &rd_temp, DEF_TIMEOUT
);
Converted to the usual form and routed to the console
temp = 1;
rd_temp = rd_temp >> 3;
if( rd_temp & 0x2000 ) {
temp = -1; rd_temp = 0x2000 - rd_temp;
}
temp = temp * rd_temp * 0.0625;
printf( " Temperature=%.4f\r\n", temp );