Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <SPI.h>
  2. //Give convenient names to the control pins
  3.  
  4. #define slaveAPin 10
  5. // set up the speed, data order and data mode
  6. SPISettings settingsA(4000000, MSBFIRST, SPI_MODE1);
  7.  
  8. void setup() {
  9.  
  10. Serial.begin(9600);
  11. pinMode(slaveAPin,OUTPUT);
  12. SPI.begin(slaveAPin);
  13.  
  14. }
  15.  
  16. uint8_t val1, val2, val3, val4;
  17.  
  18. void loop() {
  19. // read four bytes from device A
  20. Serial.println(ReadTemp());
  21. delay(1000);
  22.  
  23.  
  24. }
  25.  
  26. uint8_t ReadTemp(void)
  27. {
  28. SPI.beginTransaction(settingsA);
  29. digitalWrite (slaveAPin, LOW);
  30. // reading only, so data sent does not matter
  31. val1 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  32. val2 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  33. val3 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  34. val4 = SPI.transfer(slaveAPin,0x00,SPI_LAST);
  35. digitalWrite (slaveAPin, HIGH);
  36. SPI.endTransaction();
  37.  
  38. return val2;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement