Commit ea987810 authored by TMRh20's avatar TMRh20

RPi - Example updates, minor bmc driver change

- Modified spi transfernb hopefully for the last time, re #9
- Updated RPi examples to minimize CPU usage
- Updated transfer example for Arduino and RPi to exit TX mode after 4ms
per manufacturer. Improves multicast streaming.
- Bit of a cleanup on RPi examples
parent b8d97f53
......@@ -621,28 +621,17 @@ void __bcm2835_spi_transfernb(char* tbuf, char* rbuf, uint32_t len, uint8_t dela
{
bcm2835_peri_write_nb(fifo, tbuf[TXCnt]);
TXCnt++;
}
//Rx fifo not empty, so get the next received bytes
while(! (bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXD) ){}
while(((bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXD))&&( RXCnt < len ))
{
while(! (bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_DONE) ){}
if(TXCnt == len){ bcm2835_peri_set_bits(paddr, 0, BCM2835_SPI0_CS_TA); if(delay){ delayMicroseconds(20);}}
while(((bcm2835_peri_read(paddr) & BCM2835_SPI0_CS_RXD))&&( RXCnt < len )){
rbuf[RXCnt] = bcm2835_peri_read_nb(fifo);
RXCnt++;
}
if(delay){ delayMicroseconds(10); }
}
// Wait for DONE to be set
while (!(bcm2835_peri_read_nb(paddr) & BCM2835_SPI0_CS_DONE)){
}
// Set TA = 0, and also set the barrier
bcm2835_peri_set_bits(paddr, 0, BCM2835_SPI0_CS_TA);
if(delay){ delayMicroseconds(20);}
delayMicroseconds(5);
}
......
......@@ -42,7 +42,6 @@ using namespace std;
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.
const uint8_t pipes[][6] = {"1Node","2Node"};
//const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
......@@ -61,7 +60,6 @@ int main(int argc, char** argv){
// optionally, increase the delay between retries & # of retries
radio.setRetries(15,15);
// Dump the configuration of the rf unit for debugging
radio.printDetails();
......@@ -121,8 +119,6 @@ int main(int argc, char** argv){
unsigned long started_waiting_at = millis();
bool timeout = false;
while ( ! radio.available() && ! timeout ) {
// by bcatalin » Thu Feb 14, 2013 11:26 am
//delay(5); //add a small delay to let radio.available to check payload
if (millis() - started_waiting_at > 200 )
timeout = true;
}
......@@ -156,6 +152,7 @@ int main(int argc, char** argv){
if ( role == role_pong_back )
{
// if there is data ready
//printf("Check available...\n");
......@@ -170,7 +167,6 @@ int main(int argc, char** argv){
radio.stopListening();
// Seem to need a delay, or the RPi is too quick
radio.write( &got_time, sizeof(unsigned long) );
// Now, resume listening so we catch the next packets.
......@@ -179,6 +175,8 @@ int main(int argc, char** argv){
// Spew it
printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time);
delay(925); //Delay after payload responded to, minimize RPi CPU time
}
}
......
......@@ -28,12 +28,12 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
//RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS1, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
// Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
// Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
......@@ -48,14 +48,12 @@ uint8_t counter = 1; //
int main(int argc, char** argv){
printf("RF24/examples/gettingstarted_call_response\n");
printf("RPi/RF24/examples/gettingstarted_call_response\n");
radio.begin();
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.enableAckPayload(); // Allow optional ack payloads
radio.setRetries(1,15); // Smallest time between retries, max no. of retries
radio.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed
//radio.powerUp();
radio.printDetails(); // Dump the configuration of the rf unit for debugging
......@@ -76,9 +74,8 @@ int main(int argc, char** argv){
}
}
/***********************************/
// This simple sketch opens two pipes for these two nodes to communicate
// This opens two pipes for these two nodes to communicate
// back and forth.
if ( role == role_ping_out ) {
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
......@@ -123,15 +120,15 @@ while (1){
if ( role == role_pong_back ) {
uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received
while( radio.available(&pipeNo)){ // Read all available payloads
if( radio.available(&pipeNo)){ // Read all available payloads
radio.flush_tx(); // Clear any unused ACK payloads
radio.read( &gotByte, 1 );
// Since this is a call-response. Respond directly with an ack payload.
// Ack payloads are much more efficient than switching to transmit mode to respond to a call
radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads.
printf("Sent response %d \n\r", gotByte);
delay(900); //Delay after a response to minimize CPU usage on RPi
//Expects a payload every second
}
}
......
......@@ -56,7 +56,7 @@ int main(int argc, char** argv){
radio.begin(); // Setup and configure rf radio
radio.setChannel(1);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_2MBPS);
radio.setDataRate(RF24_1MBPS);
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
radio.setCRCLength(RF24_CRC_8);
......@@ -102,6 +102,7 @@ int main(int argc, char** argv){
long int cycles = 10000; //Change this to a higher or lower number.
// unsigned long pauseTime = millis(); //Uncomment if autoAck == 1 ( NOACK )
startTime = millis();
for(int i=0; i<cycles; i++){ //Loop through a number of cycles
......@@ -109,6 +110,13 @@ int main(int argc, char** argv){
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
counter++; //Keep count of failed payloads
}
//This is only required when NO ACK ( enableAutoAck(0) ) payloads are used
/* if(millis() - pauseTime > 3){ // Need to drop out of TX mode every 4ms if sending a steady stream of multicast data
pauseTime = millis();
radio.txStandBy(); // This gives the PLL time to sync back up
}
*/
}
stopTime = millis();
......
......@@ -13,16 +13,13 @@ TMRh20 2014
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
/************* USER Configuration *****************************/
// Hardware configuration
RF24 radio(48,49); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8
boolean RADIO_NO = 0; //SET THIS TO 0 or 1 for 1st or 2nd radio
RF24 radio(7,8); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8
/***************************************************************/
......@@ -46,7 +43,6 @@ void setup(void) {
radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
radio.setCRCLength(RF24_CRC_8);
//radio.disableCRC();
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
......@@ -77,12 +73,21 @@ void loop(void){
unsigned long cycles = 10000; //Change this to a higher or lower number.
startTime = millis();
unsigned long pauseTime = millis();
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
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
counter++; //Keep count of failed payloads
}
//This is only required when NO ACK ( enableAutoAck(0) ) payloads are used
// if(millis() - pauseTime > 3){
// pauseTime = millis();
// radio.txStandBy(); // Need to drop out of TX mode every 4ms if sending a steady stream of multicast data
// //delayMicroseconds(130); // This gives the PLL time to sync back up
// }
}
stopTime = millis();
......@@ -93,8 +98,8 @@ void loop(void){
float numBytes = cycles*32;
float rate = numBytes / (stopTime - startTime);
printf("Transfer complete at "); Serial.print(rate); printf(" KB/s \n\r");
printf("%d of ",counter); Serial.print(cycles); printf(" Packets Failed to Send\n\r");
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");
counter = 0;
}
......@@ -108,11 +113,10 @@ if(role == RX){
}
if(millis() - rxTimer > 1000){
rxTimer = millis();
printf("Rate: ");
float numBytes = counter*32;
Serial.print(numBytes/1000);
printf(" KB/s\n\r");
printf("Payload Count: %d \n\r", counter);
float numBytes = (counter*32)/1000.0;
Serial.print("Rate: ");
Serial.print(numBytes);
printf("KB/s \n Payload Count: %d \n\r", counter);
counter = 0;
}
}
......@@ -141,4 +145,3 @@ if(role == RX){
}
}
}
// vim:cin:ai:sts=2 sw=2 ft=cpp
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