Library for nRF24 module communications

Dependents:   Arts_DMX512_carteV3_MIDI_nRF IeTI_nRF24

Files at this revision

API Documentation at this revision

Comitter:
villemejane
Date:
Sun Dec 12 12:42:12 2021 +0000
Commit message:
Library for nRF24 module communications

Changed in this revision

nRF24.cpp Show annotated file Show diff for this revision Revisions of this file
nRF24.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 659c6ffdd56c nRF24.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24.cpp	Sun Dec 12 12:42:12 2021 +0000
@@ -0,0 +1,62 @@
+/****************************************************************************/
+/*  nRF24L1 module library                                                  */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - nRF24.cpp file                                                */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 4th nov 2021                                  */
+/****************************************************************************/
+
+#include "nRF24.h"
+
+#define TRANSFER_SIZE   8
+
+nRF24L01P       nRF24_mod(D11, D12, D13, D10, D9, PB_8);
+// MOSI, MISO, SCK, CSN, CE, IRQ
+
+char k;
+char    dataToSend[TRANSFER_SIZE] = {0xAA, 0x01, 0x10, 0xF0,0xAA, 0x01, 0x10, 0xF0};
+char    dataReceived[TRANSFER_SIZE] = {0};
+char    rxDataCnt;
+
+
+// Fonction d'initialisation du module BT nRF24L01
+void initNRF24(){
+    nRF24_mod.powerUp();
+    wait_us(100000);
+    nRF24_mod.setAirDataRate(NRF24L01P_DATARATE_250_KBPS);
+    nRF24_mod.setRfFrequency(2400);
+    wait_us(100000);
+    debug_pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  nRF24_mod.getRfFrequency() );
+    debug_pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  nRF24_mod.getRfOutputPower() );
+    debug_pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", nRF24_mod.getAirDataRate() );
+    debug_pc.printf( "Transfers are grouped into %d characters\r\n", TRANSFER_SIZE );
+    nRF24_mod.setTransferSize( TRANSFER_SIZE );
+    nRF24_mod.setReceiveMode();
+    nRF24_mod.enable();
+}
+
+// Fonction de test du module BT nRF24L01
+void testNRF24(void){
+    /* Lecture donnée depuis nRF24 */
+    if ( nRF24_mod.readable() ) {
+
+        // ...read the data into the receive buffer
+        rxDataCnt = nRF24_mod.read( NRF24L01P_PIPE_P0, dataReceived, TRANSFER_SIZE);
+
+        // Display the receive buffer contents via the host serial link
+        debug_pc.printf("\tD = ");
+        for ( int i = 0; i < rxDataCnt; i++ ) {
+            debug_pc.printf(" %x \t", dataReceived[i]);
+        }
+        debug_pc.printf("\r\n");
+    }   
+    /* Transmission donnée depuis nRF24 */
+    if(bp_int == 0){
+        nRF24_mod.setRfFrequency(2400);
+        nRF24_mod.write( NRF24L01P_PIPE_P0, dataToSend, TRANSFER_SIZE );
+        debug_pc.printf( "SENDED\r\n");
+        wait_us(100000);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 659c6ffdd56c nRF24.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF24.h	Sun Dec 12 12:42:12 2021 +0000
@@ -0,0 +1,37 @@
+/****************************************************************************/
+/*  nRF24L1 module library                                                  */
+/****************************************************************************/
+/*  LEnsE / Julien VILLEMEJANE       /   Institut d'Optique Graduate School */
+/****************************************************************************/
+/*  Library - nRF24.h file                                                  */
+/****************************************************************************/
+/*  Tested on Nucleo-L476RG / 4th nov 2021                                  */
+/****************************************************************************/
+
+#ifndef     NRF24_H_INCLUDED
+#define     NRF24_H_INCLUDED
+
+#include    "mbed.h"
+#include    "MOD24_NRF.h"
+#define     TRANSFER_SIZE   8
+
+/* Entrées - Sorties */
+extern      nRF24L01P       nRF24_mod;
+// Debugage
+extern      Serial      debug_pc;
+extern      InterruptIn bp_int;
+
+// Transmission nrF24
+extern  char    k;
+extern  char    dataToSend[TRANSFER_SIZE];
+extern  char    dataReceived[TRANSFER_SIZE];
+extern  char    rxDataCnt;
+
+// Fonction d'initialisation du module BT nRF24L01
+void initNRF24();
+// Fonction de test du module BT nRF24L01
+void testNRF24(void);
+
+
+
+#endif
\ No newline at end of file