Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- //Give convenient names to the control pins
- #define slaveAPin 10
- // set up the speed, data order and data mode
- SPISettings settingsA(4000000, MSBFIRST, SPI_MODE1);
- void setup() {
- Serial.begin(9600);
- pinMode(slaveAPin,OUTPUT);
- SPI.begin(slaveAPin);
- }
- uint8_t val1, val2, val3, val4;
- void loop() {
- // read four bytes from device A
- Serial.println(ReadTemp());
- delay(1000);
- }
- uint8_t ReadTemp(void)
- {
- SPI.beginTransaction(settingsA);
- digitalWrite (slaveAPin, LOW);
- // reading only, so data sent does not matter
- val1 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
- val2 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
- val3 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
- val4 = SPI.transfer(slaveAPin,0x00,SPI_LAST);
- digitalWrite (slaveAPin, HIGH);
- SPI.endTransaction();
- return val2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement