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
- void writeRegister(uint8_t registerAddress, uint8_t registerValueW)
- {
- waitforDRDY(); //waiting for DRDY to go LOW
- 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(0x50 | registerAddress); // 0x50 = WREG, '|' = Bitwise OR operator
- SPI.transfer(0x00);
- delayMicroseconds(7); //see t6 in the datasheet
- SPI.transfer(registerValueW); //Sending the desired value of the register that we write
- //registerValueW is a variable which gets its value from the serial terminal
- delayMicroseconds(7); //see t6 in the datasheet
- digitalWrite(CS_pin, HIGH);
- SPI.endTransaction();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement