Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MSPPS_H__
00013 #define __MSPPS_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #pragma systemFile
00036
00037 #ifndef __COMMON_H__
00038 #include "common.h"
00039 #endif
00040
00041 #define MSPPS_I2C_ADDR 0x18
00042
00043 #define MSPPS_CMD 0x41
00044
00045 #define MSPPS_UNIT 0x42
00046 #define MSPPS_PRESS_ABS 0x43
00047 #define MSPPS_PRESS_GAUGE 0x45
00048 #define MSPPS_PRESS_REF 0x47
00049
00050 #define MSPPS_UNIT_PSI 0x50
00051 #define MSPPS_UNIT_MB 0x62
00052 #define MSPPS_UNIT_KPA 0x6B
00053
00054 #define MSPSS_CMD_SETREF 0x44
00055
00056
00057 bool MSPPSsendCmd(tSensors link, ubyte command);
00058 bool MSPPSsetUnit(tSensors link, ubyte unit);
00059 long MSPPSreadPressure(tSensors link, ubyte reg);
00060 long MSPPSreadAbsPressure(tSensors link);
00061 long MSPPSreadGaugePressure(tSensors link);
00062 long MSPPSreadRefPressure(tSensors link);
00063 bool MSPPSsetRefPressure(tSensors link);
00064 bool MSPPSsetRefPressure(tSensors link, int refpressure);
00065
00066
00067 #define MSPPSsetUnitPSI(X) MSPPSsetUnit(X, MSPPS_UNIT_PSI)
00068 #define MSPPSsetUnitmB(X) MSPPSsetUnit(X, MSPPS_UNIT_MB)
00069 #define MSPPSsetUnitkPa(X) MSPPSsetUnit(X, MSPPS_UNIT_KPA)
00070
00071 tByteArray MSPPS_I2CRequest;
00072 tByteArray MSPPS_I2CReply;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 long MSPPSreadPressure(tSensors link, ubyte reg)
00085 {
00086 memset(MSPPS_I2CRequest, 0, sizeof(tByteArray));
00087
00088 MSPPS_I2CRequest[0] = 2;
00089 MSPPS_I2CRequest[1] = MSPPS_I2C_ADDR;
00090 MSPPS_I2CRequest[2] = reg;
00091
00092 if (!writeI2C(link, MSPPS_I2CRequest, MSPPS_I2CReply, 2))
00093 return 0;
00094
00095 return ((long)MSPPS_I2CReply[1] * 256) + MSPPS_I2CReply[0];
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105 long MSPPSreadAbsPressure(tSensors link)
00106 {
00107 return MSPPSreadPressure(link, MSPPS_PRESS_ABS);
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 long MSPPSreadGaugePressure(tSensors link)
00119 {
00120 return MSPPSreadPressure(link, MSPPS_PRESS_GAUGE);
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130 long MSPPSreadRefPressure(tSensors link)
00131 {
00132 return MSPPSreadPressure(link, MSPPS_PRESS_REF);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142 bool MSPPSsetRefPressure(tSensors link, int refpressure)
00143 {
00144 memset(MSPPS_I2CRequest, 0, sizeof(tByteArray));
00145
00146 MSPPS_I2CRequest[0] = 4;
00147 MSPPS_I2CRequest[1] = MSPPS_I2C_ADDR;
00148 MSPPS_I2CRequest[2] = MSPPS_PRESS_REF;
00149 MSPPS_I2CRequest[3] = refpressure & 0xFF;
00150 MSPPS_I2CRequest[4] = (refpressure << 8) & 0xFF;
00151
00152 return writeI2C(link, MSPPS_I2CRequest);
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 bool MSPPSsetRefPressure(tSensors link)
00162 {
00163 return MSPPSsendCmd(link, MSPSS_CMD_SETREF);
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173 bool MSPPSsendCmd(tSensors link, ubyte command) {
00174 memset(MSPPS_I2CRequest, 0, sizeof(tByteArray));
00175
00176 MSPPS_I2CRequest[0] = 3;
00177 MSPPS_I2CRequest[1] = MSPPS_I2C_ADDR;
00178 MSPPS_I2CRequest[2] = MSPPS_CMD;
00179 MSPPS_I2CRequest[3] = command;
00180
00181 return writeI2C(link, MSPPS_I2CRequest);
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191 bool MSPPSsetUnit(tSensors link, ubyte unit) {
00192 memset(MSPPS_I2CRequest, 0, sizeof(tByteArray));
00193
00194 MSPPS_I2CRequest[0] = 3;
00195 MSPPS_I2CRequest[1] = MSPPS_I2C_ADDR;
00196 MSPPS_I2CRequest[2] = MSPPS_UNIT;
00197 MSPPS_I2CRequest[3] = unit;
00198
00199 return writeI2C(link, MSPPS_I2CRequest);
00200 }
00201
00202 #endif //__MSPPS_H__
00203
00204
00205
00206
00207
00208