Skip to content

Commit

Permalink
#24 Add softSPI supp, fix SPI_UART
Browse files Browse the repository at this point in the history
- Added softSPI support for https://github.com/greiman/DigitalIO library
- Updated SPI_UART code to allow use at the same time as the SPI library
  • Loading branch information
TMRh20 committed Oct 3, 2014
1 parent 3f4a1cb commit 56b7711
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void RF24::csn(bool mode)
// divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
#ifdef ARDUINO
#if ( !defined(RF24_TINY) && !defined (__arm__) ) || defined (CORE_TEENSY)
#if ( !defined(RF24_TINY) && !defined (__arm__) && !defined (SOFTSPI)) || defined (CORE_TEENSY)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
Expand All @@ -38,7 +38,7 @@ void RF24::csn(bool mode)
}
else {
PORTB &= ~(1<<PINB2); // SCK->CSN LOW
delayMicroseconds(20); // allow csn to settle
delayMicroseconds(11); // allow csn to settle
}
}
#else if !defined (__arm__) || defined (CORE_TEENSY)
Expand Down
10 changes: 9 additions & 1 deletion RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#define __RF24_H__

#include <RF24_config.h>

#if defined SOFTSPI
#include <DigitalIO.h>
#endif
/**
* Power Amplifier level.
*
Expand Down Expand Up @@ -45,6 +47,12 @@ typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e
class RF24
{
private:
#ifdef SOFTSPI
SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;
#endif
#ifdef SPI_UART
SPIUARTClass spi;
#endif
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint8_t csn_pin; /**< SPI Chip select */
bool p_variant; /* False for RF24L01 and true for RF24L01P */
Expand Down
11 changes: 11 additions & 0 deletions RF24_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
//#define SERIAL_DEBUG
//#define MINIMAL
#define SPI_UART
//#define SOFTSPI
/**********************/

// Define _BV for non-Arduino platforms and for Arduino DUE
Expand All @@ -34,6 +35,16 @@
#else
#if defined SPI_UART
#include <SPI_UART.h>
#define SPI spi
#elif defined 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

#else
#include <SPI.h>
#endif
Expand Down

0 comments on commit 56b7711

Please sign in to comment.