Skip to content

Commit d5c8287

Browse files
committed
Revert "SPI library to new format"
1 parent ff24874 commit d5c8287

File tree

13 files changed

+81
-57
lines changed

13 files changed

+81
-57
lines changed

libraries/SPI/arch/avr/SPI.cpp renamed to hardware/arduino/avr/libraries/SPI/SPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
#include "pins_arduino.h"
12-
#include "SPI_Class.h"
12+
#include "SPI.h"
1313

1414
SPIClass SPI;
1515

libraries/SPI/arch/sam/SPI.cpp renamed to hardware/arduino/sam/libraries/SPI/SPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* published by the Free Software Foundation.
99
*/
1010

11-
#include "SPI_Class.h"
11+
#include "SPI.h"
1212

1313
SPIClass::SPIClass(Spi *_spi, uint32_t _id, void(*_initCb)(void)) :
1414
spi(_spi), id(_id), initCb(_initCb), initialized(false)
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
SCP1000 Barometric Pressure Sensor Display
2+
SCP1000 Barometric Pressure Sensor Display
33
44
Shows the output of a Barometric Pressure Sensor on a
55
Uses the SPI library. For details on the sensor, see:
@@ -29,8 +29,9 @@
2929
const int PRESSURE = 0x1F; //3 most significant bits of pressure
3030
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
3131
const int TEMPERATURE = 0x21; //16 bit temperature reading
32-
cont byte READ = 0b00000000; // SCP1000's read command
32+
const byte READ = 0b11111100; // SCP1000's read command
3333
const byte WRITE = 0b00000010; // SCP1000's write command
34+
3435
// pins used for the connection with the sensor
3536
// the other you need are controlled by the SPI library):
3637
const int dataReadyPin = 6;
@@ -87,13 +88,14 @@ void loop() {
8788
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
8889
byte inByte = 0; // incoming byte from the SPI
8990
unsigned int result = 0; // result to return
90-
91+
Serial.print(thisRegister, BIN);
92+
Serial.print("\t");
9193
// SCP1000 expects the register name in the upper 6 bits
9294
// of the byte. So shift the bits left by two bits:
9395
thisRegister = thisRegister << 2;
9496
// now combine the address and the command into one byte
95-
dataToSend = thisRegister & READ;
96-
97+
byte dataToSend = thisRegister & READ;
98+
Serial.println(thisRegister, BIN);
9799
// take the chip select low to select the device:
98100
digitalWrite(chipSelectPin, LOW);
99101
// send the device the register you want to read:
@@ -127,7 +129,7 @@ void writeRegister(byte thisRegister, byte thisValue) {
127129
// of the byte. So shift the bits left by two bits:
128130
thisRegister = thisRegister << 2;
129131
// now combine the register address and the command into one byte:
130-
dataToSend = thisRegister | WRITE;
132+
byte dataToSend = thisRegister | WRITE;
131133

132134
// take the chip select low to select the device:
133135
digitalWrite(chipSelectPin, LOW);
@@ -139,5 +141,3 @@ void writeRegister(byte thisRegister, byte thisValue) {
139141
digitalWrite(chipSelectPin, HIGH);
140142
}
141143

142-
143-
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Digital Pot Control
3+
4+
This example controls an Analog Devices AD5206 digital potentiometer.
5+
The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
6+
A - connect this to voltage
7+
W - this is the pot's wiper, which changes when you set it
8+
B - connect this to ground.
9+
10+
The AD5206 is SPI-compatible,and to command it, you send two bytes,
11+
one with the channel number (0 - 5) and one with the resistance value for the
12+
channel (0 - 255).
13+
14+
The circuit:
15+
* All A pins of AD5206 connected to +5V
16+
* All B pins of AD5206 connected to ground
17+
* An LED and a 220-ohm resisor in series connected from each W pin to ground
18+
* CS - to digital pin 10 (SS pin)
19+
* SDI - to digital pin 11 (MOSI pin)
20+
* CLK - to digital pin 13 (SCK pin)
21+
22+
created 10 Aug 2010
23+
by Tom Igoe
24+
25+
Thanks to Heather Dewey-Hagborg for the original tutorial, 2005
26+
27+
*/
28+
29+
30+
// inslude the SPI library:
31+
#include <SPI.h>
32+
33+
34+
// set pin 10 as the slave select for the digital pot:
35+
const int slaveSelectPin = 10;
36+
37+
void setup() {
38+
// set the slaveSelectPin as an output:
39+
pinMode (slaveSelectPin, OUTPUT);
40+
// initialize SPI:
41+
SPI.begin();
42+
}
43+
44+
void loop() {
45+
// go through the six channels of the digital pot:
46+
for (int channel = 0; channel < 6; channel++) {
47+
// change the resistance on this channel from min to max:
48+
for (int level = 0; level < 255; level++) {
49+
digitalPotWrite(channel, level);
50+
delay(10);
51+
}
52+
// wait a second at the top:
53+
delay(100);
54+
// change the resistance on this channel from max to min:
55+
for (int level = 0; level < 255; level++) {
56+
digitalPotWrite(channel, 255 - level);
57+
delay(10);
58+
}
59+
}
60+
61+
}
62+
63+
void digitalPotWrite(int address, int value) {
64+
// take the SS pin low to select the chip:
65+
digitalWrite(slaveSelectPin, LOW);
66+
// send in the address and value via SPI:
67+
SPI.transfer(address);
68+
SPI.transfer(value);
69+
// take the SS pin high to de-select the chip:
70+
digitalWrite(slaveSelectPin, HIGH);
71+
}

0 commit comments

Comments
 (0)