Advertisement
CuriousScientist

ADS1256 RDATAC code snippet

Feb 9th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is the function which gets a single conversion result from a chosen input.
  2. //The code belongs to the following Youtube tutorial: https://youtu.be/GBWJdyjRIdM
  3. //If you used the code, please SUBSCRIBE: https://www.youtube.com/c/CuriousScientist
  4. /*
  5. If you want to buy the parts and support me at the same time, please use the following affiliation links:
  6. Arduino UNO: https://www.banggood.com/custlink/33KKF85c3i
  7. Arduino Nano with expansion board: https://www.banggood.com/custlink/vDGD9KnOHl
  8. ADS1256 Board (green): https://www.banggood.com/custlink/Dmv3VZHrDC
  9. ADS1256 Board (blue): https://www.banggood.com/custlink/KKv3bkIZNg
  10. ADS1256 Board with built in connectors (black): https://www.banggood.com/custlink/mm3DnqZIQO
  11. */
  12. //Datasheet: http://www.ti.com/lit/ds/sbas288k/sbas288k.pdf
  13.  
  14. void readSingleContinuous()
  15. {
  16.   //Some commands should only be initiated in the beginning of this type of acquisition (RDATAC)
  17.   //Therefore, we run them outside the while().        
  18.     SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1));
  19.     digitalWrite(CS_pin, LOW); //REF: P34: "CS must stay low during the entire command sequence"
  20.  
  21.     waitforDRDY();//Wait for DRDY to go LOW
  22.     SPI.transfer(B00000011);  //Issue RDATAC (0000 0011) command
  23.     delayMicroseconds(7);    //Wait t6 time (~6.51 us) REF: P34, FIG:30.
  24.    
  25.     while (Serial.read() != 's')
  26.     {
  27.     registerData = 0; // every time we call this function, this should be 0 in the beginning!
  28.     waitforDRDY();
  29.        
  30.     //Previously, we used 0x0F, here we use 0 for the SPI.transfer() argument;
  31.     registerData |= SPI.transfer(0); //MSB comes in, first 8 bit is updated
  32.     registerData <<= 8;                 //MSB gets shifted LEFT by 8 bits
  33.     registerData |= SPI.transfer(0); //MSB | Mid-byte
  34.     registerData <<= 8;                 //MSB | Mid-byte gets shifted LEFT by 8 bits
  35.     registerData |= SPI.transfer(0); //(MSB | Mid-byte) | LSB - final result
  36.        
  37.     Serial.println(registerData);  
  38.     }
  39.     digitalWrite(CS_pin, HIGH); //We finished the command sequence, so we switch it back to HIGH
  40.     SPI.endTransaction();   //Close SPI
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement