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.
temperature.c
00001 // =============================================================================================== 00002 // = UAVXArm Quadrocopter Controller = 00003 // = Copyright (c) 2008 by Prof. Greg Egan = 00004 // = Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer = 00005 // = http://code.google.com/p/uavp-mods/ = 00006 // =============================================================================================== 00007 00008 // This is part of UAVXArm. 00009 00010 // UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU 00011 // General Public License as published by the Free Software Foundation, either version 3 of the 00012 // License, or (at your option) any later version. 00013 00014 // UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without 00015 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 // See the GNU General Public License for more details. 00017 00018 // You should have received a copy of the GNU General Public License along with this program. 00019 // If not, see http://www.gnu.org/licenses/ 00020 00021 #include "UAVXArm.h" 00022 void GetTemperature(void); 00023 void InitTemperature(void); 00024 00025 i16u AmbientTemperature; 00026 00027 void GetTemperature(void) { 00028 00029 I2CTEMP.start(); 00030 if ( I2CTEMP.write(TMP100_RD) != I2C_ACK ) goto TMP100Error; 00031 AmbientTemperature.b1 = I2CTEMP.read(I2C_ACK); 00032 AmbientTemperature.b0 = I2CTEMP.read(I2C_NACK); 00033 I2CTEMP.stop(); 00034 00035 // Top 9 bits 0.5C res. scale to 0.1C 00036 AmbientTemperature.i16 = SRS16( AmbientTemperature.i16, 7) * 5; 00037 if ( AmbientTemperature.i16 > Stats[MaxTempS]) 00038 Stats[MaxTempS] = AmbientTemperature.i16; 00039 else 00040 if ( AmbientTemperature.i16 < Stats[MinTempS] ) 00041 Stats[MinTempS] = AmbientTemperature.i16; 00042 return; 00043 00044 TMP100Error: 00045 I2CTEMP.stop(); 00046 00047 I2CError[TMP100_ID]++; 00048 AmbientTemperature.i16 = 0; 00049 00050 return; 00051 } // GetTemperature 00052 00053 void InitTemperature(void) { 00054 I2CTEMP.start(); 00055 if( I2CTEMP.write(TMP100_WR) != I2C_ACK ) goto Terror; 00056 if( I2CTEMP.write(TMP100_CMD) != I2C_ACK ) goto Terror; 00057 if( I2CTEMP.write(TMP100_CFG) != I2C_ACK ) goto Terror; 00058 I2CTEMP.stop(); 00059 00060 I2CTEMP.start(); 00061 if( I2CTEMP.write(TMP100_WR) != I2C_ACK ) goto Terror; 00062 if( I2CTEMP.write(TMP100_TMP) != I2C_ACK ) goto Terror; // Select temperature 00063 I2CTEMP.stop(); 00064 00065 GetTemperature(); 00066 00067 return; 00068 00069 Terror: 00070 I2CTEMP.stop(); 00071 AmbientTemperature.i16 = 0; 00072 00073 } // InitTemperature
Generated on Wed Jul 13 2022 01:50:20 by
1.7.2