Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is the function which reads the value of a selected register
- //The function expects the address of the register and returns with its value
- //The code belongs to the following Youtube tutorial: https://youtu.be/KQ0nWjM-MtI
- //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
- unsigned long readRegister(uint8_t registerAddress) //Function for READING a selected register
- {
- waitforDRDY(); //Waiting for DRDY to go low ('1')
- //this is a separate function that watches the attachinterrupt() pin
- SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1));
- //SPI_MODE1 = output edge: rising, data capture: falling; clock polarity: 0, clock phase: 1.
- digitalWrite(CS_pin, LOW); //CS must stay LOW during the entire sequence [Ref: P34, T24]
- delayMicroseconds(7); //see t6 in the datasheet
- //t6 = 50 * tau_CLKIN = 50 * 130.2 ns = 6510 ns = 6.51 us; you want to round it UP to the next integer (even if it would be 6.1 us)
- SPI.transfer(0x10 | registerAddress); //0x10 = RREG, '|' = bitwise OR operation
- SPI.transfer(0x00);
- delayMicroseconds(7); //see t6 in the datasheet
- registerValueR = SPI.transfer(0xFF); //obtaining the data and 'saving' into the variable
- delayMicroseconds(7); //see t6 in the datasheet
- digitalWrite(CS_pin, HIGH);
- SPI.endTransaction();
- return registerValueR;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement