Skip to content
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

enable SoftSPI for RF24 when using ethernet cards #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

#include "nRF24L01.h"
#include "RF24_config.h"
#ifdef SOFTSPI
#include "DigitalIO.h"
#else
#include <SPI.h>
#endif
#include "RF24.h"

/****************************************************************************/
Expand All @@ -19,9 +24,15 @@ void RF24::csn(int mode)
// divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
#ifdef ARDUINO
//
// we do not use these with SoftSPI
//
#ifndef SOFTSPI
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV4);
#endif

#endif
digitalWrite(csn_pin,mode);
}
Expand Down
26 changes: 17 additions & 9 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
* Class declaration for RF24 and helper enums
*/


#ifndef __RF24_H__
#define __RF24_H__

#include <RF24_config.h>

#ifdef SOFTSPI
#include <DigitalIO.h>
#endif

/**
* Power Amplifier level.
*
Expand Down Expand Up @@ -45,15 +50,18 @@ typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e
class RF24
{
private:
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint8_t csn_pin; /**< SPI Chip select */
bool wide_band; /* 2Mbs data rate in use? */
bool p_variant; /* False for RF24L01 and true for RF24L01P */
uint8_t payload_size; /**< Fixed size of payloads */
bool ack_payload_available; /**< Whether there is an ack payload waiting */
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */
#ifdef SOFTSPI
SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;
#endif
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint8_t csn_pin; /**< SPI Chip select */
bool wide_band; /* 2Mbs data rate in use? */
bool p_variant; /* False for RF24L01 and true for RF24L01P */
uint8_t payload_size; /**< Fixed size of payloads */
bool ack_payload_available; /**< Whether there is an ack payload waiting */
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. */
uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */

protected:
/**
Expand Down
16 changes: 16 additions & 0 deletions RF24_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ extern HardwareSPI SPI;
#else
#define IF_SERIAL_DEBUG(x)
#endif
//
// if we are using Soft SPI
//
#ifdef ARDUINO
#define SOFTSPI // comment out this line to use hardwarer SPI
#ifdef SOFTSPI
//
// change these pins to your liking
//
const uint8_t SOFT_SPI_MISO_PIN = 16;
const uint8_t SOFT_SPI_MOSI_PIN = 15;
const uint8_t SOFT_SPI_SCK_PIN = 14;
const uint8_t SPI_MODE = 0;
#define SPI spi
#endif
#endif

// Avoid spurious warnings
#if 1
Expand Down