mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Renaming SPI.send() to SPI.transfer() to better reflect its bi-directional nature.
This commit is contained in:
parent
05e8d675cd
commit
3899ffc75d
@ -183,8 +183,8 @@ void writeRegister(byte registerName, byte registerValue) {
|
|||||||
// take the chip select low to select the device:
|
// take the chip select low to select the device:
|
||||||
digitalWrite(chipSelectPin, LOW);
|
digitalWrite(chipSelectPin, LOW);
|
||||||
|
|
||||||
SPI.send(registerName); //Send register location
|
SPI.transfer(registerName); //Send register location
|
||||||
SPI.send(registerValue); //Send value to record into register
|
SPI.transfer(registerValue); //Send value to record into register
|
||||||
|
|
||||||
// take the chip select high to de-select:
|
// take the chip select high to de-select:
|
||||||
digitalWrite(chipSelectPin, HIGH);
|
digitalWrite(chipSelectPin, HIGH);
|
||||||
@ -205,16 +205,16 @@ unsigned int readRegister(byte registerName, int numBytes) {
|
|||||||
// take the chip select low to select the device:
|
// take the chip select low to select the device:
|
||||||
digitalWrite(chipSelectPin, LOW);
|
digitalWrite(chipSelectPin, LOW);
|
||||||
// send the device the register you want to read:
|
// send the device the register you want to read:
|
||||||
int command = SPI.send(registerName);
|
int command = SPI.transfer(registerName);
|
||||||
// send a value of 0 to read the first byte returned:
|
// send a value of 0 to read the first byte returned:
|
||||||
inByte = SPI.send(0x00);
|
inByte = SPI.transfer(0x00);
|
||||||
|
|
||||||
result = inByte;
|
result = inByte;
|
||||||
// if there's more than one byte returned,
|
// if there's more than one byte returned,
|
||||||
// shift the first byte then get the second byte:
|
// shift the first byte then get the second byte:
|
||||||
if (numBytes > 1){
|
if (numBytes > 1){
|
||||||
result = inByte << 8;
|
result = inByte << 8;
|
||||||
inByte = SPI.send(0x00);
|
inByte = SPI.transfer(0x00);
|
||||||
result = result |inByte;
|
result = result |inByte;
|
||||||
}
|
}
|
||||||
// take the chip select high to de-select:
|
// take the chip select high to de-select:
|
||||||
|
@ -118,10 +118,10 @@ void W5100Class::read_data(SOCKET s, volatile uint8_t *src, volatile uint8_t *ds
|
|||||||
uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
|
uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
|
||||||
{
|
{
|
||||||
setSS();
|
setSS();
|
||||||
SPI.send(0xF0);
|
SPI.transfer(0xF0);
|
||||||
SPI.send(_addr >> 8);
|
SPI.transfer(_addr >> 8);
|
||||||
SPI.send(_addr & 0xFF);
|
SPI.transfer(_addr & 0xFF);
|
||||||
SPI.send(_data);
|
SPI.transfer(_data);
|
||||||
resetSS();
|
resetSS();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -131,11 +131,11 @@ uint16_t W5100Class::write(uint16_t _addr, uint8_t *_buf, uint16_t _len)
|
|||||||
for (int i=0; i<_len; i++)
|
for (int i=0; i<_len; i++)
|
||||||
{
|
{
|
||||||
setSS();
|
setSS();
|
||||||
SPI.send(0xF0);
|
SPI.transfer(0xF0);
|
||||||
SPI.send(_addr >> 8);
|
SPI.transfer(_addr >> 8);
|
||||||
SPI.send(_addr & 0xFF);
|
SPI.transfer(_addr & 0xFF);
|
||||||
_addr++;
|
_addr++;
|
||||||
SPI.send(_buf[i]);
|
SPI.transfer(_buf[i]);
|
||||||
resetSS();
|
resetSS();
|
||||||
}
|
}
|
||||||
return _len;
|
return _len;
|
||||||
@ -144,10 +144,10 @@ uint16_t W5100Class::write(uint16_t _addr, uint8_t *_buf, uint16_t _len)
|
|||||||
uint8_t W5100Class::read(uint16_t _addr)
|
uint8_t W5100Class::read(uint16_t _addr)
|
||||||
{
|
{
|
||||||
setSS();
|
setSS();
|
||||||
SPI.send(0x0F);
|
SPI.transfer(0x0F);
|
||||||
SPI.send(_addr >> 8);
|
SPI.transfer(_addr >> 8);
|
||||||
SPI.send(_addr & 0xFF);
|
SPI.transfer(_addr & 0xFF);
|
||||||
uint8_t _data = SPI.send(0);
|
uint8_t _data = SPI.transfer(0);
|
||||||
resetSS();
|
resetSS();
|
||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
@ -157,11 +157,11 @@ uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
|
|||||||
for (int i=0; i<_len; i++)
|
for (int i=0; i<_len; i++)
|
||||||
{
|
{
|
||||||
setSS();
|
setSS();
|
||||||
SPI.send(0x0F);
|
SPI.transfer(0x0F);
|
||||||
SPI.send(_addr >> 8);
|
SPI.transfer(_addr >> 8);
|
||||||
SPI.send(_addr & 0xFF);
|
SPI.transfer(_addr & 0xFF);
|
||||||
_addr++;
|
_addr++;
|
||||||
_buf[i] = SPI.send(0);
|
_buf[i] = SPI.transfer(0);
|
||||||
resetSS();
|
resetSS();
|
||||||
}
|
}
|
||||||
return _len;
|
return _len;
|
||||||
|
@ -38,7 +38,7 @@ class SPIClass {
|
|||||||
public:
|
public:
|
||||||
SPIClass();
|
SPIClass();
|
||||||
|
|
||||||
inline static byte send(byte _data);
|
inline static byte transfer(byte _data);
|
||||||
|
|
||||||
// SPI Configuration methods
|
// SPI Configuration methods
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
|
|
||||||
extern SPIClass SPI;
|
extern SPIClass SPI;
|
||||||
|
|
||||||
byte SPIClass::send(byte _data) {
|
byte SPIClass::transfer(byte _data) {
|
||||||
SPDR = _data;
|
SPDR = _data;
|
||||||
while (!(SPSR & _BV(SPIF)))
|
while (!(SPSR & _BV(SPIF)))
|
||||||
;
|
;
|
||||||
|
@ -92,8 +92,8 @@ void writeRegister(byte registerName, byte registerValue) {
|
|||||||
// take the chip select low to select the device:
|
// take the chip select low to select the device:
|
||||||
digitalWrite(chipSelectPin, LOW);
|
digitalWrite(chipSelectPin, LOW);
|
||||||
|
|
||||||
SPI.send(registerName); //Send register location
|
SPI.transfer(registerName); //Send register location
|
||||||
SPI.send(registerValue); //Send value to record into register
|
SPI.transfer(registerValue); //Send value to record into register
|
||||||
|
|
||||||
// take the chip select high to de-select:
|
// take the chip select high to de-select:
|
||||||
digitalWrite(chipSelectPin, HIGH); //Select SPI device
|
digitalWrite(chipSelectPin, HIGH); //Select SPI device
|
||||||
@ -114,9 +114,9 @@ unsigned int readRegister(byte registerName, int numBytes) {
|
|||||||
// take the chip select low to select the device:
|
// take the chip select low to select the device:
|
||||||
digitalWrite(chipSelectPin, LOW);
|
digitalWrite(chipSelectPin, LOW);
|
||||||
// send the device the register you want to read:
|
// send the device the register you want to read:
|
||||||
int command = SPI.send(registerName);
|
int command = SPI.transfer(registerName);
|
||||||
// send a value of 0 to read the forst byte returned:
|
// send a value of 0 to read the forst byte returned:
|
||||||
inByte = SPI.send(0x00);
|
inByte = SPI.transfer(0x00);
|
||||||
|
|
||||||
// if there's more than one byte returned,
|
// if there's more than one byte returned,
|
||||||
// shift the first byte then get the second byte:
|
// shift the first byte then get the second byte:
|
||||||
@ -126,7 +126,7 @@ unsigned int readRegister(byte registerName, int numBytes) {
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
result = inByte << 8;
|
result = inByte << 8;
|
||||||
inByte = SPI.send(0x00);
|
inByte = SPI.transfer(0x00);
|
||||||
result = result |inByte;
|
result = result |inByte;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user