Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ADS1299.cpp@0:675506e540be, 2015-03-23 (annotated)
- Committer:
- biomurph
- Date:
- Mon Mar 23 19:22:04 2015 +0000
- Revision:
- 0:675506e540be
Publishing this old ADS1299 code for the first time!
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| biomurph | 0:675506e540be | 1 | // |
| biomurph | 0:675506e540be | 2 | // ADS1299.cpp mbed LIBRARY FOR COMMUNICATING WITH ADS1299 |
| biomurph | 0:675506e540be | 3 | // |
| biomurph | 0:675506e540be | 4 | // Created by Joel Murphy. Fall, 2013 Ported from Arduino library by Conor, Joel, and Luke, Summer 2013 |
| biomurph | 0:675506e540be | 5 | // |
| biomurph | 0:675506e540be | 6 | |
| biomurph | 0:675506e540be | 7 | |
| biomurph | 0:675506e540be | 8 | #include "ADS1299.h" |
| biomurph | 0:675506e540be | 9 | |
| biomurph | 0:675506e540be | 10 | void ADS1299::initialize(){ |
| biomurph | 0:675506e540be | 11 | DRDY = _DRDY; |
| biomurph | 0:675506e540be | 12 | CS = _CS; |
| biomurph | 0:675506e540be | 13 | int FREQ = _FREQ; |
| biomurph | 0:675506e540be | 14 | int RST = _RST; |
| biomurph | 0:675506e540be | 15 | DigitalOut CS (PTD0); // arduino pin 10 - chip select |
| biomurph | 0:675506e540be | 16 | DigitalOut RST(PTD5); // arduino pin 9 - reset pin |
| biomurph | 0:675506e540be | 17 | DigitalIn DRDY(PTA13); // arduino pin 8 - data ready pin |
| biomurph | 0:675506e540be | 18 | |
| biomurph | 0:675506e540be | 19 | delay(50); // recommended power up sequence requiers Tpor (~32mS) |
| biomurph | 0:675506e540be | 20 | pinMode(RST,OUTPUT); |
| biomurph | 0:675506e540be | 21 | wait_ms(50); // wait Tpor |
| biomurph | 0:675506e540be | 22 | RST = 0; // put the ADS into reset mode |
| biomurph | 0:675506e540be | 23 | wait_us(8); // wait Trst |
| biomurph | 0:675506e540be | 24 | RST = 1; // take ADS out of reset mode |
| biomurph | 0:675506e540be | 25 | wait_us(20); // advertised to wait 18 Tclk before operation |
| biomurph | 0:675506e540be | 26 | |
| biomurph | 0:675506e540be | 27 | |
| biomurph | 0:675506e540be | 28 | |
| biomurph | 0:675506e540be | 29 | } |
| biomurph | 0:675506e540be | 30 | |
| biomurph | 0:675506e540be | 31 | //System Commands |
| biomurph | 0:675506e540be | 32 | void ADS1299::WAKEUP() { |
| biomurph | 0:675506e540be | 33 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 34 | transfer(_WAKEUP); |
| biomurph | 0:675506e540be | 35 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 36 | delayMicroseconds(3); //must wait 4 tCLK cycles before sending another command (Datasheet, pg. 35) |
| biomurph | 0:675506e540be | 37 | } |
| biomurph | 0:675506e540be | 38 | |
| biomurph | 0:675506e540be | 39 | void ADS1299::STANDBY() { // only allowed to send WAKEUP after sending STANDBY |
| biomurph | 0:675506e540be | 40 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 41 | transfer(_STANDBY); |
| biomurph | 0:675506e540be | 42 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 43 | } |
| biomurph | 0:675506e540be | 44 | |
| biomurph | 0:675506e540be | 45 | void ADS1299::RESET() { // reset all the registers to default settings |
| biomurph | 0:675506e540be | 46 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 47 | transfer(_RESET); |
| biomurph | 0:675506e540be | 48 | delayMicroseconds(12); //must wait 18 tCLK cycles to execute this command (Datasheet, pg. 35) |
| biomurph | 0:675506e540be | 49 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 50 | } |
| biomurph | 0:675506e540be | 51 | |
| biomurph | 0:675506e540be | 52 | void ADS1299::START() { //start data conversion |
| biomurph | 0:675506e540be | 53 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 54 | transfer(_START); |
| biomurph | 0:675506e540be | 55 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 56 | } |
| biomurph | 0:675506e540be | 57 | |
| biomurph | 0:675506e540be | 58 | void ADS1299::STOP() { //stop data conversion |
| biomurph | 0:675506e540be | 59 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 60 | transfer(_STOP); |
| biomurph | 0:675506e540be | 61 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 62 | } |
| biomurph | 0:675506e540be | 63 | |
| biomurph | 0:675506e540be | 64 | void ADS1299::RDATAC() { |
| biomurph | 0:675506e540be | 65 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 66 | transfer(_RDATAC); |
| biomurph | 0:675506e540be | 67 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 68 | delayMicroseconds(3); |
| biomurph | 0:675506e540be | 69 | } |
| biomurph | 0:675506e540be | 70 | void ADS1299::SDATAC() { |
| biomurph | 0:675506e540be | 71 | digitalWrite(CS, LOW); |
| biomurph | 0:675506e540be | 72 | transfer(_SDATAC); |
| biomurph | 0:675506e540be | 73 | digitalWrite(CS, HIGH); |
| biomurph | 0:675506e540be | 74 | delayMicroseconds(3); //must wait 4 tCLK cycles after executing this command (Datasheet, pg. 37) |
| biomurph | 0:675506e540be | 75 | } |
| biomurph | 0:675506e540be | 76 | |
| biomurph | 0:675506e540be | 77 | |
| biomurph | 0:675506e540be | 78 | // Register Read/Write Commands |
| biomurph | 0:675506e540be | 79 | byte ADS1299::getDeviceID() { // simple hello world com check |
| biomurph | 0:675506e540be | 80 | byte data = RREG(0x00); |
| biomurph | 0:675506e540be | 81 | if(verbose){ // verbose otuput |
| biomurph | 0:675506e540be | 82 | Serial.print(F("Device ID ")); |
| biomurph | 0:675506e540be | 83 | printHex(data); |
| biomurph | 0:675506e540be | 84 | } |
| biomurph | 0:675506e540be | 85 | return data; |
| biomurph | 0:675506e540be | 86 | } |
| biomurph | 0:675506e540be | 87 | |
| biomurph | 0:675506e540be | 88 | byte ADS1299::RREG(byte _address) { // reads ONE register at _address |
| biomurph | 0:675506e540be | 89 | byte opcode1 = _address + 0x20; // RREG expects 001rrrrr where rrrrr = _address |
| biomurph | 0:675506e540be | 90 | digitalWrite(CS, LOW); // open SPI |
| biomurph | 0:675506e540be | 91 | transfer(opcode1); // opcode1 |
| biomurph | 0:675506e540be | 92 | transfer(0x00); // opcode2 |
| biomurph | 0:675506e540be | 93 | regData[_address] = transfer(0x00);// update mirror location with returned byte |
| biomurph | 0:675506e540be | 94 | digitalWrite(CS, HIGH); // close SPI |
| biomurph | 0:675506e540be | 95 | if (verbose){ // verbose output |
| biomurph | 0:675506e540be | 96 | printRegisterName(_address); |
| biomurph | 0:675506e540be | 97 | printHex(_address); |
| biomurph | 0:675506e540be | 98 | Serial.print(", "); |
| biomurph | 0:675506e540be | 99 | printHex(regData[_address]); |
| biomurph | 0:675506e540be | 100 | Serial.print(", "); |
| biomurph | 0:675506e540be | 101 | for(byte j = 0; j<8; j++){ |
| biomurph | 0:675506e540be | 102 | Serial.print(bitRead(regData[_address], 7-j)); |
| biomurph | 0:675506e540be | 103 | if(j!=7) Serial.print(", "); |
| biomurph | 0:675506e540be | 104 | } |
| biomurph | 0:675506e540be | 105 | |
| biomurph | 0:675506e540be | 106 | Serial.println(); |
| biomurph | 0:675506e540be | 107 | } |
| biomurph | 0:675506e540be | 108 | return regData[_address]; // return requested register value |
| biomurph | 0:675506e540be | 109 | } |
| biomurph | 0:675506e540be | 110 | |
| biomurph | 0:675506e540be | 111 | // Read more than one register starting at _address |
| biomurph | 0:675506e540be | 112 | void ADS1299::RREGS(byte _address, byte _numRegistersMinusOne) { |
| biomurph | 0:675506e540be | 113 | // for(byte i = 0; i < 0x17; i++){ |
| biomurph | 0:675506e540be | 114 | // regData[i] = 0; // reset the regData array |
| biomurph | 0:675506e540be | 115 | // } |
| biomurph | 0:675506e540be | 116 | byte opcode1 = _address + 0x20; // RREG expects 001rrrrr where rrrrr = _address |
| biomurph | 0:675506e540be | 117 | digitalWrite(CS, LOW); // open SPI |
| biomurph | 0:675506e540be | 118 | transfer(opcode1); // opcode1 |
| biomurph | 0:675506e540be | 119 | transfer(_numRegistersMinusOne); // opcode2 |
| biomurph | 0:675506e540be | 120 | for(int i = 0; i <= _numRegistersMinusOne; i++){ |
| biomurph | 0:675506e540be | 121 | regData[_address + i] = transfer(0x00); // add register byte to mirror array |
| biomurph | 0:675506e540be | 122 | } |
| biomurph | 0:675506e540be | 123 | digitalWrite(CS, HIGH); // close SPI |
| biomurph | 0:675506e540be | 124 | if(verbose){ // verbose output |
| biomurph | 0:675506e540be | 125 | for(int i = 0; i<= _numRegistersMinusOne; i++){ |
| biomurph | 0:675506e540be | 126 | printRegisterName(_address + i); |
| biomurph | 0:675506e540be | 127 | printHex(_address + i); |
| biomurph | 0:675506e540be | 128 | Serial.print(", "); |
| biomurph | 0:675506e540be | 129 | printHex(regData[_address + i]); |
| biomurph | 0:675506e540be | 130 | Serial.print(", "); |
| biomurph | 0:675506e540be | 131 | for(int j = 0; j<8; j++){ |
| biomurph | 0:675506e540be | 132 | Serial.print(bitRead(regData[_address + i], 7-j)); |
| biomurph | 0:675506e540be | 133 | if(j!=7) Serial.print(", "); |
| biomurph | 0:675506e540be | 134 | } |
| biomurph | 0:675506e540be | 135 | Serial.println(); |
| biomurph | 0:675506e540be | 136 | } |
| biomurph | 0:675506e540be | 137 | } |
| biomurph | 0:675506e540be | 138 | |
| biomurph | 0:675506e540be | 139 | } |
| biomurph | 0:675506e540be | 140 | |
| biomurph | 0:675506e540be | 141 | void ADS1299::WREG(byte _address, byte _value) { // Write ONE register at _address |
| biomurph | 0:675506e540be | 142 | byte opcode1 = _address + 0x40; // WREG expects 010rrrrr where rrrrr = _address |
| biomurph | 0:675506e540be | 143 | digitalWrite(CS, LOW); // open SPI |
| biomurph | 0:675506e540be | 144 | transfer(opcode1); // Send WREG command & address |
| biomurph | 0:675506e540be | 145 | transfer(0x00); // Send number of registers to read -1 |
| biomurph | 0:675506e540be | 146 | transfer(_value); // Write the value to the register |
| biomurph | 0:675506e540be | 147 | digitalWrite(CS, HIGH); // close SPI |
| biomurph | 0:675506e540be | 148 | regData[_address] = _value; // update the mirror array |
| biomurph | 0:675506e540be | 149 | if(verbose){ // verbose output |
| biomurph | 0:675506e540be | 150 | Serial.print(F("Register ")); |
| biomurph | 0:675506e540be | 151 | printHex(_address); |
| biomurph | 0:675506e540be | 152 | Serial.println(F(" modified.")); |
| biomurph | 0:675506e540be | 153 | } |
| biomurph | 0:675506e540be | 154 | } |
| biomurph | 0:675506e540be | 155 | |
| biomurph | 0:675506e540be | 156 | void ADS1299::WREGS(byte _address, byte _numRegistersMinusOne) { |
| biomurph | 0:675506e540be | 157 | byte opcode1 = _address + 0x40; // WREG expects 010rrrrr where rrrrr = _address |
| biomurph | 0:675506e540be | 158 | digitalWrite(CS, LOW); // open SPI |
| biomurph | 0:675506e540be | 159 | transfer(opcode1); // Send WREG command & address |
| biomurph | 0:675506e540be | 160 | transfer(_numRegistersMinusOne); // Send number of registers to read -1 |
| biomurph | 0:675506e540be | 161 | for (int i=_address; i <=(_address + _numRegistersMinusOne); i++){ |
| biomurph | 0:675506e540be | 162 | transfer(regData[i]); // Write to the registers |
| biomurph | 0:675506e540be | 163 | } |
| biomurph | 0:675506e540be | 164 | digitalWrite(CS,HIGH); // close SPI |
| biomurph | 0:675506e540be | 165 | if(verbose){ |
| biomurph | 0:675506e540be | 166 | Serial.print(F("Registers ")); |
| biomurph | 0:675506e540be | 167 | printHex(_address); Serial.print(F(" to ")); |
| biomurph | 0:675506e540be | 168 | printHex(_address + _numRegistersMinusOne); |
| biomurph | 0:675506e540be | 169 | Serial.println(F(" modified")); |
| biomurph | 0:675506e540be | 170 | } |
| biomurph | 0:675506e540be | 171 | } |
| biomurph | 0:675506e540be | 172 | |
| biomurph | 0:675506e540be | 173 | |
| biomurph | 0:675506e540be | 174 | void ADS1299::updateChannelData(){ |
| biomurph | 0:675506e540be | 175 | byte inByte; |
| biomurph | 0:675506e540be | 176 | digitalWrite(CS, LOW); // open SPI |
| biomurph | 0:675506e540be | 177 | stat = transfer(0x00); // read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4]) |
| biomurph | 0:675506e540be | 178 | stat = transfer(0x00); // read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4]) |
| biomurph | 0:675506e540be | 179 | stat = transfer(0x00); // read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4]) |
| biomurph | 0:675506e540be | 180 | for(int i = 0; i<8; i++){ |
| biomurph | 0:675506e540be | 181 | for(int j=0; j<3; j++){ // read 24 bits of channel data in 8 3 byte chunks |
| biomurph | 0:675506e540be | 182 | inByte = transfer(0x00); |
| biomurph | 0:675506e540be | 183 | channelData[i] = (channelData[i]<<8) | inByte; |
| biomurph | 0:675506e540be | 184 | } |
| biomurph | 0:675506e540be | 185 | } |
| biomurph | 0:675506e540be | 186 | digitalWrite(CS, HIGH); // close SPI |
| biomurph | 0:675506e540be | 187 | |
| biomurph | 0:675506e540be | 188 | for(int i=0; i<8; i++){ // convert 3 byte 2's compliment to 4 byte 2's compliment |
| biomurph | 0:675506e540be | 189 | if(bitRead(channelData[i],23) == 1){ |
| biomurph | 0:675506e540be | 190 | channelData[i] |= 0xFF000000; |
| biomurph | 0:675506e540be | 191 | }else{ |
| biomurph | 0:675506e540be | 192 | channelData[i] &= 0x00FFFFFF; |
| biomurph | 0:675506e540be | 193 | } |
| biomurph | 0:675506e540be | 194 | } |
| biomurph | 0:675506e540be | 195 | // if(verbose){ |
| biomurph | 0:675506e540be | 196 | // Serial.print(stat); Serial.print(", "); |
| biomurph | 0:675506e540be | 197 | // for(int i=0; i<8; i++){ |
| biomurph | 0:675506e540be | 198 | // Serial.print(channelData[i]); |
| biomurph | 0:675506e540be | 199 | // if(i<7){Serial.print(", ");} |
| biomurph | 0:675506e540be | 200 | // } |
| biomurph | 0:675506e540be | 201 | // Serial.println(); |
| biomurph | 0:675506e540be | 202 | // } |
| biomurph | 0:675506e540be | 203 | } |
| biomurph | 0:675506e540be | 204 | |
| biomurph | 0:675506e540be | 205 | |
| biomurph | 0:675506e540be | 206 | |
| biomurph | 0:675506e540be | 207 | |
| biomurph | 0:675506e540be | 208 | void ADS1299::RDATA() { // use in Stop Read Continuous mode when DRDY goes low |
| biomurph | 0:675506e540be | 209 | byte inByte; // to read in one sample of the channels |
| biomurph | 0:675506e540be | 210 | digitalWrite(CS, LOW); // open SPI |
| biomurph | 0:675506e540be | 211 | transfer(_RDATA); // send the RDATA command |
| biomurph | 0:675506e540be | 212 | stat = transfer(0x00); // read status register (1100 + LOFF_STATP + LOFF_STATN + GPIO[7:4]) |
| biomurph | 0:675506e540be | 213 | for(int i = 0; i<8; i++){ |
| biomurph | 0:675506e540be | 214 | for(int j=0; j<3; j++){ // read in the status register and new channel data |
| biomurph | 0:675506e540be | 215 | inByte = transfer(0x00); |
| biomurph | 0:675506e540be | 216 | channelData[i] = (channelData[i]<<8) | inByte; |
| biomurph | 0:675506e540be | 217 | } |
| biomurph | 0:675506e540be | 218 | } |
| biomurph | 0:675506e540be | 219 | digitalWrite(CS, HIGH); // close SPI |
| biomurph | 0:675506e540be | 220 | |
| biomurph | 0:675506e540be | 221 | for(int i=0; i<8; i++){ |
| biomurph | 0:675506e540be | 222 | if(bitRead(channelData[i],23) == 1){ // convert 3 byte 2's compliment to 4 byte 2's compliment |
| biomurph | 0:675506e540be | 223 | channelData[i] |= 0xFF000000; |
| biomurph | 0:675506e540be | 224 | }else{ |
| biomurph | 0:675506e540be | 225 | channelData[i] &= 0x00FFFFFF; |
| biomurph | 0:675506e540be | 226 | } |
| biomurph | 0:675506e540be | 227 | } |
| biomurph | 0:675506e540be | 228 | |
| biomurph | 0:675506e540be | 229 | } |
| biomurph | 0:675506e540be | 230 | |
| biomurph | 0:675506e540be | 231 | |
| biomurph | 0:675506e540be | 232 | // String-Byte converters for RREG and WREG |
| biomurph | 0:675506e540be | 233 | void ADS1299::printRegisterName(byte _address) { |
| biomurph | 0:675506e540be | 234 | if(_address == ID){ |
| biomurph | 0:675506e540be | 235 | Serial.print(F("ID, ")); //the "F" macro loads the string directly from Flash memory, thereby saving RAM |
| biomurph | 0:675506e540be | 236 | } |
| biomurph | 0:675506e540be | 237 | else if(_address == CONFIG1){ |
| biomurph | 0:675506e540be | 238 | Serial.print(F("CONFIG1, ")); |
| biomurph | 0:675506e540be | 239 | } |
| biomurph | 0:675506e540be | 240 | else if(_address == CONFIG2){ |
| biomurph | 0:675506e540be | 241 | Serial.print(F("CONFIG2, ")); |
| biomurph | 0:675506e540be | 242 | } |
| biomurph | 0:675506e540be | 243 | else if(_address == CONFIG3){ |
| biomurph | 0:675506e540be | 244 | Serial.print(F("CONFIG3, ")); |
| biomurph | 0:675506e540be | 245 | } |
| biomurph | 0:675506e540be | 246 | else if(_address == LOFF){ |
| biomurph | 0:675506e540be | 247 | Serial.print(F("LOFF, ")); |
| biomurph | 0:675506e540be | 248 | } |
| biomurph | 0:675506e540be | 249 | else if(_address == CH1SET){ |
| biomurph | 0:675506e540be | 250 | Serial.print(F("CH1SET, ")); |
| biomurph | 0:675506e540be | 251 | } |
| biomurph | 0:675506e540be | 252 | else if(_address == CH2SET){ |
| biomurph | 0:675506e540be | 253 | Serial.print(F("CH2SET, ")); |
| biomurph | 0:675506e540be | 254 | } |
| biomurph | 0:675506e540be | 255 | else if(_address == CH3SET){ |
| biomurph | 0:675506e540be | 256 | Serial.print(F("CH3SET, ")); |
| biomurph | 0:675506e540be | 257 | } |
| biomurph | 0:675506e540be | 258 | else if(_address == CH4SET){ |
| biomurph | 0:675506e540be | 259 | Serial.print(F("CH4SET, ")); |
| biomurph | 0:675506e540be | 260 | } |
| biomurph | 0:675506e540be | 261 | else if(_address == CH5SET){ |
| biomurph | 0:675506e540be | 262 | Serial.print(F("CH5SET, ")); |
| biomurph | 0:675506e540be | 263 | } |
| biomurph | 0:675506e540be | 264 | else if(_address == CH6SET){ |
| biomurph | 0:675506e540be | 265 | Serial.print(F("CH6SET, ")); |
| biomurph | 0:675506e540be | 266 | } |
| biomurph | 0:675506e540be | 267 | else if(_address == CH7SET){ |
| biomurph | 0:675506e540be | 268 | Serial.print(F("CH7SET, ")); |
| biomurph | 0:675506e540be | 269 | } |
| biomurph | 0:675506e540be | 270 | else if(_address == CH8SET){ |
| biomurph | 0:675506e540be | 271 | Serial.print(F("CH8SET, ")); |
| biomurph | 0:675506e540be | 272 | } |
| biomurph | 0:675506e540be | 273 | else if(_address == BIAS_SENSP){ |
| biomurph | 0:675506e540be | 274 | Serial.print(F("BIAS_SENSP, ")); |
| biomurph | 0:675506e540be | 275 | } |
| biomurph | 0:675506e540be | 276 | else if(_address == BIAS_SENSN){ |
| biomurph | 0:675506e540be | 277 | Serial.print(F("BIAS_SENSN, ")); |
| biomurph | 0:675506e540be | 278 | } |
| biomurph | 0:675506e540be | 279 | else if(_address == LOFF_SENSP){ |
| biomurph | 0:675506e540be | 280 | Serial.print(F("LOFF_SENSP, ")); |
| biomurph | 0:675506e540be | 281 | } |
| biomurph | 0:675506e540be | 282 | else if(_address == LOFF_SENSN){ |
| biomurph | 0:675506e540be | 283 | Serial.print(F("LOFF_SENSN, ")); |
| biomurph | 0:675506e540be | 284 | } |
| biomurph | 0:675506e540be | 285 | else if(_address == LOFF_FLIP){ |
| biomurph | 0:675506e540be | 286 | Serial.print(F("LOFF_FLIP, ")); |
| biomurph | 0:675506e540be | 287 | } |
| biomurph | 0:675506e540be | 288 | else if(_address == LOFF_STATP){ |
| biomurph | 0:675506e540be | 289 | Serial.print(F("LOFF_STATP, ")); |
| biomurph | 0:675506e540be | 290 | } |
| biomurph | 0:675506e540be | 291 | else if(_address == LOFF_STATN){ |
| biomurph | 0:675506e540be | 292 | Serial.print(F("LOFF_STATN, ")); |
| biomurph | 0:675506e540be | 293 | } |
| biomurph | 0:675506e540be | 294 | else if(_address == GPIO){ |
| biomurph | 0:675506e540be | 295 | Serial.print(F("GPIO, ")); |
| biomurph | 0:675506e540be | 296 | } |
| biomurph | 0:675506e540be | 297 | else if(_address == MISC1){ |
| biomurph | 0:675506e540be | 298 | Serial.print(F("MISC1, ")); |
| biomurph | 0:675506e540be | 299 | } |
| biomurph | 0:675506e540be | 300 | else if(_address == MISC2){ |
| biomurph | 0:675506e540be | 301 | Serial.print(F("MISC2, ")); |
| biomurph | 0:675506e540be | 302 | } |
| biomurph | 0:675506e540be | 303 | else if(_address == CONFIG4){ |
| biomurph | 0:675506e540be | 304 | Serial.print(F("CONFIG4, ")); |
| biomurph | 0:675506e540be | 305 | } |
| biomurph | 0:675506e540be | 306 | } |
| biomurph | 0:675506e540be | 307 | |
| biomurph | 0:675506e540be | 308 | //SPI communication methods |
| biomurph | 0:675506e540be | 309 | byte ADS1299::transfer(byte _data) { |
| biomurph | 0:675506e540be | 310 | cli(); |
| biomurph | 0:675506e540be | 311 | SPDR = _data; |
| biomurph | 0:675506e540be | 312 | while (!(SPSR & _BV(SPIF))) |
| biomurph | 0:675506e540be | 313 | ; |
| biomurph | 0:675506e540be | 314 | sei(); |
| biomurph | 0:675506e540be | 315 | return SPDR; |
| biomurph | 0:675506e540be | 316 | } |
| biomurph | 0:675506e540be | 317 | |
| biomurph | 0:675506e540be | 318 | // Used for printing HEX in verbose feedback mode |
| biomurph | 0:675506e540be | 319 | void ADS1299::printHex(byte _data){ |
| biomurph | 0:675506e540be | 320 | Serial.print("0x"); |
| biomurph | 0:675506e540be | 321 | if(_data < 0x10) Serial.print("0"); |
| biomurph | 0:675506e540be | 322 | Serial.print(_data, HEX); |
| biomurph | 0:675506e540be | 323 | } |
| biomurph | 0:675506e540be | 324 | |
| biomurph | 0:675506e540be | 325 | //-------------------------------------------------------------------// |
| biomurph | 0:675506e540be | 326 | //-------------------------------------------------------------------// |
| biomurph | 0:675506e540be | 327 | //-------------------------------------------------------------------// |
| biomurph | 0:675506e540be | 328 | |
| biomurph | 0:675506e540be | 329 | |
| biomurph | 0:675506e540be | 330 |