ADS1220 Library Modified from Sandeep Malladi

Dependents:   ADS1220SPI BMI160Test Seismograph-Geodynamic

Committer:
firewalk
Date:
Thu Oct 13 02:07:10 2016 +0000
Revision:
1:34692a3d25f7
Parent:
0:90cd7e5e24af
Modified by Celso Varella

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sandeepmalladi 0:90cd7e5e24af 1 #include "mbed.h"
sandeepmalladi 0:90cd7e5e24af 2 #include "ADS1220.h"
sandeepmalladi 0:90cd7e5e24af 3 #include <inttypes.h>
sandeepmalladi 0:90cd7e5e24af 4
sandeepmalladi 0:90cd7e5e24af 5 ADS1220::ADS1220(PinName mosi, PinName miso, PinName sclk):
sandeepmalladi 0:90cd7e5e24af 6 _device(mosi, miso, sclk)
sandeepmalladi 0:90cd7e5e24af 7 {
sandeepmalladi 0:90cd7e5e24af 8 _device.frequency(4000000);
sandeepmalladi 0:90cd7e5e24af 9 _device.format(8,1);
sandeepmalladi 0:90cd7e5e24af 10 }
sandeepmalladi 0:90cd7e5e24af 11
sandeepmalladi 0:90cd7e5e24af 12
sandeepmalladi 0:90cd7e5e24af 13 // ADS1220 Initial Configuration
sandeepmalladi 0:90cd7e5e24af 14 void ADS1220::Config(void)
sandeepmalladi 0:90cd7e5e24af 15 {
sandeepmalladi 0:90cd7e5e24af 16 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 17 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 18
sandeepmalladi 0:90cd7e5e24af 19 // clear prev value;
sandeepmalladi 0:90cd7e5e24af 20 Temp &= 0x00;
firewalk 1:34692a3d25f7 21 Temp |= (ADS1220_MUX_1_G | ADS1220_GAIN_1 | ADS1220_PGA_BYPASS);//MUX_AIN1, ADS1220_GAIN_1, PGA-BYPASS ON);
sandeepmalladi 0:90cd7e5e24af 22
sandeepmalladi 0:90cd7e5e24af 23 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 24 WriteRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 25
sandeepmalladi 0:90cd7e5e24af 26 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 27 // clear prev DataRate code;
sandeepmalladi 0:90cd7e5e24af 28 Temp &= 0x00;
firewalk 1:34692a3d25f7 29 Temp |= (ADS1220_DR_1000 | ADS1220_MODE_TURBO); // Set turbo start mode to 1000sps(2000 sps) and single shot conversions
sandeepmalladi 0:90cd7e5e24af 30
sandeepmalladi 0:90cd7e5e24af 31 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 32 WriteRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 33
sandeepmalladi 0:90cd7e5e24af 34 // ADS1220WriteRegister(ADS1220_2_REGISTER, 0x01, 0x00000000);
sandeepmalladi 0:90cd7e5e24af 35 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 36
sandeepmalladi 0:90cd7e5e24af 37 // clear prev DataRate code;
sandeepmalladi 0:90cd7e5e24af 38 Temp &= 0x00;
firewalk 1:34692a3d25f7 39 Temp |= (ADS1220_VREF_SUPPLY | ADS1220_REJECT_OFF); // Set External Reference 5.00 V (AVDD - AVSS)
sandeepmalladi 0:90cd7e5e24af 40
sandeepmalladi 0:90cd7e5e24af 41 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 42 WriteRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 43 }
sandeepmalladi 0:90cd7e5e24af 44
sandeepmalladi 0:90cd7e5e24af 45
sandeepmalladi 0:90cd7e5e24af 46 void ADS1220::SendByte(unsigned char Value)
sandeepmalladi 0:90cd7e5e24af 47 {
sandeepmalladi 0:90cd7e5e24af 48
sandeepmalladi 0:90cd7e5e24af 49 _device.write(Value);
sandeepmalladi 0:90cd7e5e24af 50 }
sandeepmalladi 0:90cd7e5e24af 51
sandeepmalladi 0:90cd7e5e24af 52
sandeepmalladi 0:90cd7e5e24af 53 unsigned int ADS1220::ReceiveByte(void)
sandeepmalladi 0:90cd7e5e24af 54 {
sandeepmalladi 0:90cd7e5e24af 55 unsigned int readvalue;
sandeepmalladi 0:90cd7e5e24af 56 readvalue = _device.write(0x00);
sandeepmalladi 0:90cd7e5e24af 57
sandeepmalladi 0:90cd7e5e24af 58 return readvalue;
sandeepmalladi 0:90cd7e5e24af 59 }
sandeepmalladi 0:90cd7e5e24af 60
sandeepmalladi 0:90cd7e5e24af 61 /*
sandeepmalladi 0:90cd7e5e24af 62 ******************************************************************************
sandeepmalladi 0:90cd7e5e24af 63 higher level functions
sandeepmalladi 0:90cd7e5e24af 64 */
sandeepmalladi 0:90cd7e5e24af 65 unsigned int ADS1220::ReadData(void)
sandeepmalladi 0:90cd7e5e24af 66 {
sandeepmalladi 0:90cd7e5e24af 67 uint32_t Data;
sandeepmalladi 0:90cd7e5e24af 68
sandeepmalladi 0:90cd7e5e24af 69
sandeepmalladi 0:90cd7e5e24af 70 // assert CS to start transfer
sandeepmalladi 0:90cd7e5e24af 71 // ADS1220AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 72
sandeepmalladi 0:90cd7e5e24af 73 // send the command byte
sandeepmalladi 0:90cd7e5e24af 74 SendByte(ADS1220_CMD_RDATA);
sandeepmalladi 0:90cd7e5e24af 75
sandeepmalladi 0:90cd7e5e24af 76 // get the conversion result
sandeepmalladi 0:90cd7e5e24af 77 #ifdef ADS1120
sandeepmalladi 0:90cd7e5e24af 78 Data = ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 79 Data = (Data << 8) | ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 80 //Data = (Data << 8) | ADS1220ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 81
sandeepmalladi 0:90cd7e5e24af 82 // sign extend data
sandeepmalladi 0:90cd7e5e24af 83 if (Data & 0x8000)
sandeepmalladi 0:90cd7e5e24af 84 Data |= 0xffff0000;
sandeepmalladi 0:90cd7e5e24af 85 #else
sandeepmalladi 0:90cd7e5e24af 86 Data = ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 87 Data = (Data << 8) |ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 88 Data = (Data << 8) |ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 89
sandeepmalladi 0:90cd7e5e24af 90 // sign extend data
sandeepmalladi 0:90cd7e5e24af 91 if (Data & 0x800000)
sandeepmalladi 0:90cd7e5e24af 92 Data |= 0xff000000;
sandeepmalladi 0:90cd7e5e24af 93
sandeepmalladi 0:90cd7e5e24af 94 #endif
sandeepmalladi 0:90cd7e5e24af 95 // de-assert CS
sandeepmalladi 0:90cd7e5e24af 96 //ADS1220AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 97 return Data;
sandeepmalladi 0:90cd7e5e24af 98 }
sandeepmalladi 0:90cd7e5e24af 99
sandeepmalladi 0:90cd7e5e24af 100 void ADS1220::ReadRegister(int StartAddress, int NumRegs, unsigned * pData)
sandeepmalladi 0:90cd7e5e24af 101 {
sandeepmalladi 0:90cd7e5e24af 102 int i;
sandeepmalladi 0:90cd7e5e24af 103
sandeepmalladi 0:90cd7e5e24af 104 // assert CS to start transfer
sandeepmalladi 0:90cd7e5e24af 105 // ADS1220AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 106
sandeepmalladi 0:90cd7e5e24af 107 // send the command byte
sandeepmalladi 0:90cd7e5e24af 108 SendByte(ADS1220_CMD_RREG | (((StartAddress<<2) & 0x0c) |((NumRegs-1)&0x03)));
sandeepmalladi 0:90cd7e5e24af 109
sandeepmalladi 0:90cd7e5e24af 110 // get the register content
sandeepmalladi 0:90cd7e5e24af 111 for (i=0; i< NumRegs; i++)
sandeepmalladi 0:90cd7e5e24af 112 {
sandeepmalladi 0:90cd7e5e24af 113 *pData++ = ReceiveByte();
sandeepmalladi 0:90cd7e5e24af 114 }
sandeepmalladi 0:90cd7e5e24af 115
sandeepmalladi 0:90cd7e5e24af 116 // de-assert CS
sandeepmalladi 0:90cd7e5e24af 117 // ADS1220AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 118
sandeepmalladi 0:90cd7e5e24af 119 return;
sandeepmalladi 0:90cd7e5e24af 120 }
sandeepmalladi 0:90cd7e5e24af 121
sandeepmalladi 0:90cd7e5e24af 122 void ADS1220::WriteRegister(int StartAddress, int NumRegs, unsigned * pData)
sandeepmalladi 0:90cd7e5e24af 123 {
sandeepmalladi 0:90cd7e5e24af 124 int i;
sandeepmalladi 0:90cd7e5e24af 125
sandeepmalladi 0:90cd7e5e24af 126 // assert CS to start transfer
sandeepmalladi 0:90cd7e5e24af 127 //ADS1220AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 128
sandeepmalladi 0:90cd7e5e24af 129 // send the command byte
sandeepmalladi 0:90cd7e5e24af 130 SendByte(ADS1220_CMD_WREG | (((StartAddress<<2) & 0x0c) |((NumRegs-1)&0x03)));
sandeepmalladi 0:90cd7e5e24af 131
sandeepmalladi 0:90cd7e5e24af 132 // send the data bytes
sandeepmalladi 0:90cd7e5e24af 133 for (i=0; i< NumRegs; i++)
sandeepmalladi 0:90cd7e5e24af 134 {
sandeepmalladi 0:90cd7e5e24af 135 SendByte(*pData++);
sandeepmalladi 0:90cd7e5e24af 136 }
sandeepmalladi 0:90cd7e5e24af 137
sandeepmalladi 0:90cd7e5e24af 138 // de-assert CS
sandeepmalladi 0:90cd7e5e24af 139 //ADS1220AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 140
sandeepmalladi 0:90cd7e5e24af 141 return;
sandeepmalladi 0:90cd7e5e24af 142 }
sandeepmalladi 0:90cd7e5e24af 143
sandeepmalladi 0:90cd7e5e24af 144 void ADS1220::SendResetCommand(void)
sandeepmalladi 0:90cd7e5e24af 145 {
sandeepmalladi 0:90cd7e5e24af 146 // assert CS to start transfer
sandeepmalladi 0:90cd7e5e24af 147 //ADS1220AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 148
sandeepmalladi 0:90cd7e5e24af 149 // send the command byte
sandeepmalladi 0:90cd7e5e24af 150 SendByte(ADS1220_CMD_RESET);
sandeepmalladi 0:90cd7e5e24af 151
sandeepmalladi 0:90cd7e5e24af 152 // de-assert CS
sandeepmalladi 0:90cd7e5e24af 153 //ADS1220AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 154
sandeepmalladi 0:90cd7e5e24af 155 return;
sandeepmalladi 0:90cd7e5e24af 156 }
sandeepmalladi 0:90cd7e5e24af 157
sandeepmalladi 0:90cd7e5e24af 158 void ADS1220::SendStartCommand(void)
sandeepmalladi 0:90cd7e5e24af 159 {
sandeepmalladi 0:90cd7e5e24af 160 // assert CS to start transfer
sandeepmalladi 0:90cd7e5e24af 161 //ADS1220AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 162
sandeepmalladi 0:90cd7e5e24af 163 // send the command byte
sandeepmalladi 0:90cd7e5e24af 164 SendByte(ADS1220_CMD_SYNC);
sandeepmalladi 0:90cd7e5e24af 165
sandeepmalladi 0:90cd7e5e24af 166 // de-assert CS
sandeepmalladi 0:90cd7e5e24af 167 //ADS1220AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 168
sandeepmalladi 0:90cd7e5e24af 169 return;
sandeepmalladi 0:90cd7e5e24af 170 }
sandeepmalladi 0:90cd7e5e24af 171
sandeepmalladi 0:90cd7e5e24af 172 void ADS1220::SendShutdownCommand(void)
sandeepmalladi 0:90cd7e5e24af 173 {
sandeepmalladi 0:90cd7e5e24af 174 // assert CS to start transfer
sandeepmalladi 0:90cd7e5e24af 175 //ADS1220AssertCS(1);
sandeepmalladi 0:90cd7e5e24af 176
sandeepmalladi 0:90cd7e5e24af 177 // send the command byte
sandeepmalladi 0:90cd7e5e24af 178 SendByte(ADS1220_CMD_SHUTDOWN);
sandeepmalladi 0:90cd7e5e24af 179
sandeepmalladi 0:90cd7e5e24af 180 // de-assert CS
sandeepmalladi 0:90cd7e5e24af 181 //ADS1220AssertCS(0);
sandeepmalladi 0:90cd7e5e24af 182
sandeepmalladi 0:90cd7e5e24af 183 return;
sandeepmalladi 0:90cd7e5e24af 184 }
sandeepmalladi 0:90cd7e5e24af 185
sandeepmalladi 0:90cd7e5e24af 186 /*
sandeepmalladi 0:90cd7e5e24af 187 ******************************************************************************
sandeepmalladi 0:90cd7e5e24af 188 register set value commands
sandeepmalladi 0:90cd7e5e24af 189 */
sandeepmalladi 0:90cd7e5e24af 190
sandeepmalladi 0:90cd7e5e24af 191 int ADS1220::SetChannel(int Mux)
sandeepmalladi 0:90cd7e5e24af 192 {
sandeepmalladi 0:90cd7e5e24af 193 unsigned int cMux = Mux;
sandeepmalladi 0:90cd7e5e24af 194 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 195 WriteRegister(ADS1220_0_REGISTER, 0x01, &cMux);
sandeepmalladi 0:90cd7e5e24af 196
sandeepmalladi 0:90cd7e5e24af 197 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 198 }
sandeepmalladi 0:90cd7e5e24af 199
sandeepmalladi 0:90cd7e5e24af 200 int ADS1220::SetGain(int Gain)
sandeepmalladi 0:90cd7e5e24af 201 {
sandeepmalladi 0:90cd7e5e24af 202 unsigned int cGain = Gain;
sandeepmalladi 0:90cd7e5e24af 203 // write the register value containing the new code back to the ADS
sandeepmalladi 0:90cd7e5e24af 204 WriteRegister(ADS1220_0_REGISTER, 0x01, &cGain);
sandeepmalladi 0:90cd7e5e24af 205
sandeepmalladi 0:90cd7e5e24af 206 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 207 }
sandeepmalladi 0:90cd7e5e24af 208
sandeepmalladi 0:90cd7e5e24af 209 int ADS1220::SetPGABypass(int Bypass)
sandeepmalladi 0:90cd7e5e24af 210 {
sandeepmalladi 0:90cd7e5e24af 211 unsigned int cBypass = Bypass;
sandeepmalladi 0:90cd7e5e24af 212 // write the register value containing the new code back to the ADS
sandeepmalladi 0:90cd7e5e24af 213 WriteRegister(ADS1220_0_REGISTER, 0x01, &cBypass);
sandeepmalladi 0:90cd7e5e24af 214
sandeepmalladi 0:90cd7e5e24af 215 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 216 }
sandeepmalladi 0:90cd7e5e24af 217
sandeepmalladi 0:90cd7e5e24af 218 int ADS1220::SetDataRate(int DataRate)
sandeepmalladi 0:90cd7e5e24af 219 {
sandeepmalladi 0:90cd7e5e24af 220 unsigned int cDataRate = DataRate;
sandeepmalladi 0:90cd7e5e24af 221 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 222 WriteRegister(ADS1220_1_REGISTER, 0x01, &cDataRate);
sandeepmalladi 0:90cd7e5e24af 223
sandeepmalladi 0:90cd7e5e24af 224 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 225 }
sandeepmalladi 0:90cd7e5e24af 226
sandeepmalladi 0:90cd7e5e24af 227 int ADS1220::SetClockMode(int ClockMode)
sandeepmalladi 0:90cd7e5e24af 228 {
sandeepmalladi 0:90cd7e5e24af 229 unsigned int cClockMode = ClockMode;
sandeepmalladi 0:90cd7e5e24af 230
sandeepmalladi 0:90cd7e5e24af 231 // write the register value containing the value back to the ADS
sandeepmalladi 0:90cd7e5e24af 232 WriteRegister(ADS1220_1_REGISTER, 0x01, &cClockMode);
sandeepmalladi 0:90cd7e5e24af 233
sandeepmalladi 0:90cd7e5e24af 234 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 235 }
sandeepmalladi 0:90cd7e5e24af 236
sandeepmalladi 0:90cd7e5e24af 237 int ADS1220::SetPowerDown(int PowerDown)
sandeepmalladi 0:90cd7e5e24af 238 {
sandeepmalladi 0:90cd7e5e24af 239 unsigned int cPowerDown = PowerDown;
sandeepmalladi 0:90cd7e5e24af 240
sandeepmalladi 0:90cd7e5e24af 241 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 242 WriteRegister(ADS1220_1_REGISTER, 0x01, &cPowerDown);
sandeepmalladi 0:90cd7e5e24af 243
sandeepmalladi 0:90cd7e5e24af 244 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 245 }
sandeepmalladi 0:90cd7e5e24af 246
sandeepmalladi 0:90cd7e5e24af 247 int ADS1220::SetTemperatureMode(int TempMode)
sandeepmalladi 0:90cd7e5e24af 248 {
sandeepmalladi 0:90cd7e5e24af 249 unsigned int cTempMode = TempMode;
sandeepmalladi 0:90cd7e5e24af 250
sandeepmalladi 0:90cd7e5e24af 251 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 252 WriteRegister(ADS1220_1_REGISTER, 0x01, &cTempMode);
sandeepmalladi 0:90cd7e5e24af 253
sandeepmalladi 0:90cd7e5e24af 254 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 255 }
sandeepmalladi 0:90cd7e5e24af 256
sandeepmalladi 0:90cd7e5e24af 257 int ADS1220::SetBurnOutSource(int BurnOut)
sandeepmalladi 0:90cd7e5e24af 258 {
sandeepmalladi 0:90cd7e5e24af 259 unsigned int cBurnOut = BurnOut;
sandeepmalladi 0:90cd7e5e24af 260
sandeepmalladi 0:90cd7e5e24af 261 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 262 WriteRegister(ADS1220_1_REGISTER, 0x01, &cBurnOut);
sandeepmalladi 0:90cd7e5e24af 263
sandeepmalladi 0:90cd7e5e24af 264 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 265 }
sandeepmalladi 0:90cd7e5e24af 266
sandeepmalladi 0:90cd7e5e24af 267 int ADS1220::SetVoltageReference(int VoltageRef)
sandeepmalladi 0:90cd7e5e24af 268 {
sandeepmalladi 0:90cd7e5e24af 269 unsigned int cVoltageRef = VoltageRef;
sandeepmalladi 0:90cd7e5e24af 270
sandeepmalladi 0:90cd7e5e24af 271 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 272 WriteRegister(ADS1220_2_REGISTER, 0x01, &cVoltageRef);
sandeepmalladi 0:90cd7e5e24af 273
sandeepmalladi 0:90cd7e5e24af 274 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 275 }
sandeepmalladi 0:90cd7e5e24af 276
sandeepmalladi 0:90cd7e5e24af 277 int ADS1220::Set50_60Rejection(int Rejection)
sandeepmalladi 0:90cd7e5e24af 278 {
sandeepmalladi 0:90cd7e5e24af 279 unsigned int cRejection = Rejection;
sandeepmalladi 0:90cd7e5e24af 280
sandeepmalladi 0:90cd7e5e24af 281 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 282 WriteRegister(ADS1220_2_REGISTER, 0x01, &cRejection);
sandeepmalladi 0:90cd7e5e24af 283
sandeepmalladi 0:90cd7e5e24af 284 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 285 }
sandeepmalladi 0:90cd7e5e24af 286
sandeepmalladi 0:90cd7e5e24af 287 int ADS1220::SetLowSidePowerSwitch(int PowerSwitch)
sandeepmalladi 0:90cd7e5e24af 288 {
sandeepmalladi 0:90cd7e5e24af 289 unsigned int cPowerSwitch = PowerSwitch;
sandeepmalladi 0:90cd7e5e24af 290
sandeepmalladi 0:90cd7e5e24af 291 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 292 WriteRegister(ADS1220_2_REGISTER, 0x01, &cPowerSwitch);
sandeepmalladi 0:90cd7e5e24af 293
sandeepmalladi 0:90cd7e5e24af 294 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 295 }
sandeepmalladi 0:90cd7e5e24af 296
sandeepmalladi 0:90cd7e5e24af 297 int ADS1220::SetCurrentDACOutput(int CurrentOutput)
sandeepmalladi 0:90cd7e5e24af 298 {
sandeepmalladi 0:90cd7e5e24af 299 unsigned int cCurrentOutput = CurrentOutput;
sandeepmalladi 0:90cd7e5e24af 300
sandeepmalladi 0:90cd7e5e24af 301 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 302 WriteRegister(ADS1220_2_REGISTER, 0x01, &cCurrentOutput);
sandeepmalladi 0:90cd7e5e24af 303
sandeepmalladi 0:90cd7e5e24af 304 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 305 }
sandeepmalladi 0:90cd7e5e24af 306
sandeepmalladi 0:90cd7e5e24af 307 int ADS1220::SetIDACRouting(int IDACRoute)
sandeepmalladi 0:90cd7e5e24af 308 {
sandeepmalladi 0:90cd7e5e24af 309 unsigned int cIDACRoute = IDACRoute;
sandeepmalladi 0:90cd7e5e24af 310
sandeepmalladi 0:90cd7e5e24af 311 // write the register value containing the new value back to the ADS
sandeepmalladi 0:90cd7e5e24af 312 WriteRegister(ADS1220_3_REGISTER, 0x01, &cIDACRoute);
sandeepmalladi 0:90cd7e5e24af 313
sandeepmalladi 0:90cd7e5e24af 314 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 315 }
sandeepmalladi 0:90cd7e5e24af 316
sandeepmalladi 0:90cd7e5e24af 317 int ADS1220::SetDRDYMode(int DRDYMode)
sandeepmalladi 0:90cd7e5e24af 318 {
sandeepmalladi 0:90cd7e5e24af 319 unsigned int cDRDYMode = DRDYMode;
sandeepmalladi 0:90cd7e5e24af 320
sandeepmalladi 0:90cd7e5e24af 321 // write the register value containing the new gain code back to the ADS
sandeepmalladi 0:90cd7e5e24af 322 WriteRegister(ADS1220_3_REGISTER, 0x01, &cDRDYMode);
sandeepmalladi 0:90cd7e5e24af 323
sandeepmalladi 0:90cd7e5e24af 324 return ADS1220_NO_ERROR;
sandeepmalladi 0:90cd7e5e24af 325 }
sandeepmalladi 0:90cd7e5e24af 326
sandeepmalladi 0:90cd7e5e24af 327 /*
sandeepmalladi 0:90cd7e5e24af 328 ******************************************************************************
sandeepmalladi 0:90cd7e5e24af 329 register get value commands
sandeepmalladi 0:90cd7e5e24af 330 */
sandeepmalladi 0:90cd7e5e24af 331
sandeepmalladi 0:90cd7e5e24af 332 int ADS1220::GetChannel(void)
sandeepmalladi 0:90cd7e5e24af 333 {
sandeepmalladi 0:90cd7e5e24af 334 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 335
sandeepmalladi 0:90cd7e5e24af 336 //Parse Mux data from register
sandeepmalladi 0:90cd7e5e24af 337 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 338
sandeepmalladi 0:90cd7e5e24af 339 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 340 return (Temp >>4);
sandeepmalladi 0:90cd7e5e24af 341 }
sandeepmalladi 0:90cd7e5e24af 342
sandeepmalladi 0:90cd7e5e24af 343 int ADS1220::GetGain(void)
sandeepmalladi 0:90cd7e5e24af 344 {
sandeepmalladi 0:90cd7e5e24af 345 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 346
sandeepmalladi 0:90cd7e5e24af 347 //Parse Gain data from register
sandeepmalladi 0:90cd7e5e24af 348 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 349
sandeepmalladi 0:90cd7e5e24af 350 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 351 return ( (Temp & 0x0e) >>1);
sandeepmalladi 0:90cd7e5e24af 352 }
sandeepmalladi 0:90cd7e5e24af 353
sandeepmalladi 0:90cd7e5e24af 354 int ADS1220::GetPGABypass(void)
sandeepmalladi 0:90cd7e5e24af 355 {
sandeepmalladi 0:90cd7e5e24af 356 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 357
sandeepmalladi 0:90cd7e5e24af 358 //Parse Bypass data from register
sandeepmalladi 0:90cd7e5e24af 359 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 360
sandeepmalladi 0:90cd7e5e24af 361 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 362 return (Temp & 0x01);
sandeepmalladi 0:90cd7e5e24af 363 }
sandeepmalladi 0:90cd7e5e24af 364
sandeepmalladi 0:90cd7e5e24af 365 int ADS1220::GetDataRate(void)
sandeepmalladi 0:90cd7e5e24af 366 {
sandeepmalladi 0:90cd7e5e24af 367 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 368
sandeepmalladi 0:90cd7e5e24af 369 //Parse DataRate data from register
sandeepmalladi 0:90cd7e5e24af 370 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 371
sandeepmalladi 0:90cd7e5e24af 372 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 373 return ( Temp >>5 );
sandeepmalladi 0:90cd7e5e24af 374 }
sandeepmalladi 0:90cd7e5e24af 375
sandeepmalladi 0:90cd7e5e24af 376 int ADS1220::GetClockMode(void)
sandeepmalladi 0:90cd7e5e24af 377 {
sandeepmalladi 0:90cd7e5e24af 378 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 379
sandeepmalladi 0:90cd7e5e24af 380 //Parse ClockMode data from register
sandeepmalladi 0:90cd7e5e24af 381 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 382
sandeepmalladi 0:90cd7e5e24af 383 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 384 return ( (Temp & 0x18) >>3 );
sandeepmalladi 0:90cd7e5e24af 385 }
sandeepmalladi 0:90cd7e5e24af 386
sandeepmalladi 0:90cd7e5e24af 387 int ADS1220::GetPowerDown(void)
sandeepmalladi 0:90cd7e5e24af 388 {
sandeepmalladi 0:90cd7e5e24af 389 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 390
sandeepmalladi 0:90cd7e5e24af 391 //Parse PowerDown data from register
sandeepmalladi 0:90cd7e5e24af 392 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 393
sandeepmalladi 0:90cd7e5e24af 394 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 395 return ( (Temp & 0x04) >>2 );
sandeepmalladi 0:90cd7e5e24af 396 }
sandeepmalladi 0:90cd7e5e24af 397
sandeepmalladi 0:90cd7e5e24af 398 int ADS1220::GetTemperatureMode(void)
sandeepmalladi 0:90cd7e5e24af 399 {
sandeepmalladi 0:90cd7e5e24af 400 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 401
sandeepmalladi 0:90cd7e5e24af 402 //Parse TempMode data from register
sandeepmalladi 0:90cd7e5e24af 403 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 404
sandeepmalladi 0:90cd7e5e24af 405 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 406 return ( (Temp & 0x02) >>1 );
sandeepmalladi 0:90cd7e5e24af 407 }
sandeepmalladi 0:90cd7e5e24af 408
sandeepmalladi 0:90cd7e5e24af 409 int ADS1220::GetBurnOutSource(void)
sandeepmalladi 0:90cd7e5e24af 410 {
sandeepmalladi 0:90cd7e5e24af 411 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 412
sandeepmalladi 0:90cd7e5e24af 413 //Parse BurnOut data from register
sandeepmalladi 0:90cd7e5e24af 414 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 415
sandeepmalladi 0:90cd7e5e24af 416 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 417 return ( Temp & 0x01 );
sandeepmalladi 0:90cd7e5e24af 418 }
sandeepmalladi 0:90cd7e5e24af 419
sandeepmalladi 0:90cd7e5e24af 420 int ADS1220::GetVoltageReference(void)
sandeepmalladi 0:90cd7e5e24af 421 {
sandeepmalladi 0:90cd7e5e24af 422 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 423
sandeepmalladi 0:90cd7e5e24af 424 //Parse VoltageRef data from register
sandeepmalladi 0:90cd7e5e24af 425 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 426
sandeepmalladi 0:90cd7e5e24af 427 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 428 return ( Temp >>6 );
sandeepmalladi 0:90cd7e5e24af 429 }
sandeepmalladi 0:90cd7e5e24af 430
sandeepmalladi 0:90cd7e5e24af 431 int ADS1220::Get50_60Rejection(void)
sandeepmalladi 0:90cd7e5e24af 432 {
sandeepmalladi 0:90cd7e5e24af 433 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 434
sandeepmalladi 0:90cd7e5e24af 435 //Parse Rejection data from register
sandeepmalladi 0:90cd7e5e24af 436 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 437
sandeepmalladi 0:90cd7e5e24af 438 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 439 return ( (Temp & 0x30) >>4 );
sandeepmalladi 0:90cd7e5e24af 440 }
sandeepmalladi 0:90cd7e5e24af 441
sandeepmalladi 0:90cd7e5e24af 442 int ADS1220::GetLowSidePowerSwitch(void)
sandeepmalladi 0:90cd7e5e24af 443 {
sandeepmalladi 0:90cd7e5e24af 444 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 445
sandeepmalladi 0:90cd7e5e24af 446 //Parse PowerSwitch data from register
sandeepmalladi 0:90cd7e5e24af 447 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 448
sandeepmalladi 0:90cd7e5e24af 449 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 450 return ( (Temp & 0x08) >>3);
sandeepmalladi 0:90cd7e5e24af 451 }
sandeepmalladi 0:90cd7e5e24af 452
sandeepmalladi 0:90cd7e5e24af 453 int ADS1220::GetCurrentDACOutput(void)
sandeepmalladi 0:90cd7e5e24af 454 {
sandeepmalladi 0:90cd7e5e24af 455 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 456
sandeepmalladi 0:90cd7e5e24af 457 //Parse IDACOutput data from register
sandeepmalladi 0:90cd7e5e24af 458 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 459
sandeepmalladi 0:90cd7e5e24af 460 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 461 return ( Temp & 0x07 );
sandeepmalladi 0:90cd7e5e24af 462 }
sandeepmalladi 0:90cd7e5e24af 463
sandeepmalladi 0:90cd7e5e24af 464 int ADS1220::GetIDACRouting(int WhichOne)
sandeepmalladi 0:90cd7e5e24af 465 {
sandeepmalladi 0:90cd7e5e24af 466 // Check WhichOne sizing
sandeepmalladi 0:90cd7e5e24af 467 if (WhichOne >1) return ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 468
sandeepmalladi 0:90cd7e5e24af 469 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 470
sandeepmalladi 0:90cd7e5e24af 471 //Parse Mux data from register
sandeepmalladi 0:90cd7e5e24af 472 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 473
sandeepmalladi 0:90cd7e5e24af 474 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 475 if (WhichOne) return ( (Temp & 0x1c) >>2);
sandeepmalladi 0:90cd7e5e24af 476
sandeepmalladi 0:90cd7e5e24af 477 else return ( Temp >>5 );
sandeepmalladi 0:90cd7e5e24af 478
sandeepmalladi 0:90cd7e5e24af 479 }
sandeepmalladi 0:90cd7e5e24af 480
sandeepmalladi 0:90cd7e5e24af 481 int ADS1220::GetDRDYMode(void)
sandeepmalladi 0:90cd7e5e24af 482 {
sandeepmalladi 0:90cd7e5e24af 483 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 484
sandeepmalladi 0:90cd7e5e24af 485 //Parse DRDYMode data from register
sandeepmalladi 0:90cd7e5e24af 486 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 487
sandeepmalladi 0:90cd7e5e24af 488 // return the parsed data
sandeepmalladi 0:90cd7e5e24af 489 return ( (Temp & 0x02) >>1 );
sandeepmalladi 0:90cd7e5e24af 490 }
sandeepmalladi 0:90cd7e5e24af 491
sandeepmalladi 0:90cd7e5e24af 492
sandeepmalladi 0:90cd7e5e24af 493
sandeepmalladi 0:90cd7e5e24af 494 /* Useful Functions within Main Program for Setting Register Contents
sandeepmalladi 0:90cd7e5e24af 495 *
sandeepmalladi 0:90cd7e5e24af 496 * These functions show the programming flow based on the header definitions.
sandeepmalladi 0:90cd7e5e24af 497 * The calls are not made within the demo example, but could easily be used by calling the function
sandeepmalladi 0:90cd7e5e24af 498 * defined within the program to complete a fully useful program.
sandeepmalladi 0:90cd7e5e24af 499 * Similar function calls were made in the firwmare design for the ADS1220EVM.
sandeepmalladi 0:90cd7e5e24af 500 *
sandeepmalladi 0:90cd7e5e24af 501 * The following function calls use ASCII data sent from a COM port to control settings
sandeepmalladi 0:90cd7e5e24af 502 * on the The data is recontructed from ASCII and then combined with the
sandeepmalladi 0:90cd7e5e24af 503 * register contents to save as new configuration settings.
sandeepmalladi 0:90cd7e5e24af 504 *
sandeepmalladi 0:90cd7e5e24af 505 * Function names correspond to datasheet register definitions
sandeepmalladi 0:90cd7e5e24af 506 */
sandeepmalladi 0:90cd7e5e24af 507 void ADS1220::set_MUX(char c)
sandeepmalladi 0:90cd7e5e24af 508 {
sandeepmalladi 0:90cd7e5e24af 509 int dERROR;
sandeepmalladi 0:90cd7e5e24af 510 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 511 char mux = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 512
sandeepmalladi 0:90cd7e5e24af 513
sandeepmalladi 0:90cd7e5e24af 514 if (mux>=49 && mux<=54) mux -= 39;
sandeepmalladi 0:90cd7e5e24af 515
sandeepmalladi 0:90cd7e5e24af 516 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 517 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 518 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 519
sandeepmalladi 0:90cd7e5e24af 520 Temp &= 0x0f; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 521 // Change Data rate
sandeepmalladi 0:90cd7e5e24af 522 switch(mux) {
sandeepmalladi 0:90cd7e5e24af 523 case 0:
sandeepmalladi 0:90cd7e5e24af 524 dERROR = SetChannel(Temp + ADS1220_MUX_0_1);
sandeepmalladi 0:90cd7e5e24af 525 break;
sandeepmalladi 0:90cd7e5e24af 526 case 1:
sandeepmalladi 0:90cd7e5e24af 527 dERROR = SetChannel(Temp + ADS1220_MUX_0_2);
sandeepmalladi 0:90cd7e5e24af 528 break;
sandeepmalladi 0:90cd7e5e24af 529 case 2:
sandeepmalladi 0:90cd7e5e24af 530 dERROR = SetChannel(Temp + ADS1220_MUX_0_3);
sandeepmalladi 0:90cd7e5e24af 531 break;
sandeepmalladi 0:90cd7e5e24af 532 case 3:
sandeepmalladi 0:90cd7e5e24af 533 dERROR = SetChannel(Temp + ADS1220_MUX_1_2);
sandeepmalladi 0:90cd7e5e24af 534 break;
sandeepmalladi 0:90cd7e5e24af 535 case 4:
sandeepmalladi 0:90cd7e5e24af 536 dERROR = SetChannel(Temp + ADS1220_MUX_1_3);
sandeepmalladi 0:90cd7e5e24af 537 break;
sandeepmalladi 0:90cd7e5e24af 538 case 5:
sandeepmalladi 0:90cd7e5e24af 539 dERROR = SetChannel(Temp + ADS1220_MUX_2_3);
sandeepmalladi 0:90cd7e5e24af 540 break;
sandeepmalladi 0:90cd7e5e24af 541 case 6:
sandeepmalladi 0:90cd7e5e24af 542 dERROR = SetChannel(Temp + ADS1220_MUX_1_0);
sandeepmalladi 0:90cd7e5e24af 543 break;
sandeepmalladi 0:90cd7e5e24af 544 case 7:
sandeepmalladi 0:90cd7e5e24af 545 dERROR = SetChannel(Temp + ADS1220_MUX_3_2);
sandeepmalladi 0:90cd7e5e24af 546 break;
sandeepmalladi 0:90cd7e5e24af 547 case 8:
firewalk 1:34692a3d25f7 548 dERROR = SetChannel(Temp + ADS1220_MUX_2_G);
sandeepmalladi 0:90cd7e5e24af 549 break;
sandeepmalladi 0:90cd7e5e24af 550 case 9:
sandeepmalladi 0:90cd7e5e24af 551 dERROR = SetChannel(Temp + ADS1220_MUX_1_G);
sandeepmalladi 0:90cd7e5e24af 552 break;
sandeepmalladi 0:90cd7e5e24af 553 case 10:
firewalk 1:34692a3d25f7 554 dERROR = SetChannel(Temp + ADS1220_MUX_0_G);
sandeepmalladi 0:90cd7e5e24af 555 break;
sandeepmalladi 0:90cd7e5e24af 556 case 11:
sandeepmalladi 0:90cd7e5e24af 557 dERROR = SetChannel(Temp + ADS1220_MUX_3_G);
sandeepmalladi 0:90cd7e5e24af 558 break;
sandeepmalladi 0:90cd7e5e24af 559 case 12:
sandeepmalladi 0:90cd7e5e24af 560 dERROR = SetChannel(Temp + ADS1220_MUX_EX_VREF);
sandeepmalladi 0:90cd7e5e24af 561 break;
sandeepmalladi 0:90cd7e5e24af 562 case 13:
sandeepmalladi 0:90cd7e5e24af 563 dERROR = SetChannel(Temp + ADS1220_MUX_AVDD);
sandeepmalladi 0:90cd7e5e24af 564 break;
sandeepmalladi 0:90cd7e5e24af 565 case 14:
sandeepmalladi 0:90cd7e5e24af 566 dERROR = SetChannel(Temp + ADS1220_MUX_DIV2);
sandeepmalladi 0:90cd7e5e24af 567 break;
sandeepmalladi 0:90cd7e5e24af 568 case 15:
sandeepmalladi 0:90cd7e5e24af 569 dERROR = SetChannel(Temp + ADS1220_MUX_DIV2);
sandeepmalladi 0:90cd7e5e24af 570 break;
sandeepmalladi 0:90cd7e5e24af 571 default:
sandeepmalladi 0:90cd7e5e24af 572 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 573 break;
sandeepmalladi 0:90cd7e5e24af 574 }
sandeepmalladi 0:90cd7e5e24af 575
sandeepmalladi 0:90cd7e5e24af 576 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 577 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 578
sandeepmalladi 0:90cd7e5e24af 579 }
sandeepmalladi 0:90cd7e5e24af 580
sandeepmalladi 0:90cd7e5e24af 581 void ADS1220::set_GAIN(char c)
sandeepmalladi 0:90cd7e5e24af 582 {
sandeepmalladi 0:90cd7e5e24af 583 int pga = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 584 int dERROR;
sandeepmalladi 0:90cd7e5e24af 585 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 586
sandeepmalladi 0:90cd7e5e24af 587 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 588 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 589 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 590
sandeepmalladi 0:90cd7e5e24af 591 Temp &= 0xf1; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 592 // Change gain rate
sandeepmalladi 0:90cd7e5e24af 593 switch(pga) {
sandeepmalladi 0:90cd7e5e24af 594 case 0:
sandeepmalladi 0:90cd7e5e24af 595 dERROR = SetGain(Temp + ADS1220_GAIN_1);
sandeepmalladi 0:90cd7e5e24af 596 break;
sandeepmalladi 0:90cd7e5e24af 597 case 1:
sandeepmalladi 0:90cd7e5e24af 598 dERROR = SetGain(Temp + ADS1220_GAIN_2);
sandeepmalladi 0:90cd7e5e24af 599 break;
sandeepmalladi 0:90cd7e5e24af 600 case 2:
sandeepmalladi 0:90cd7e5e24af 601 dERROR = SetGain(Temp + ADS1220_GAIN_4);
sandeepmalladi 0:90cd7e5e24af 602 break;
sandeepmalladi 0:90cd7e5e24af 603 case 3:
sandeepmalladi 0:90cd7e5e24af 604 dERROR = SetGain(Temp + ADS1220_GAIN_8);
sandeepmalladi 0:90cd7e5e24af 605 break;
sandeepmalladi 0:90cd7e5e24af 606 case 4:
sandeepmalladi 0:90cd7e5e24af 607 dERROR = SetGain(Temp + ADS1220_GAIN_16);
sandeepmalladi 0:90cd7e5e24af 608 break;
sandeepmalladi 0:90cd7e5e24af 609 case 5:
sandeepmalladi 0:90cd7e5e24af 610 dERROR = SetGain(Temp + ADS1220_GAIN_32);
sandeepmalladi 0:90cd7e5e24af 611 break;
sandeepmalladi 0:90cd7e5e24af 612 case 6:
sandeepmalladi 0:90cd7e5e24af 613 dERROR = SetGain(Temp + ADS1220_GAIN_64);
sandeepmalladi 0:90cd7e5e24af 614 break;
sandeepmalladi 0:90cd7e5e24af 615 case 7:
sandeepmalladi 0:90cd7e5e24af 616 dERROR = SetGain(Temp + ADS1220_GAIN_128);
sandeepmalladi 0:90cd7e5e24af 617 break;
sandeepmalladi 0:90cd7e5e24af 618 default:
sandeepmalladi 0:90cd7e5e24af 619 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 620 break;
sandeepmalladi 0:90cd7e5e24af 621 }
sandeepmalladi 0:90cd7e5e24af 622
sandeepmalladi 0:90cd7e5e24af 623
sandeepmalladi 0:90cd7e5e24af 624
sandeepmalladi 0:90cd7e5e24af 625 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 626 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 627 }
sandeepmalladi 0:90cd7e5e24af 628
sandeepmalladi 0:90cd7e5e24af 629 void ADS1220::set_PGA_BYPASS(char c)
sandeepmalladi 0:90cd7e5e24af 630 {
sandeepmalladi 0:90cd7e5e24af 631 int buff = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 632 int dERROR;
sandeepmalladi 0:90cd7e5e24af 633 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 634
sandeepmalladi 0:90cd7e5e24af 635 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 636 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 637 ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 638
sandeepmalladi 0:90cd7e5e24af 639 Temp &= 0xfe; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 640 // Change PGA Bypass
sandeepmalladi 0:90cd7e5e24af 641 switch(buff) {
sandeepmalladi 0:90cd7e5e24af 642 case 0:
sandeepmalladi 0:90cd7e5e24af 643 dERROR = SetPGABypass(Temp);
sandeepmalladi 0:90cd7e5e24af 644 break;
sandeepmalladi 0:90cd7e5e24af 645 case 1:
sandeepmalladi 0:90cd7e5e24af 646 dERROR = SetPGABypass(Temp + ADS1220_PGA_BYPASS);
sandeepmalladi 0:90cd7e5e24af 647 break;
sandeepmalladi 0:90cd7e5e24af 648 default:
sandeepmalladi 0:90cd7e5e24af 649 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 650 break;
sandeepmalladi 0:90cd7e5e24af 651
sandeepmalladi 0:90cd7e5e24af 652 }
sandeepmalladi 0:90cd7e5e24af 653
sandeepmalladi 0:90cd7e5e24af 654 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 655 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 656
sandeepmalladi 0:90cd7e5e24af 657 }
sandeepmalladi 0:90cd7e5e24af 658
sandeepmalladi 0:90cd7e5e24af 659 void ADS1220::set_DR(char c)
sandeepmalladi 0:90cd7e5e24af 660 {
sandeepmalladi 0:90cd7e5e24af 661 int spd = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 662 int dERROR;
sandeepmalladi 0:90cd7e5e24af 663 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 664
sandeepmalladi 0:90cd7e5e24af 665 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 666 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 667 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 668
sandeepmalladi 0:90cd7e5e24af 669 Temp &= 0x1f; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 670 // Change Data rate
sandeepmalladi 0:90cd7e5e24af 671 switch(spd) {
sandeepmalladi 0:90cd7e5e24af 672 case 0:
sandeepmalladi 0:90cd7e5e24af 673 dERROR = SetDataRate(Temp + ADS1220_DR_20);
sandeepmalladi 0:90cd7e5e24af 674 break;
sandeepmalladi 0:90cd7e5e24af 675 case 1:
sandeepmalladi 0:90cd7e5e24af 676 dERROR = SetDataRate(Temp + ADS1220_DR_45);
sandeepmalladi 0:90cd7e5e24af 677 break;
sandeepmalladi 0:90cd7e5e24af 678 case 2:
sandeepmalladi 0:90cd7e5e24af 679 dERROR = SetDataRate(Temp + ADS1220_DR_90);
sandeepmalladi 0:90cd7e5e24af 680 break;
sandeepmalladi 0:90cd7e5e24af 681 case 3:
sandeepmalladi 0:90cd7e5e24af 682 dERROR = SetDataRate(Temp + ADS1220_DR_175);
sandeepmalladi 0:90cd7e5e24af 683 break;
sandeepmalladi 0:90cd7e5e24af 684 case 4:
sandeepmalladi 0:90cd7e5e24af 685 dERROR = SetDataRate(Temp + ADS1220_DR_330);
sandeepmalladi 0:90cd7e5e24af 686 break;
sandeepmalladi 0:90cd7e5e24af 687 case 5:
sandeepmalladi 0:90cd7e5e24af 688 dERROR = SetDataRate(Temp + ADS1220_DR_600);
sandeepmalladi 0:90cd7e5e24af 689 break;
sandeepmalladi 0:90cd7e5e24af 690 case 6:
sandeepmalladi 0:90cd7e5e24af 691 dERROR = SetDataRate(Temp + ADS1220_DR_1000);
sandeepmalladi 0:90cd7e5e24af 692 break;
sandeepmalladi 0:90cd7e5e24af 693 case 7:
sandeepmalladi 0:90cd7e5e24af 694 dERROR = SetDataRate(Temp + ADS1220_DR_1000);
sandeepmalladi 0:90cd7e5e24af 695 break;
sandeepmalladi 0:90cd7e5e24af 696 default:
sandeepmalladi 0:90cd7e5e24af 697 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 698 break;
sandeepmalladi 0:90cd7e5e24af 699 }
sandeepmalladi 0:90cd7e5e24af 700
sandeepmalladi 0:90cd7e5e24af 701 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 702 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 703
sandeepmalladi 0:90cd7e5e24af 704 }
sandeepmalladi 0:90cd7e5e24af 705
sandeepmalladi 0:90cd7e5e24af 706 void ADS1220::set_MODE(char c)
sandeepmalladi 0:90cd7e5e24af 707 {
sandeepmalladi 0:90cd7e5e24af 708 int spd = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 709 int dERROR;
sandeepmalladi 0:90cd7e5e24af 710 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 711
sandeepmalladi 0:90cd7e5e24af 712 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 713 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 714 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 715
sandeepmalladi 0:90cd7e5e24af 716 Temp &= 0xe7; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 717 // Change Data rate
sandeepmalladi 0:90cd7e5e24af 718 switch(spd) {
sandeepmalladi 0:90cd7e5e24af 719 case 0:
sandeepmalladi 0:90cd7e5e24af 720 dERROR = SetClockMode(Temp + ADS1220_MODE_NORMAL);
sandeepmalladi 0:90cd7e5e24af 721 break;
sandeepmalladi 0:90cd7e5e24af 722 case 1:
sandeepmalladi 0:90cd7e5e24af 723 dERROR = SetClockMode(Temp + ADS1220_MODE_DUTY);
sandeepmalladi 0:90cd7e5e24af 724 break;
sandeepmalladi 0:90cd7e5e24af 725 case 2:
sandeepmalladi 0:90cd7e5e24af 726 dERROR = SetClockMode(Temp + ADS1220_MODE_TURBO);
sandeepmalladi 0:90cd7e5e24af 727 break;
sandeepmalladi 0:90cd7e5e24af 728 case 3:
sandeepmalladi 0:90cd7e5e24af 729 dERROR = SetClockMode(Temp + ADS1220_MODE_DCT);
sandeepmalladi 0:90cd7e5e24af 730 break;
sandeepmalladi 0:90cd7e5e24af 731 default:
sandeepmalladi 0:90cd7e5e24af 732 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 733 break;
sandeepmalladi 0:90cd7e5e24af 734
sandeepmalladi 0:90cd7e5e24af 735 }
sandeepmalladi 0:90cd7e5e24af 736
sandeepmalladi 0:90cd7e5e24af 737 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 738 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 739
sandeepmalladi 0:90cd7e5e24af 740 }
sandeepmalladi 0:90cd7e5e24af 741
sandeepmalladi 0:90cd7e5e24af 742 void ADS1220::set_CM(char c)
sandeepmalladi 0:90cd7e5e24af 743 {
sandeepmalladi 0:90cd7e5e24af 744 int pwrdn = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 745 int dERROR;
sandeepmalladi 0:90cd7e5e24af 746 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 747
sandeepmalladi 0:90cd7e5e24af 748 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 749 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 750 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 751
sandeepmalladi 0:90cd7e5e24af 752 Temp &= 0xfb; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 753 // Change power down mode
sandeepmalladi 0:90cd7e5e24af 754 switch(pwrdn) {
sandeepmalladi 0:90cd7e5e24af 755 case 0:
sandeepmalladi 0:90cd7e5e24af 756 dERROR = SetPowerDown(Temp);
sandeepmalladi 0:90cd7e5e24af 757 break;
sandeepmalladi 0:90cd7e5e24af 758 case 1:
sandeepmalladi 0:90cd7e5e24af 759 dERROR = SetPowerDown(Temp + ADS1220_CC);
sandeepmalladi 0:90cd7e5e24af 760 break;
sandeepmalladi 0:90cd7e5e24af 761 default:
sandeepmalladi 0:90cd7e5e24af 762 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 763 break;
sandeepmalladi 0:90cd7e5e24af 764
sandeepmalladi 0:90cd7e5e24af 765 }
sandeepmalladi 0:90cd7e5e24af 766
sandeepmalladi 0:90cd7e5e24af 767 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 768 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 769
sandeepmalladi 0:90cd7e5e24af 770 }
sandeepmalladi 0:90cd7e5e24af 771
sandeepmalladi 0:90cd7e5e24af 772 void ADS1220::set_TS(char c)
sandeepmalladi 0:90cd7e5e24af 773 {
sandeepmalladi 0:90cd7e5e24af 774 int tmp = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 775 int dERROR;
sandeepmalladi 0:90cd7e5e24af 776 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 777
sandeepmalladi 0:90cd7e5e24af 778 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 779 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 780 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 781
sandeepmalladi 0:90cd7e5e24af 782 Temp &= 0xfd; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 783 // Change Temp Diode Setting
sandeepmalladi 0:90cd7e5e24af 784 switch(tmp) {
sandeepmalladi 0:90cd7e5e24af 785 case 0:
sandeepmalladi 0:90cd7e5e24af 786 dERROR = SetTemperatureMode(Temp);
sandeepmalladi 0:90cd7e5e24af 787 break;
sandeepmalladi 0:90cd7e5e24af 788 case 1:
sandeepmalladi 0:90cd7e5e24af 789 dERROR = SetTemperatureMode(Temp + ADS1220_TEMP_SENSOR);
sandeepmalladi 0:90cd7e5e24af 790 break;
sandeepmalladi 0:90cd7e5e24af 791 default:
sandeepmalladi 0:90cd7e5e24af 792 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 793 break;
sandeepmalladi 0:90cd7e5e24af 794
sandeepmalladi 0:90cd7e5e24af 795 }
sandeepmalladi 0:90cd7e5e24af 796
sandeepmalladi 0:90cd7e5e24af 797 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 798 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 799
sandeepmalladi 0:90cd7e5e24af 800 }
sandeepmalladi 0:90cd7e5e24af 801
sandeepmalladi 0:90cd7e5e24af 802 void ADS1220::set_BCS(char c)
sandeepmalladi 0:90cd7e5e24af 803 {
sandeepmalladi 0:90cd7e5e24af 804 int bo = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 805 int dERROR;
sandeepmalladi 0:90cd7e5e24af 806 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 807
sandeepmalladi 0:90cd7e5e24af 808 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 809 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 810 ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 811
sandeepmalladi 0:90cd7e5e24af 812 Temp &= 0xfe; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 813 // Change PGA Bypass
sandeepmalladi 0:90cd7e5e24af 814 switch(bo) {
sandeepmalladi 0:90cd7e5e24af 815 case 0:
sandeepmalladi 0:90cd7e5e24af 816 dERROR = SetBurnOutSource(Temp);
sandeepmalladi 0:90cd7e5e24af 817 break;
sandeepmalladi 0:90cd7e5e24af 818 case 1:
sandeepmalladi 0:90cd7e5e24af 819 dERROR = SetBurnOutSource(Temp + ADS1220_BCS);
sandeepmalladi 0:90cd7e5e24af 820 break;
sandeepmalladi 0:90cd7e5e24af 821 default:
sandeepmalladi 0:90cd7e5e24af 822 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 823 break;
sandeepmalladi 0:90cd7e5e24af 824
sandeepmalladi 0:90cd7e5e24af 825 }
sandeepmalladi 0:90cd7e5e24af 826
sandeepmalladi 0:90cd7e5e24af 827 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 828 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 829
sandeepmalladi 0:90cd7e5e24af 830 }
sandeepmalladi 0:90cd7e5e24af 831
sandeepmalladi 0:90cd7e5e24af 832 void ADS1220::set_VREF(char c)
sandeepmalladi 0:90cd7e5e24af 833 {
sandeepmalladi 0:90cd7e5e24af 834 int ref = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 835 int dERROR;
sandeepmalladi 0:90cd7e5e24af 836 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 837
sandeepmalladi 0:90cd7e5e24af 838 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 839 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 840 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 841
sandeepmalladi 0:90cd7e5e24af 842 Temp &= 0x3f; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 843 // Change Reference
sandeepmalladi 0:90cd7e5e24af 844 switch(ref) {
sandeepmalladi 0:90cd7e5e24af 845 case 0:
sandeepmalladi 0:90cd7e5e24af 846 dERROR = SetVoltageReference(Temp + ADS1220_VREF_INT);
sandeepmalladi 0:90cd7e5e24af 847 break;
sandeepmalladi 0:90cd7e5e24af 848 case 1:
sandeepmalladi 0:90cd7e5e24af 849 dERROR = SetVoltageReference(Temp + ADS1220_VREF_EX_DED);
sandeepmalladi 0:90cd7e5e24af 850 break;
sandeepmalladi 0:90cd7e5e24af 851 case 2:
sandeepmalladi 0:90cd7e5e24af 852 dERROR = SetVoltageReference(Temp + ADS1220_VREF_EX_AIN);
sandeepmalladi 0:90cd7e5e24af 853 break;
sandeepmalladi 0:90cd7e5e24af 854 case 3:
sandeepmalladi 0:90cd7e5e24af 855 dERROR = SetVoltageReference(Temp + ADS1220_VREF_SUPPLY);
sandeepmalladi 0:90cd7e5e24af 856 break;
sandeepmalladi 0:90cd7e5e24af 857 default:
sandeepmalladi 0:90cd7e5e24af 858 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 859 break;
sandeepmalladi 0:90cd7e5e24af 860
sandeepmalladi 0:90cd7e5e24af 861 }
sandeepmalladi 0:90cd7e5e24af 862
sandeepmalladi 0:90cd7e5e24af 863 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 864 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 865
sandeepmalladi 0:90cd7e5e24af 866 }
sandeepmalladi 0:90cd7e5e24af 867 void ADS1220::set_50_60(char c)
sandeepmalladi 0:90cd7e5e24af 868 {
sandeepmalladi 0:90cd7e5e24af 869 int flt = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 870 int dERROR;
sandeepmalladi 0:90cd7e5e24af 871 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 872
sandeepmalladi 0:90cd7e5e24af 873 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 874 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 875 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 876
sandeepmalladi 0:90cd7e5e24af 877 Temp &= 0xcf; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 878 // Change Filter
sandeepmalladi 0:90cd7e5e24af 879 switch(flt) {
sandeepmalladi 0:90cd7e5e24af 880 case 0:
sandeepmalladi 0:90cd7e5e24af 881 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_OFF);
sandeepmalladi 0:90cd7e5e24af 882 break;
sandeepmalladi 0:90cd7e5e24af 883 case 1:
sandeepmalladi 0:90cd7e5e24af 884 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_BOTH);
sandeepmalladi 0:90cd7e5e24af 885 break;
sandeepmalladi 0:90cd7e5e24af 886 case 2:
sandeepmalladi 0:90cd7e5e24af 887 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_50);
sandeepmalladi 0:90cd7e5e24af 888 break;
sandeepmalladi 0:90cd7e5e24af 889 case 3:
sandeepmalladi 0:90cd7e5e24af 890 dERROR = Set50_60Rejection(Temp + ADS1220_REJECT_60);
sandeepmalladi 0:90cd7e5e24af 891 break;
sandeepmalladi 0:90cd7e5e24af 892 default:
sandeepmalladi 0:90cd7e5e24af 893 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 894 break;
sandeepmalladi 0:90cd7e5e24af 895
sandeepmalladi 0:90cd7e5e24af 896 }
sandeepmalladi 0:90cd7e5e24af 897
sandeepmalladi 0:90cd7e5e24af 898 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 899 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 900
sandeepmalladi 0:90cd7e5e24af 901 }
sandeepmalladi 0:90cd7e5e24af 902
sandeepmalladi 0:90cd7e5e24af 903 void ADS1220::set_PSW(char c)
sandeepmalladi 0:90cd7e5e24af 904 {
sandeepmalladi 0:90cd7e5e24af 905 int sw = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 906 int dERROR;
sandeepmalladi 0:90cd7e5e24af 907 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 908
sandeepmalladi 0:90cd7e5e24af 909 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 910 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 911 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 912
sandeepmalladi 0:90cd7e5e24af 913 Temp &= 0xf7; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 914 // Change power down mode
sandeepmalladi 0:90cd7e5e24af 915 switch(sw) {
sandeepmalladi 0:90cd7e5e24af 916 case 0:
sandeepmalladi 0:90cd7e5e24af 917 dERROR = SetLowSidePowerSwitch(Temp);
sandeepmalladi 0:90cd7e5e24af 918 break;
sandeepmalladi 0:90cd7e5e24af 919 case 1:
sandeepmalladi 0:90cd7e5e24af 920 dERROR = SetLowSidePowerSwitch(Temp + ADS1220_PSW_SW);
sandeepmalladi 0:90cd7e5e24af 921 break;
sandeepmalladi 0:90cd7e5e24af 922 default:
sandeepmalladi 0:90cd7e5e24af 923 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 924 break;
sandeepmalladi 0:90cd7e5e24af 925
sandeepmalladi 0:90cd7e5e24af 926 }
sandeepmalladi 0:90cd7e5e24af 927
sandeepmalladi 0:90cd7e5e24af 928 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 929 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 930
sandeepmalladi 0:90cd7e5e24af 931 }
sandeepmalladi 0:90cd7e5e24af 932
sandeepmalladi 0:90cd7e5e24af 933 void ADS1220::set_IDAC(char c)
sandeepmalladi 0:90cd7e5e24af 934 {
sandeepmalladi 0:90cd7e5e24af 935 int current = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 936 int dERROR;
sandeepmalladi 0:90cd7e5e24af 937 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 938
sandeepmalladi 0:90cd7e5e24af 939 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 940 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 941 ReadRegister(ADS1220_2_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 942
sandeepmalladi 0:90cd7e5e24af 943 Temp &= 0xf8; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 944 // Change IDAC Current Output
sandeepmalladi 0:90cd7e5e24af 945 switch(current) {
sandeepmalladi 0:90cd7e5e24af 946 case 0:
sandeepmalladi 0:90cd7e5e24af 947 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_OFF);
sandeepmalladi 0:90cd7e5e24af 948 break;
sandeepmalladi 0:90cd7e5e24af 949 case 1:
sandeepmalladi 0:90cd7e5e24af 950 #ifdef ADS1120
sandeepmalladi 0:90cd7e5e24af 951 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_OFF);
sandeepmalladi 0:90cd7e5e24af 952 #else
sandeepmalladi 0:90cd7e5e24af 953 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_10);
sandeepmalladi 0:90cd7e5e24af 954 #endif
sandeepmalladi 0:90cd7e5e24af 955
sandeepmalladi 0:90cd7e5e24af 956 break;
sandeepmalladi 0:90cd7e5e24af 957 case 2:
sandeepmalladi 0:90cd7e5e24af 958 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_50);
sandeepmalladi 0:90cd7e5e24af 959 break;
sandeepmalladi 0:90cd7e5e24af 960 case 3:
sandeepmalladi 0:90cd7e5e24af 961 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_100);
sandeepmalladi 0:90cd7e5e24af 962 break;
sandeepmalladi 0:90cd7e5e24af 963 case 4:
sandeepmalladi 0:90cd7e5e24af 964 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_250);
sandeepmalladi 0:90cd7e5e24af 965 break;
sandeepmalladi 0:90cd7e5e24af 966 case 5:
sandeepmalladi 0:90cd7e5e24af 967 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_500);
sandeepmalladi 0:90cd7e5e24af 968 break;
sandeepmalladi 0:90cd7e5e24af 969 case 6:
sandeepmalladi 0:90cd7e5e24af 970 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_1000);
sandeepmalladi 0:90cd7e5e24af 971 break;
sandeepmalladi 0:90cd7e5e24af 972 case 7:
sandeepmalladi 0:90cd7e5e24af 973 dERROR = SetCurrentDACOutput(Temp + ADS1220_IDAC_2000);
sandeepmalladi 0:90cd7e5e24af 974 break;
sandeepmalladi 0:90cd7e5e24af 975 default:
sandeepmalladi 0:90cd7e5e24af 976 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 977 break;
sandeepmalladi 0:90cd7e5e24af 978
sandeepmalladi 0:90cd7e5e24af 979 }
sandeepmalladi 0:90cd7e5e24af 980
sandeepmalladi 0:90cd7e5e24af 981 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 982 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 983
sandeepmalladi 0:90cd7e5e24af 984 }
sandeepmalladi 0:90cd7e5e24af 985
sandeepmalladi 0:90cd7e5e24af 986 void ADS1220::set_IMUX(char c, int i)
sandeepmalladi 0:90cd7e5e24af 987 {
sandeepmalladi 0:90cd7e5e24af 988 int mux = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 989 int dERROR;
sandeepmalladi 0:90cd7e5e24af 990 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 991
sandeepmalladi 0:90cd7e5e24af 992 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 993 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 994 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 995
sandeepmalladi 0:90cd7e5e24af 996 if (i==1) {
sandeepmalladi 0:90cd7e5e24af 997 Temp &= 0xe3; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 998
sandeepmalladi 0:90cd7e5e24af 999 // Change IDAC2 MUX Output
sandeepmalladi 0:90cd7e5e24af 1000
sandeepmalladi 0:90cd7e5e24af 1001 switch(mux) {
sandeepmalladi 0:90cd7e5e24af 1002 case 0:
sandeepmalladi 0:90cd7e5e24af 1003 Temp |= ADS1220_IDAC2_OFF;
sandeepmalladi 0:90cd7e5e24af 1004 break;
sandeepmalladi 0:90cd7e5e24af 1005 case 1:
sandeepmalladi 0:90cd7e5e24af 1006 Temp |= ADS1220_IDAC2_AIN0;
sandeepmalladi 0:90cd7e5e24af 1007 break;
sandeepmalladi 0:90cd7e5e24af 1008 case 2:
sandeepmalladi 0:90cd7e5e24af 1009 Temp |= ADS1220_IDAC2_AIN1;
sandeepmalladi 0:90cd7e5e24af 1010 break;
sandeepmalladi 0:90cd7e5e24af 1011 case 3:
sandeepmalladi 0:90cd7e5e24af 1012 Temp |= ADS1220_IDAC2_AIN2;
sandeepmalladi 0:90cd7e5e24af 1013 break;
sandeepmalladi 0:90cd7e5e24af 1014 case 4:
sandeepmalladi 0:90cd7e5e24af 1015 Temp |= ADS1220_IDAC2_AIN3;
sandeepmalladi 0:90cd7e5e24af 1016 break;
sandeepmalladi 0:90cd7e5e24af 1017 case 5:
sandeepmalladi 0:90cd7e5e24af 1018 Temp |= ADS1220_IDAC2_REFP0;
sandeepmalladi 0:90cd7e5e24af 1019 break;
sandeepmalladi 0:90cd7e5e24af 1020 case 6:
sandeepmalladi 0:90cd7e5e24af 1021 Temp |= ADS1220_IDAC2_REFN0;
sandeepmalladi 0:90cd7e5e24af 1022 break;
sandeepmalladi 0:90cd7e5e24af 1023 case 7:
sandeepmalladi 0:90cd7e5e24af 1024 Temp |= ADS1220_IDAC2_REFN0;
sandeepmalladi 0:90cd7e5e24af 1025 break;
sandeepmalladi 0:90cd7e5e24af 1026 default:
sandeepmalladi 0:90cd7e5e24af 1027 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 1028 break;
sandeepmalladi 0:90cd7e5e24af 1029
sandeepmalladi 0:90cd7e5e24af 1030 }
sandeepmalladi 0:90cd7e5e24af 1031 }
sandeepmalladi 0:90cd7e5e24af 1032 else {
sandeepmalladi 0:90cd7e5e24af 1033 Temp &= 0x1f;
sandeepmalladi 0:90cd7e5e24af 1034 // Change IDAC1 MUX Output
sandeepmalladi 0:90cd7e5e24af 1035 switch(mux) {
sandeepmalladi 0:90cd7e5e24af 1036 case 0:
sandeepmalladi 0:90cd7e5e24af 1037 Temp |= ADS1220_IDAC1_OFF;
sandeepmalladi 0:90cd7e5e24af 1038 break;
sandeepmalladi 0:90cd7e5e24af 1039 case 1:
sandeepmalladi 0:90cd7e5e24af 1040 Temp |= ADS1220_IDAC1_AIN0;
sandeepmalladi 0:90cd7e5e24af 1041 break;
sandeepmalladi 0:90cd7e5e24af 1042 case 2:
sandeepmalladi 0:90cd7e5e24af 1043 Temp |= ADS1220_IDAC1_AIN1;
sandeepmalladi 0:90cd7e5e24af 1044 break;
sandeepmalladi 0:90cd7e5e24af 1045 case 3:
sandeepmalladi 0:90cd7e5e24af 1046 Temp |= ADS1220_IDAC1_AIN2;
sandeepmalladi 0:90cd7e5e24af 1047 break;
sandeepmalladi 0:90cd7e5e24af 1048 case 4:
sandeepmalladi 0:90cd7e5e24af 1049 Temp |= ADS1220_IDAC1_AIN3;
sandeepmalladi 0:90cd7e5e24af 1050 break;
sandeepmalladi 0:90cd7e5e24af 1051 case 5:
sandeepmalladi 0:90cd7e5e24af 1052 Temp |= ADS1220_IDAC1_REFP0;
sandeepmalladi 0:90cd7e5e24af 1053 break;
sandeepmalladi 0:90cd7e5e24af 1054 case 6:
sandeepmalladi 0:90cd7e5e24af 1055 Temp |= ADS1220_IDAC1_REFN0;
sandeepmalladi 0:90cd7e5e24af 1056 break;
sandeepmalladi 0:90cd7e5e24af 1057 case 7:
sandeepmalladi 0:90cd7e5e24af 1058 Temp |= ADS1220_IDAC1_REFN0;
sandeepmalladi 0:90cd7e5e24af 1059 break;
sandeepmalladi 0:90cd7e5e24af 1060 default:
sandeepmalladi 0:90cd7e5e24af 1061 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 1062 break;
sandeepmalladi 0:90cd7e5e24af 1063 }
sandeepmalladi 0:90cd7e5e24af 1064 }
sandeepmalladi 0:90cd7e5e24af 1065
sandeepmalladi 0:90cd7e5e24af 1066 if (dERROR==ADS1220_NO_ERROR)
sandeepmalladi 0:90cd7e5e24af 1067 dERROR = SetIDACRouting(Temp);
sandeepmalladi 0:90cd7e5e24af 1068
sandeepmalladi 0:90cd7e5e24af 1069 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 1070 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 1071
sandeepmalladi 0:90cd7e5e24af 1072 }
sandeepmalladi 0:90cd7e5e24af 1073
sandeepmalladi 0:90cd7e5e24af 1074 void ADS1220::set_DRDYM(char c)
sandeepmalladi 0:90cd7e5e24af 1075 {
sandeepmalladi 0:90cd7e5e24af 1076 int drdy = (int) c - 48;
sandeepmalladi 0:90cd7e5e24af 1077 int dERROR;
sandeepmalladi 0:90cd7e5e24af 1078 unsigned Temp;
sandeepmalladi 0:90cd7e5e24af 1079
sandeepmalladi 0:90cd7e5e24af 1080 // the DataRate value is only part of the register, so we have to read it back
sandeepmalladi 0:90cd7e5e24af 1081 // and massage the new value into it
sandeepmalladi 0:90cd7e5e24af 1082 ReadRegister(ADS1220_3_REGISTER, 0x01, &Temp);
sandeepmalladi 0:90cd7e5e24af 1083
sandeepmalladi 0:90cd7e5e24af 1084 Temp &= 0xfd; // strip out old settings
sandeepmalladi 0:90cd7e5e24af 1085 // Change DRDY Mode Setting
sandeepmalladi 0:90cd7e5e24af 1086 switch(drdy) {
sandeepmalladi 0:90cd7e5e24af 1087 case 0:
sandeepmalladi 0:90cd7e5e24af 1088 dERROR = SetDRDYMode(Temp);
sandeepmalladi 0:90cd7e5e24af 1089 break;
sandeepmalladi 0:90cd7e5e24af 1090 case 1:
sandeepmalladi 0:90cd7e5e24af 1091 dERROR = SetDRDYMode(Temp + ADS1220_DRDY_MODE);
sandeepmalladi 0:90cd7e5e24af 1092 break;
sandeepmalladi 0:90cd7e5e24af 1093 default:
sandeepmalladi 0:90cd7e5e24af 1094 dERROR = ADS1220_ERROR;
sandeepmalladi 0:90cd7e5e24af 1095 break;
sandeepmalladi 0:90cd7e5e24af 1096
sandeepmalladi 0:90cd7e5e24af 1097 }
sandeepmalladi 0:90cd7e5e24af 1098
sandeepmalladi 0:90cd7e5e24af 1099 if (dERROR==ADS1220_ERROR)
sandeepmalladi 0:90cd7e5e24af 1100 set_ERROR();
sandeepmalladi 0:90cd7e5e24af 1101
sandeepmalladi 0:90cd7e5e24af 1102 }
sandeepmalladi 0:90cd7e5e24af 1103
sandeepmalladi 0:90cd7e5e24af 1104
sandeepmalladi 0:90cd7e5e24af 1105
sandeepmalladi 0:90cd7e5e24af 1106
sandeepmalladi 0:90cd7e5e24af 1107 void ADS1220::set_ERROR_Transmit(void)
sandeepmalladi 0:90cd7e5e24af 1108 {
sandeepmalladi 0:90cd7e5e24af 1109 /* De-initialize the SPI comunication BUS */
sandeepmalladi 0:90cd7e5e24af 1110 }
sandeepmalladi 0:90cd7e5e24af 1111
sandeepmalladi 0:90cd7e5e24af 1112 void ADS1220::set_ERROR_Receive(void)
sandeepmalladi 0:90cd7e5e24af 1113 {
sandeepmalladi 0:90cd7e5e24af 1114 /* De-initialize the SPI comunication BUS */
sandeepmalladi 0:90cd7e5e24af 1115 // serial.printf("\rSPI Failed during Reception\n\r");
sandeepmalladi 0:90cd7e5e24af 1116 }
sandeepmalladi 0:90cd7e5e24af 1117
sandeepmalladi 0:90cd7e5e24af 1118 void ADS1220::set_ERROR(void)
sandeepmalladi 0:90cd7e5e24af 1119 {
sandeepmalladi 0:90cd7e5e24af 1120 /* De-initialize the SPI comunication BUS */
sandeepmalladi 0:90cd7e5e24af 1121 //serial.printf("\rADS1220 Error\n\r");
sandeepmalladi 0:90cd7e5e24af 1122 }