Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
d9579b3c
Commit
d9579b3c
authored
Apr 18, 2015
by
TMRh20
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/Updates'
parents
8a8803be
90d85bef
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
137 deletions
+83
-137
RF24.cpp
RF24.cpp
+49
-116
RF24.h
RF24.h
+27
-1
RF24_config.h
RF24_config.h
+5
-18
examples/Transfer/Transfer.ino
examples/Transfer/Transfer.ino
+2
-2
No files found.
RF24.cpp
View file @
d9579b3c
...
...
@@ -90,20 +90,14 @@ uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
// decrement before to skip status byte
while
(
--
size
){
*
buf
++
=
*
prx
++
;
}
#elif defined (RF24_DUE)
status
=
_SPI
.
transfer
(
csn_pin
,
R_REGISTER
|
(
REGISTER_MASK
&
reg
),
SPI_CONTINUE
);
while
(
len
--
>
1
){
*
buf
++
=
_SPI
.
transfer
(
csn_pin
,
0xff
,
SPI_CONTINUE
);
}
*
buf
++
=
_SPI
.
transfer
(
csn_pin
,
0xff
);
#else
csn
(
LOW
);
beginTransaction
();
status
=
_SPI
.
transfer
(
R_REGISTER
|
(
REGISTER_MASK
&
reg
)
);
while
(
len
--
){
*
buf
++
=
_SPI
.
transfer
(
0xff
);
}
csn
(
HIGH
);
endTransaction
(
);
#endif
...
...
@@ -128,15 +122,13 @@ uint8_t RF24::read_register(uint8_t reg)
_SPI
.
transfernb
(
(
char
*
)
spi_txbuff
,
(
char
*
)
spi_rxbuff
,
2
);
result
=
*++
prx
;
// result is 2nd byte of receive buffer
#elif defined (RF24_DUE)
_SPI
.
transfer
(
csn_pin
,
R_REGISTER
|
(
REGISTER_MASK
&
reg
)
,
SPI_CONTINUE
);
result
=
_SPI
.
transfer
(
csn_pin
,
0xff
);
#else
csn
(
LOW
);
beginTransaction
();
_SPI
.
transfer
(
R_REGISTER
|
(
REGISTER_MASK
&
reg
)
);
result
=
_SPI
.
transfer
(
0xff
);
endTransaction
();
csn
(
HIGH
);
#endif
return
result
;
...
...
@@ -162,20 +154,13 @@ uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
_SPI
.
transfernb
(
(
char
*
)
spi_txbuff
,
(
char
*
)
spi_rxbuff
,
size
);
status
=
*
prx
;
// status is 1st byte of receive buffer
#elif defined (RF24_DUE)
status
=
_SPI
.
transfer
(
csn_pin
,
W_REGISTER
|
(
REGISTER_MASK
&
reg
),
SPI_CONTINUE
);
while
(
--
len
){
_SPI
.
transfer
(
csn_pin
,
*
buf
++
,
SPI_CONTINUE
);
}
_SPI
.
transfer
(
csn_pin
,
*
buf
++
);
#else
csn
(
LOW
);
beginTransaction
(
);
status
=
_SPI
.
transfer
(
W_REGISTER
|
(
REGISTER_MASK
&
reg
)
);
while
(
len
--
)
_SPI
.
transfer
(
*
buf
++
);
csn
(
HIGH
);
endTransaction
();
#endif
...
...
@@ -200,15 +185,12 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value)
_SPI
.
transfernb
(
(
char
*
)
spi_txbuff
,
(
char
*
)
spi_rxbuff
,
2
);
status
=
*
prx
++
;
// status is 1st byte of receive buffer
#elif defined (RF24_DUE)
status
=
_SPI
.
transfer
(
csn_pin
,
W_REGISTER
|
(
REGISTER_MASK
&
reg
),
SPI_CONTINUE
);
_SPI
.
transfer
(
csn_pin
,
value
);
#else
csn
(
LOW
);
beginTransaction
(
);
status
=
_SPI
.
transfer
(
W_REGISTER
|
(
REGISTER_MASK
&
reg
)
);
_SPI
.
transfer
(
value
);
csn
(
HIGH
);
endTransaction
(
);
#endif
...
...
@@ -244,28 +226,10 @@ uint8_t RF24::write_payload(const void* buf, uint8_t data_len, const uint8_t wri
_SPI
.
transfernb
(
(
char
*
)
spi_txbuff
,
(
char
*
)
spi_rxbuff
,
size
);
status
=
*
prx
;
// status is 1st byte of receive buffer
#elif defined (RF24_DUE)
status
=
_SPI
.
transfer
(
csn_pin
,
writeType
,
SPI_CONTINUE
);
if
(
blank_len
){
while
(
data_len
--
){
_SPI
.
transfer
(
csn_pin
,
*
current
++
,
SPI_CONTINUE
);
}
while
(
--
blank_len
){
_SPI
.
transfer
(
csn_pin
,
0
,
SPI_CONTINUE
);
}
_SPI
.
transfer
(
csn_pin
,
0
);
}
else
{
while
(
--
data_len
){
_SPI
.
transfer
(
csn_pin
,
*
current
++
,
SPI_CONTINUE
);
}
_SPI
.
transfer
(
csn_pin
,
*
current
);
}
#else
csn
(
LOW
);
beginTransaction
(
);
status
=
_SPI
.
transfer
(
writeType
);
while
(
data_len
--
)
{
_SPI
.
transfer
(
*
current
++
);
...
...
@@ -273,7 +237,7 @@ uint8_t RF24::write_payload(const void* buf, uint8_t data_len, const uint8_t wri
while
(
blank_len
--
)
{
_SPI
.
transfer
(
0
);
}
csn
(
HIGH
);
endTransaction
(
);
#endif
...
...
@@ -302,7 +266,7 @@ uint8_t RF24::read_payload(void* buf, uint8_t data_len)
size
=
data_len
+
blank_len
+
1
;
// Add register value to transmit buffer
*
ptx
++
=
R_RX_PAYLOAD
;
while
(
size
--
)
while
(
--
size
)
*
ptx
++
=
NOP
;
size
=
data_len
+
blank_len
+
1
;
// Size has been lost during while, re affect
...
...
@@ -316,29 +280,9 @@ uint8_t RF24::read_payload(void* buf, uint8_t data_len)
*
current
=
*
prx
;
#elif defined (RF24_DUE)
status
=
_SPI
.
transfer
(
csn_pin
,
R_RX_PAYLOAD
,
SPI_CONTINUE
);
if
(
blank_len
){
while
(
data_len
--
){
*
current
++
=
_SPI
.
transfer
(
csn_pin
,
0xFF
,
SPI_CONTINUE
);
}
while
(
--
blank_len
){
_SPI
.
transfer
(
csn_pin
,
0xFF
,
SPI_CONTINUE
);
}
_SPI
.
transfer
(
csn_pin
,
0xFF
);
}
else
{
while
(
--
data_len
){
*
current
++
=
_SPI
.
transfer
(
csn_pin
,
0xFF
,
SPI_CONTINUE
);
}
*
current
=
_SPI
.
transfer
(
csn_pin
,
0xFF
);
}
#else
csn
(
LOW
);
beginTransaction
(
);
status
=
_SPI
.
transfer
(
R_RX_PAYLOAD
);
while
(
data_len
--
)
{
*
current
++
=
_SPI
.
transfer
(
0xFF
);
...
...
@@ -346,7 +290,7 @@ uint8_t RF24::read_payload(void* buf, uint8_t data_len)
while
(
blank_len
--
)
{
_SPI
.
transfer
(
0xff
);
}
csn
(
HIGH
);
endTransaction
(
);
#endif
...
...
@@ -375,14 +319,15 @@ uint8_t RF24::spiTrans(uint8_t cmd){
#if defined (RF24_LINUX)
csn
(
LOW
);
status
=
_SPI
.
transfer
(
cmd
);
#elif defined (RF24_DUE)
status
=
_SPI
.
transfer
(
csn_pin
,
cmd
);
#else
csn
(
LOW
);
beginTransaction
(
);
status
=
_SPI
.
transfer
(
cmd
);
csn
(
HIGH
);
endTransaction
();
#endif
return
status
;
}
...
...
@@ -422,7 +367,7 @@ void RF24::print_observe_tx(uint8_t value)
void
RF24
::
print_byte_register
(
const
char
*
name
,
uint8_t
reg
,
uint8_t
qty
)
{
//char extra_tab = strlen_P(name) < 8 ? '\t' :
'\a'
;
//char extra_tab = strlen_P(name) < 8 ? '\t' :
0
;
//printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);
#if defined (RF24_LINUX)
char
extra_tab
=
strlen_P
(
name
)
<
8
?
'\t'
:
0
;
...
...
@@ -468,6 +413,7 @@ RF24::RF24(uint8_t _cepin, uint8_t _cspin):
ce_pin
(
_cepin
),
csn_pin
(
_cspin
),
p_variant
(
false
),
payload_size
(
32
),
dynamic_payloads_enabled
(
false
),
addr_width
(
5
)
//,pipe0_reading_address(0)
{
pipe0_reading_address
[
0
]
=
0
;
}
/****************************************************************************/
...
...
@@ -475,7 +421,8 @@ RF24::RF24(uint8_t _cepin, uint8_t _cspin):
#if defined (RF24_LINUX) && !defined (MRAA)//RPi constructor
RF24
::
RF24
(
uint8_t
_cepin
,
uint8_t
_cspin
,
uint32_t
_spi_speed
)
:
ce_pin
(
_cepin
),
csn_pin
(
_cspin
),
spi_speed
(
_spi_speed
),
p_variant
(
false
),
payload_size
(
32
),
dynamic_payloads_enabled
(
false
),
addr_width
(
5
)
//,pipe0_reading_address(0)
{
{
pipe0_reading_address
[
0
]
=
0
;
}
#endif
...
...
@@ -617,9 +564,11 @@ void RF24::printDetails(void)
#endif
/****************************************************************************/
void
RF24
::
begin
(
void
)
bool
RF24
::
begin
(
void
)
{
uint8_t
setup
=
0
;
#if defined (RF24_LINUX)
SPI
();
...
...
@@ -652,17 +601,10 @@ void RF24::begin(void)
csn
(
HIGH
);
#else
// Initialize pins
if
(
ce_pin
!=
csn_pin
)
pinMode
(
ce_pin
,
OUTPUT
);
if
(
ce_pin
!=
csn_pin
)
pinMode
(
ce_pin
,
OUTPUT
);
#if defined (RF24_DUE)
_SPI
.
begin
(
csn_pin
);
// Using the extended SPI features of the DUE
_SPI
.
setClockDivider
(
csn_pin
,
11
);
// Set the bus speed to just under 8mhz on Due
_SPI
.
setBitOrder
(
csn_pin
,
MSBFIRST
);
// Set the bit order and mode specific to this device
_SPI
.
setDataMode
(
csn_pin
,
SPI_MODE0
);
ce
(
LOW
);
#else
#if ! defined(LITTLEWIRE)
if
(
ce_pin
!=
csn_pin
)
if
(
ce_pin
!=
csn_pin
)
#endif
pinMode
(
csn_pin
,
OUTPUT
);
...
...
@@ -672,7 +614,6 @@ void RF24::begin(void)
#if defined (__ARDUINO_X86__)
delay
(
100
);
#endif
#endif
#endif //Linux
// Must allow the radio time to settle else configuration bits will not necessarily stick.
...
...
@@ -694,14 +635,17 @@ void RF24::begin(void)
// Reset value is MAX
//setPALevel( RF24_PA_MAX ) ;
// Determine if this is a p or non-p RF24 module and then
// reset our data rate back to default value. This works
// because a non-P variant won't allow the data rate to
// be set to 250Kbps.
// check for connected module and if this is a p nRF24l01 variant
//
if
(
setDataRate
(
RF24_250KBPS
)
)
{
p_variant
=
true
;
}
/*setup = read_register(RF_SETUP);
if( setup == 0b00001110 ) // register default for nRF24L01P
{
p_variant = true ;
}*/
// Then set the data rate to the slowest (and most reliable) speed supported by all
// hardware.
...
...
@@ -734,6 +678,8 @@ void RF24::begin(void)
// PTX should use only 22uA of power
write_register
(
CONFIG
,
(
read_register
(
CONFIG
)
)
&
~
_BV
(
PRIM_RX
)
);
// if setup is 0 or ff then there was no response from module
return
(
setup
!=
0
&&
setup
!=
0xff
);
}
/****************************************************************************/
...
...
@@ -1084,15 +1030,11 @@ uint8_t RF24::getDynamicPayloadSize(void)
_SPI
.
transfernb
(
(
char
*
)
spi_txbuff
,
(
char
*
)
spi_rxbuff
,
2
);
result
=
spi_rxbuff
[
1
];
csn
(
HIGH
);
#elif defined (RF24_DUE)
_SPI
.
transfer
(
csn_pin
,
R_RX_PL_WID
,
SPI_CONTINUE
);
result
=
_SPI
.
transfer
(
csn_pin
,
0xff
);
#else
csn
(
LOW
);
beginTransaction
(
);
_SPI
.
transfer
(
R_RX_PL_WID
);
result
=
_SPI
.
transfer
(
0xff
);
csn
(
HIGH
);
endTransaction
();
#endif
if
(
result
>
32
)
{
flush_rx
();
delay
(
2
);
return
0
;
}
...
...
@@ -1274,15 +1216,13 @@ void RF24::toggle_features(void)
_SPI
.
transfer
(
ACTIVATE
);
_SPI
.
transfer
(
0x73
);
csn
(
HIGH
);
#elif defined (RF24_DUE)
_SPI
.
transfer
(
csn_pin
,
ACTIVATE
,
SPI_CONTINUE
);
_SPI
.
transfer
(
csn_pin
,
0x73
);
#else
csn
(
LOW
);
_SPI
.
transfer
(
ACTIVATE
);
_SPI
.
transfer
(
0x73
);
csn
(
HIGH
);
beginTransaction
(
);
_SPI
.
transfer
(
ACTIVATE
);
_SPI
.
transfer
(
0x73
);
endTransaction
(
);
#endif
}
/****************************************************************************/
...
...
@@ -1360,23 +1300,16 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
_SPI
.
transfern
(
(
char
*
)
spi_txbuff
,
size
);
csn
(
HIGH
);
#elif defined (RF24_DUE)
_SPI
.
transfer
(
csn_pin
,
W_ACK_PAYLOAD
|
(
pipe
&
0b111
),
SPI_CONTINUE
);
while
(
data_len
--
>
1
){
_SPI
.
transfer
(
csn_pin
,
*
current
++
,
SPI_CONTINUE
);
}
_SPI
.
transfer
(
csn_pin
,
*
current
++
);
#else
csn
(
LOW
);
beginTransaction
(
);
_SPI
.
transfer
(
W_ACK_PAYLOAD
|
(
pipe
&
0b111
)
);
while
(
data_len
--
)
_SPI
.
transfer
(
*
current
++
);
endTransaction
();
#endif
csn
(
HIGH
);
#endif
}
/****************************************************************************/
...
...
RF24.h
View file @
d9579b3c
...
...
@@ -80,6 +80,31 @@ private:
uint8_t
addr_width
;
/**< The address width to use - 3,4 or 5 bytes. */
uint32_t
txRxDelay
;
/**< Var for adjusting delays depending on datarate */
#if defined (ARDUINO)
protected:
/**
* SPI transactions
*
* Common code for SPI transactions including CSN toggle
*
*/
inline
void
beginTransaction
()
{
#if defined (SPI_HAS_TRANSACTION)
_SPI
.
beginTransaction
(
SPISettings
(
RF_SPI_SPEED
,
MSBFIRST
,
SPI_MODE0
));
#endif
csn
(
LOW
);
}
inline
void
endTransaction
()
{
csn
(
HIGH
);
#if defined (SPI_HAS_TRANSACTION)
_SPI
.
endTransaction
();
#endif
}
#endif
/* ARDUINO */
public:
/**
...
...
@@ -125,7 +150,7 @@ public:
* Call this in setup(), before calling any other methods.
* @code radio.begin() @endcode
*/
void
begin
(
void
);
bool
begin
(
void
);
/**
* Start listening on the pipes opened for reading.
...
...
@@ -1309,6 +1334,7 @@ private:
* @section News News
*
* **March 2015**<br>
* - Uses SPI transactions on Arduino
* - New layout for <a href="Portability.html">easier portability:</a> Break out defines & includes for individual platforms to RF24/arch
* - <a href="MRAA.html">MRAA</a> support added ( Galileo, Edison, etc)
* - <a href="BBB.html">BBB/Generic Linux </a> support via spidev & MRAA
...
...
RF24_config.h
View file @
d9579b3c
...
...
@@ -5,8 +5,6 @@
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
Added Arduino Due support from https://github.com/mcrosson/
*/
/* spaniakos <spaniakos@gmail.com>
...
...
@@ -35,12 +33,6 @@
// The includes.h file defines either RF24_RPi, MRAA or RF24_BBB and includes the correct RF24_arch_config.h file
#include "arch/includes.h"
//Arduino Due
#elif defined ARDUINO_SAM_DUE
#define RF24_DUE
#include "arch/Due/RF24_arch_config.h"
//ATTiny
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
...
...
@@ -59,16 +51,11 @@
//Everything else
#else
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include <stddef.h>
#include <Arduino.h>
// Define _BV for non-Arduino platforms and for Arduino DUE
// RF modules support 10 Mhz SPI bus speed
const
uint32_t
RF_SPI_SPEED
=
10000000
;
#if defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
#if defined SPI_UART
#include <SPI_UART.h>
...
...
@@ -87,6 +74,7 @@
#define _SPI SPI
#endif
#else
// Define _BV for non-Arduino platforms and for Arduino DUE
#include <stdint.h>
#include <stdio.h>
#include <string.h>
...
...
@@ -106,7 +94,6 @@
#define _SPI SPI
#endif
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
...
...
examples/Transfer/Transfer.ino
View file @
d9579b3c
...
...
@@ -99,8 +99,8 @@ void loop(void){
float
numBytes
=
cycles
*
32
;
float
rate
=
numBytes
/
(
stopTime
-
startTime
);
Serial
.
print
(
"Transfer complete at "
);
Serial
.
print
(
rate
);
printf
(
" KB/s
\n\r
"
);
Serial
.
print
(
counter
);
Serial
.
print
(
" of "
);
Serial
.
print
(
cycles
);
printf
(
" Packets Failed to Send
\n\r
"
);
Serial
.
print
(
"Transfer complete at "
);
Serial
.
print
(
rate
);
Serial
.
println
(
" KB/s
"
);
Serial
.
print
(
counter
);
Serial
.
print
(
" of "
);
Serial
.
print
(
cycles
);
Serial
.
println
(
" Packets Failed to Send
"
);
counter
=
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment