Josh Blackann / Mbed 2 deprecated nRF24L01P_Hello_World_DISCO_F401RE

Dependencies:   mbed nRF24L01P

Fork of nRF24L01P_Hello_World by Owen Edwards

Files at this revision

API Documentation at this revision

Comitter:
jblackann
Date:
Fri Jun 15 12:33:52 2018 +0000
Parent:
1:5be2682710c6
Commit message:
Modified to work with the Nucleo STM32F401RE board. Also adding functionality to change the channel through the terminal.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 5be2682710c6 -r 945fa201ce19 main.cpp
--- a/main.cpp	Wed Jan 19 23:53:19 2011 +0000
+++ b/main.cpp	Fri Jun 15 12:33:52 2018 +0000
@@ -3,11 +3,90 @@
 
 Serial pc(USBTX, USBRX); // tx, rx
 
-nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10);    // mosi, miso, sck, csn, ce, irq
+/* this is being used with the nucleo F401RE */
+
+nRF24L01P my_nrf24l01p(PB_5, PB_4, PB_3, PA_4, PC_1 , PC_0);    // mosi, miso, sck, csn, ce, irq
+/*
+*  SPI_MOSI    = PB5, //previously PE_15, 
+*  SPI_MISO    = PB4, // previously PE_14, 
+*  SPI_SCK     = PB3, // previously PE_13, 
+*  SPI_CS      = PA4, // previously PE_12, 
+*  CE = PC1, // previously PE_10 
+*  IRQ = PC0 , // previously PE_11 
+*/
+
 
 DigitalOut myled1(LED1);
 DigitalOut myled2(LED2);
 
+void channelChangeMode (void)
+{
+  // NEEDS fixed to accept two digit number
+  #define   RF_CHANNEL_SIZE 2
+  
+    char stayInWhile = 1;
+    char receivedChannelCharacter;
+    int rf_channel = 2400;
+    int rf_channel_temp = 0;
+    char rf_channel_char[RF_CHANNEL_SIZE];
+    int rf_channelCnt = 0;
+    
+    pc.printf("Channel menu\n\r");
+    pc.printf("select channel as XX between 01 and 82\n\r");
+    while(stayInWhile)
+    {
+        pc.printf("waiting for Channel\n\r");
+         if ( pc.readable() ) 
+         {
+            receivedChannelCharacter = pc.getc();
+
+            if (receivedChannelCharacter >= '1' && receivedChannelCharacter <= '9') // if received 0 through 9 load transmit buffer
+            {
+                rf_channel_char[rf_channelCnt++] = pc.getc();
+
+                pc.printf("received a, %d\n\r", (receivedChannelCharacter - '0'));
+                
+                // If the transmit buffer is full
+                if ( rf_channelCnt >= sizeof( RF_CHANNEL_SIZE ) ) 
+                {
+                    //checkChannelValue();
+                    rf_channel_temp = (rf_channel_char[0]-0x30) * 10;
+                    rf_channel_temp += (rf_channel_char[1]-0x30);
+                    
+                    if((rf_channel_temp >= 1) && (rf_channel_temp <= 82))
+                    { 
+                        pc.printf("received valid number\n\r");
+                        pc.printf("new channel, %d\n\r", rf_channel_temp);
+                        rf_channel = rf_channel + rf_channel_temp; 
+                        pc.printf("new channel, %d\n\r", rf_channel);
+                        my_nrf24l01p.setRfFrequency(rf_channel);
+                        wait(1);
+                        pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
+                        stayInWhile = 0; 
+                    }
+                    else 
+                    {
+                        pc.printf(" invalid RF channel number\n\r");
+                    }
+                    
+                }
+            }
+            else if (receivedChannelCharacter == 'q' ) // if received q, exit channel change
+            {
+                pc.printf("exiting  Channel change mode\n\r");
+                stayInWhile = 0; 
+            }
+            else
+            {
+                pc.printf(" invalid number\n\r");
+            }
+        }
+        wait(1);
+    }
+    pc.printf("exiting  Channel change mode\n\r");
+    
+}
+
 int main() {
 
 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
@@ -18,6 +97,7 @@
     char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
     int txDataCnt = 0;
     int rxDataCnt = 0;
+    char receivedTerminalCharacter;
 
     my_nrf24l01p.powerUp();
 
@@ -32,28 +112,49 @@
 
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
 
+    my_nrf24l01p.setAirDataRate(NRF24L01P_DATARATE_250_KBPS);
+    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
+
     my_nrf24l01p.setReceiveMode();
     my_nrf24l01p.enable();
 
     while (1) {
 
         // If we've received anything over the host serial link...
-        if ( pc.readable() ) {
+        if ( pc.readable() ) 
+        {
 
-            // ...add it to the transmit buffer
-            txData[txDataCnt++] = pc.getc();
-
-            // If the transmit buffer is full
-            if ( txDataCnt >= sizeof( txData ) ) {
+            receivedTerminalCharacter = pc.getc();
+            
+            if (receivedTerminalCharacter >= '0' && receivedTerminalCharacter <= '9') // if received 0 through 9 load transmit buffer
+            {    // ...add it to the transmit buffer
+                txData[txDataCnt++] = pc.getc();
 
-                // Send the transmitbuffer via the nRF24L01+
-                my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
+                // If the transmit buffer is full
+                if ( txDataCnt >= sizeof( txData ) ) 
+                {
+    
+                    // Send the transmitbuffer via the nRF24L01+
+                    my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
+    
+                    txDataCnt = 0;
+                }
 
-                txDataCnt = 0;
+                // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
+                myled1 = !myled1;
+            } 
+            else if ((receivedTerminalCharacter == 'h') || (receivedTerminalCharacter == 'H')) 
+            {
+                pc.printf("Radio help menu\n\r");
+                pc.printf("Press c for channel: \n\r");
+                pc.printf("Press t for TX Power: \n\r");
+                pc.printf("Press d for datarate: \n\r");
+            } 
+            else if (receivedTerminalCharacter == 'c') 
+            {
+    
+                channelChangeMode();
             }
-
-            // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
-            myled1 = !myled1;
         }
 
         // If we've received anything in the nRF24L01+...
diff -r 5be2682710c6 -r 945fa201ce19 mbed.bld
--- a/mbed.bld	Wed Jan 19 23:53:19 2011 +0000
+++ b/mbed.bld	Fri Jun 15 12:33:52 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
+https://os.mbed.com/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file