UAVX Multicopter Flight Controller.

Dependencies:   mbed

Committer:
gke
Date:
Tue Apr 26 12:12:29 2011 +0000
Revision:
2:90292f8bd179
Parent:
0:62a1c91a859a
Not flightworthy. Posted for others to make use of the I2C SW code.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gke 0:62a1c91a859a 1 // ===============================================================================================
gke 0:62a1c91a859a 2 // = UAVXArm Quadrocopter Controller =
gke 0:62a1c91a859a 3 // = Copyright (c) 2008 by Prof. Greg Egan =
gke 0:62a1c91a859a 4 // = Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer =
gke 2:90292f8bd179 5 // = http://code.google.com/p/uavp-mods/ =
gke 0:62a1c91a859a 6 // ===============================================================================================
gke 0:62a1c91a859a 7
gke 0:62a1c91a859a 8 // This is part of UAVXArm.
gke 0:62a1c91a859a 9
gke 0:62a1c91a859a 10 // UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU
gke 0:62a1c91a859a 11 // General Public License as published by the Free Software Foundation, either version 3 of the
gke 0:62a1c91a859a 12 // License, or (at your option) any later version.
gke 0:62a1c91a859a 13
gke 0:62a1c91a859a 14 // UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without
gke 0:62a1c91a859a 15 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gke 0:62a1c91a859a 16 // See the GNU General Public License for more details.
gke 0:62a1c91a859a 17
gke 0:62a1c91a859a 18 // You should have received a copy of the GNU General Public License along with this program.
gke 0:62a1c91a859a 19 // If not, see http://www.gnu.org/licenses/
gke 0:62a1c91a859a 20
gke 0:62a1c91a859a 21 #include "UAVXArm.h"
gke 0:62a1c91a859a 22 void GetTemperature(void);
gke 0:62a1c91a859a 23 void InitTemperature(void);
gke 0:62a1c91a859a 24
gke 0:62a1c91a859a 25 i16u AmbientTemperature;
gke 0:62a1c91a859a 26
gke 0:62a1c91a859a 27 void GetTemperature(void) {
gke 0:62a1c91a859a 28
gke 0:62a1c91a859a 29 I2CTEMP.start();
gke 2:90292f8bd179 30 if ( I2CTEMP.write(TMP100_RD) != I2C_ACK ) goto TMP100Error;
gke 0:62a1c91a859a 31 AmbientTemperature.b1 = I2CTEMP.read(I2C_ACK);
gke 0:62a1c91a859a 32 AmbientTemperature.b0 = I2CTEMP.read(I2C_NACK);
gke 0:62a1c91a859a 33 I2CTEMP.stop();
gke 0:62a1c91a859a 34
gke 0:62a1c91a859a 35 // Top 9 bits 0.5C res. scale to 0.1C
gke 0:62a1c91a859a 36 AmbientTemperature.i16 = SRS16( AmbientTemperature.i16, 7) * 5;
gke 0:62a1c91a859a 37 if ( AmbientTemperature.i16 > Stats[MaxTempS])
gke 0:62a1c91a859a 38 Stats[MaxTempS] = AmbientTemperature.i16;
gke 0:62a1c91a859a 39 else
gke 0:62a1c91a859a 40 if ( AmbientTemperature.i16 < Stats[MinTempS] )
gke 0:62a1c91a859a 41 Stats[MinTempS] = AmbientTemperature.i16;
gke 0:62a1c91a859a 42 return;
gke 0:62a1c91a859a 43
gke 2:90292f8bd179 44 TMP100Error:
gke 0:62a1c91a859a 45 I2CTEMP.stop();
gke 2:90292f8bd179 46
gke 2:90292f8bd179 47 I2CError[TMP100_ID]++;
gke 0:62a1c91a859a 48 AmbientTemperature.i16 = 0;
gke 0:62a1c91a859a 49
gke 0:62a1c91a859a 50 return;
gke 0:62a1c91a859a 51 } // GetTemperature
gke 0:62a1c91a859a 52
gke 0:62a1c91a859a 53 void InitTemperature(void) {
gke 0:62a1c91a859a 54 I2CTEMP.start();
gke 0:62a1c91a859a 55 if( I2CTEMP.write(TMP100_WR) != I2C_ACK ) goto Terror;
gke 0:62a1c91a859a 56 if( I2CTEMP.write(TMP100_CMD) != I2C_ACK ) goto Terror;
gke 0:62a1c91a859a 57 if( I2CTEMP.write(TMP100_CFG) != I2C_ACK ) goto Terror;
gke 0:62a1c91a859a 58 I2CTEMP.stop();
gke 0:62a1c91a859a 59
gke 0:62a1c91a859a 60 I2CTEMP.start();
gke 0:62a1c91a859a 61 if( I2CTEMP.write(TMP100_WR) != I2C_ACK ) goto Terror;
gke 0:62a1c91a859a 62 if( I2CTEMP.write(TMP100_TMP) != I2C_ACK ) goto Terror; // Select temperature
gke 0:62a1c91a859a 63 I2CTEMP.stop();
gke 0:62a1c91a859a 64
gke 0:62a1c91a859a 65 GetTemperature();
gke 0:62a1c91a859a 66
gke 0:62a1c91a859a 67 return;
gke 0:62a1c91a859a 68
gke 0:62a1c91a859a 69 Terror:
gke 0:62a1c91a859a 70 I2CTEMP.stop();
gke 0:62a1c91a859a 71 AmbientTemperature.i16 = 0;
gke 0:62a1c91a859a 72
gke 0:62a1c91a859a 73 } // InitTemperature