Commit 6530f954 authored by TMRh20's avatar TMRh20

RPi SPI functionality and RPi fix for startWrite

- Enabled use of hardware CS1 pin
- Removed custom_cs code for software driven CSN
- Modified BCM driver to allow use of hardware SPI pins not in use while
SPI is active.
- Updated constructor in examples
parent cd8bb19d
...@@ -37,4 +37,5 @@ Supported Boards: ...@@ -37,4 +37,5 @@ Supported Boards:
* Mega Types (2560, 1280, etc) * Mega Types (2560, 1280, etc)
* ARM (Arduino Due) via extended SPI methods * ARM (Arduino Due) via extended SPI methods
* ATTiny 24/44/84 25/45/85 * ATTiny 24/44/84 25/45/85
* Raspberry Pi
* See the [documentation](http://tmrh20.github.io/) for more info * See the [documentation](http://tmrh20.github.io/) for more info
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -32,15 +32,14 @@ using namespace std; ...@@ -32,15 +32,14 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed // CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ); //RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
......
...@@ -27,15 +27,14 @@ using namespace std; ...@@ -27,15 +27,14 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed // CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ); //RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
*/ */
/** /**
* Example using Dynamic Payloads * Example using Dynamic Payloads
* *
* This is an example of how to use payloads of a varying (dynamic) size. * This is an example of how to use payloads of a varying (dynamic) size.
*/ */
#include <cstdlib> #include <cstdlib>
...@@ -22,14 +22,14 @@ using namespace std; ...@@ -22,14 +22,14 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed // CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ); //RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
...@@ -47,7 +47,7 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating ...@@ -47,7 +47,7 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating
int main(int argc, char** argv){ int main(int argc, char** argv){
// Print preamble: // Print preamble:
printf("RF24/examples/pingpair_dyn/\n"); printf("RF24/examples/pingpair_dyn/\n");
...@@ -65,7 +65,7 @@ int main(int argc, char** argv){ ...@@ -65,7 +65,7 @@ int main(int argc, char** argv){
char myChar = {0}; char myChar = {0};
cout << "Choose a role: Enter 0 for receiver, 1 for transmitter (CTRL+C to exit) \n>"; cout << "Choose a role: Enter 0 for receiver, 1 for transmitter (CTRL+C to exit) \n>";
getline(cin,input); getline(cin,input);
if(input.length() == 1) { if(input.length() == 1) {
myChar = input[0]; myChar = input[0];
if(myChar == '0'){ if(myChar == '0'){
...@@ -129,7 +129,7 @@ if (role == role_ping_out) ...@@ -129,7 +129,7 @@ if (role == role_ping_out)
// Spew it // Spew it
printf("Got response size=%i value=%s\n\r",len,receive_payload); printf("Got response size=%i value=%s\n\r",len,receive_payload);
} }
// Update size for next time. // Update size for next time.
next_payload_size += payload_size_increments_by; next_payload_size += payload_size_increments_by;
if ( next_payload_size > max_payload_size ) if ( next_payload_size > max_payload_size )
......
...@@ -7,7 +7,7 @@ TMRh20 2014 ...@@ -7,7 +7,7 @@ TMRh20 2014
*/ */
/** General Data Transfer Rate Test /** General Data Transfer Rate Test
* This example demonstrates basic data transfer functionality with the * This example demonstrates basic data transfer functionality with the
updated library. This example will display the transfer rates acheived using updated library. This example will display the transfer rates acheived using
the slower form of high-speed transfer using blocking-writes. the slower form of high-speed transfer using blocking-writes.
*/ */
...@@ -26,14 +26,14 @@ using namespace std; ...@@ -26,14 +26,14 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed // CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ); //RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
...@@ -42,16 +42,16 @@ const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; ...@@ -42,16 +42,16 @@ const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0; bool role_ping_out = 1, role_pong_back = 0;
bool role = 0; bool role = 0;
uint8_t data[32]; uint8_t data[32];
unsigned long startTime, stopTime, counter, rxTimer=0; unsigned long startTime, stopTime, counter, rxTimer=0;
int main(int argc, char** argv){ int main(int argc, char** argv){
// Print preamble: // Print preamble:
printf("RF24/examples/Transfer/\n"); printf("RF24/examples/Transfer/\n");
radio.begin(); // Setup and configure rf radio radio.begin(); // Setup and configure rf radio
radio.setChannel(1); radio.setChannel(1);
radio.setPALevel(RF24_PA_MAX); radio.setPALevel(RF24_PA_MAX);
...@@ -67,7 +67,7 @@ int main(int argc, char** argv){ ...@@ -67,7 +67,7 @@ int main(int argc, char** argv){
char myChar = {0}; char myChar = {0};
cout << "Choose a role: Enter 0 for receiver, 1 for transmitter (CTRL+C to exit)\n>"; cout << "Choose a role: Enter 0 for receiver, 1 for transmitter (CTRL+C to exit)\n>";
getline(cin,input); getline(cin,input);
if(input.length() == 1) { if(input.length() == 1) {
myChar = input[0]; myChar = input[0];
if(myChar == '0'){ if(myChar == '0'){
...@@ -86,8 +86,8 @@ int main(int argc, char** argv){ ...@@ -86,8 +86,8 @@ int main(int argc, char** argv){
radio.openReadingPipe(1,addresses[0]); radio.openReadingPipe(1,addresses[0]);
radio.startListening(); radio.startListening();
} }
for(int i=0; i<32; i++){ for(int i=0; i<32; i++){
data[i] = rand() % 255; //Load the buffer with random data data[i] = rand() % 255; //Load the buffer with random data
} }
...@@ -105,7 +105,7 @@ int main(int argc, char** argv){ ...@@ -105,7 +105,7 @@ int main(int argc, char** argv){
for(int i=0; i<cycles; i++){ //Loop through a number of cycles for(int i=0; i<cycles; i++){ //Loop through a number of cycles
data[0] = i; //Change the first byte of the payload for identification data[0] = i; //Change the first byte of the payload for identification
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
counter++; //Keep count of failed payloads counter++; //Keep count of failed payloads
} }
} }
...@@ -115,16 +115,16 @@ int main(int argc, char** argv){ ...@@ -115,16 +115,16 @@ int main(int argc, char** argv){
float numBytes = cycles*32; float numBytes = cycles*32;
float rate = numBytes / (stopTime - startTime); float rate = numBytes / (stopTime - startTime);
printf("Transfer complete at %.2f KB/s \n\r",rate); printf("Transfer complete at %.2f KB/s \n\r",rate);
printf("%lu of %lu Packets Failed to Send\n\r",counter,cycles); printf("%lu of %lu Packets Failed to Send\n\r",counter,cycles);
counter = 0; counter = 0;
} }
if(role == role_pong_back){ if(role == role_pong_back){
while(radio.available()){ while(radio.available()){
radio.read(&data,32); radio.read(&data,32);
counter++; counter++;
} }
......
...@@ -75,24 +75,33 @@ Connection Info ...@@ -75,24 +75,33 @@ Connection Info
Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN
Can use either RPi CE0 or CE1 pins for radio CSN.
Choose any RPi output pin for radio CE pin.
**Constructor:** **Constructor:**
``` ```
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
or
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS1, BCM2835_SPI_SPEED_8MHZ);
``` ```
**Pins:** **Pins:**
|NRF24L01 | RPI | P1 Connector | |NRF24L01 | RPI | P1 Connector |
|----- |----------- | -------------| |-----|-----------|-------------|
|VCC: | rpi-3v3 | (17) | | VCC | rpi-3v3 | (17) |
|GND: | rpi-gnd | (25) | | GND | rpi-gnd | (25) |
|CE: | rpi-gpio22 | (15) | | CE | rpi-gpio22 | (15) |
|CSN: | rpi-gpio8 | (24) | | CSN | rpi-gpio8 | (24) |
|SCK: | rpi-sckl | (23) | | SCK | rpi-sckl | (23) |
|MOSI: | rpi-mosi | (19) | | MOSI | rpi-mosi | (19) |
|MISO: | rpi-miso | (21) | | MISO | rpi-miso | (21) |
See http://www.airspayce.com/mikem/bcm2835/index.html for BCM2835 class documentation.
Note: The BCM library has been customized slightly to allow use of hardware CE pins not
in use for SPI, and to include a millis() function.
**************** ****************
......
...@@ -75,24 +75,33 @@ Connection Info ...@@ -75,24 +75,33 @@ Connection Info
Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN
Can use either RPi CE0 or CE1 pins for radio CSN.
Choose any RPi output pin for radio CE pin.
**Constructor:** **Constructor:**
``` ```
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
or
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS1, BCM2835_SPI_SPEED_8MHZ);
``` ```
**Pins:** **Pins:**
|NRF24L01 | RPI | P1 Connector | |NRF24L01 | RPI | P1 Connector |
|----- |----------- | -------------| |-----|-----------|-------------|
|VCC: | rpi-3v3 | (17) | | VCC | rpi-3v3 | (17) |
|GND: | rpi-gnd | (25) | | GND | rpi-gnd | (25) |
|CE: | rpi-gpio22 | (15) | | CE | rpi-gpio22 | (15) |
|CSN: | rpi-gpio8 | (24) | | CSN | rpi-gpio8 | (24) |
|SCK: | rpi-sckl | (23) | | SCK | rpi-sckl | (23) |
|MOSI: | rpi-mosi | (19) | | MOSI | rpi-mosi | (19) |
|MISO: | rpi-miso | (21) | | MISO | rpi-miso | (21) |
See http://www.airspayce.com/mikem/bcm2835/index.html for BCM2835 class documentation.
Note: The BCM library has been customized slightly to allow use of hardware CE pins not
in use for SPI, and to include a millis() function.
**************** ****************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment