Skip to content

Make SPI port configurable at runtime #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/LoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

#define MAX_PKT_LENGTH 255

static SPIClass& SPIPORT = SPI;
Copy link
Contributor

@Rotzbua Rotzbua Feb 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a member variable?
edit: I ask about the reason: programming, compiling, resources or design pattern?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, in order to make this work with multiple SX1276 devices at the same time, this would need to be part of the class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morganrallen For multiple devices are not multiple spi bus required. So 1 spi will work with 4-7 devices.
pic

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I even commented that on #104

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important part is the interrupt of each device @morganrallen are u working on this now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actively working on this yet, I hope to get time tomorrow or Saturday


LoRaClass::LoRaClass() :
_spiSettings(8E6, MSBFIRST, SPI_MODE0),
_ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN),
Expand All @@ -62,6 +64,12 @@ LoRaClass::LoRaClass() :
setTimeout(0);
}

int LoRaClass::begin(SPIClass& device, long frequency)
{
SPIPORT = device;
return begin(frequency);
}

int LoRaClass::begin(long frequency)
{
// setup pins
Expand All @@ -80,7 +88,7 @@ int LoRaClass::begin(long frequency)
}

// start SPI
SPI.begin();
SPIPORT.begin();

// check version
uint8_t version = readRegister(REG_VERSION);
Expand Down Expand Up @@ -119,7 +127,7 @@ void LoRaClass::end()
sleep();

// stop SPI
SPI.end();
SPIPORT.end();
}

int LoRaClass::beginPacket(int implicitHeader)
Expand Down Expand Up @@ -511,10 +519,10 @@ uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value)

digitalWrite(_ss, LOW);

SPI.beginTransaction(_spiSettings);
SPI.transfer(address);
response = SPI.transfer(value);
SPI.endTransaction();
SPIPORT.beginTransaction(_spiSettings);
SPIPORT.transfer(address);
response = SPIPORT.transfer(value);
SPIPORT.endTransaction();

digitalWrite(_ss, HIGH);

Expand Down
1 change: 1 addition & 0 deletions src/LoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class LoRaClass : public Stream {
public:
LoRaClass();

int begin(SPIClass& device, long frequency);
int begin(long frequency);
void end();

Expand Down