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