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