nRF_24 module library for MBED / Emitter Test Program

Dependencies:   MOD24_NRF mbed

Revision:
1:fbce251f7d0c
Parent:
0:96c89b4dc711
--- a/main.cpp	Tue Dec 08 12:10:01 2020 +0000
+++ b/main.cpp	Thu Sep 16 14:14:30 2021 +0000
@@ -1,66 +1,56 @@
-#include "mbed.h"
-#include "arm_math.h"
-/* Include mbed-dsp libraries */
-#include "dsp.h"
-#include "arm_common_tables.h"
-#include "arm_const_structs.h"
-
-#define SAMPLES                 512             /* 256 real party and 256 imaginary parts */
-#define FFT_SIZE                SAMPLES / 2     /* FFT size is always the same size as we have samples, so 256 in our case */
- 
-float32_t Input[SAMPLES];
-float32_t Output[FFT_SIZE];
-bool      trig=0;
-int       indice = 0;
+/****************************************************************************/
+/*  Test MOD-24LR / nrf24L01                                                */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Brochage                                                                */
+/*      TO COMPLETE                                                         */
+/****************************************************************************/
+/*  Test réalisé sur Nucléo-F411RE                                          */
+/****************************************************************************/
 
-DigitalOut myled(LED1);
-AnalogIn   myADC(A0);
-AnalogOut  myDAC(A2);
-Serial     pc(USBTX, USBRX);
-Ticker     timer;
- 
-void sample(){
-    myled = 1;
-    if(indice < SAMPLES){
-        Input[indice] = myADC.read() - 0.5f;    //Real part NB removing DC offset
-        Input[indice + 1] = 0;                  //Imaginary Part set to zero
-        indice += 2;
-    }
-    else{ trig = 0; }
-    myled = 0;
-}
- 
+#include "mbed.h"
+#include "MOD24_NRF.h"
+#define TRANSFER_SIZE   4
+
+nRF24L01P       my_mod(D11, D12, D13, D7, D8, D5);
+
+Serial          pc(USBTX, USBRX);
+DigitalIn       my_bp(USER_BUTTON);
+
+char k;
+char    dataToSend[TRANSFER_SIZE] = {0xAA, 0x01, 0x10, 0xF0};
+char    dataReceived[TRANSFER_SIZE] = {0};
+
 int main() {
-    float maxValue;            // Max FFT value is stored here
-    uint32_t maxIndex;         // Index in Output array where max value is
+    pc.printf("Test\r\n");
+    my_mod.setRfFrequency(2400);
+    wait(0.1);
+    my_mod.powerUp();
+    
+    // Display the (default) setup of the nRF24L01+ chip
+    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_mod.getRfFrequency() );
+    pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_mod.getRfOutputPower() );
+    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_mod.getAirDataRate() );
+    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_mod.getTxAddress() );
+    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_mod.getRxAddress() );
 
+    pc.printf( "Type keys to test transfers:\r\n  (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
+
+    my_mod.setTransferSize( TRANSFER_SIZE );
+
+    my_mod.setReceiveMode();
+    my_mod.enable();
+    
     while(1) {
-        if(trig == 0){
-            timer.detach();
-            // Init the Complex FFT module, intFlag = 0, doBitReverse = 1
-            //NB using predefined arm_cfft_sR_f32_lenXXX, in this case XXX is 256
-            arm_cfft_f32(&arm_cfft_sR_f32_len256, Input, 0, 1);
- 
-            // Complex Magniture Module put results into Output(Half size of the Input)
-            arm_cmplx_mag_f32(Input, Output, FFT_SIZE);
-            Output[0] = 0;
-            //Calculates maxValue and returns corresponding value
-            arm_max_f32(Output, FFT_SIZE/2, &maxValue, &maxIndex);
-        
-            myDAC=1.0;     //SYNC Pulse to DAC Output
-            wait_us(20);    //Used on Oscilliscope set trigger level to the highest
-            myDAC=0.0;     //point on this pulse 
-    
-            for(int i=0; i < FFT_SIZE / 2; i++){
-                myDAC=(Output[i]) * 0.9;   // Scale to Max Value and scale to 90 / 100
-                wait_us(10);                //Each pulse of 10us is 50KHz/256 = 195Hz resolution
-            }
-            myDAC=0.0;
-            pc.printf("MAX = %lf, %d \r\n", maxValue, maxIndex);
-            wait(0.2);
-            trig = 1;
-            indice = 0;
-            timer.attach_us(&sample,40);      //20us 50KHz sampling rate
+        if(my_bp == 1){
+            my_mod.setRfFrequency(2400);
+        }
+        else{
+            my_mod.setRfFrequency(2500);
         }
+        my_mod.write( NRF24L01P_PIPE_P0, dataToSend, TRANSFER_SIZE );
+        pc.printf( "SENDED\r\n");
+        wait(1);        
     }
-}
\ No newline at end of file
+}