Program to test nrF24 module / RF transmission

Dependencies:   MOD24_NRF nRF24

Committer:
villemejane
Date:
Thu Sep 23 12:33:38 2021 +0000
Revision:
0:4762540bcced
Child:
1:b96e529849d1
nRF24L01 module test program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
villemejane 0:4762540bcced 1 /****************************************************************************/
villemejane 0:4762540bcced 2 /* Test MOD-24LR / nrf24L01 */
villemejane 0:4762540bcced 3 /****************************************************************************/
villemejane 0:4762540bcced 4 /* LEnsE / Julien VILLEMEJANE / Institut d'Optique Graduate School */
villemejane 0:4762540bcced 5 /****************************************************************************/
villemejane 0:4762540bcced 6 /* Brochage */
villemejane 0:4762540bcced 7 /* TO COMPLETE */
villemejane 0:4762540bcced 8 /****************************************************************************/
villemejane 0:4762540bcced 9 /* Test réalisé sur Nucléo-F411RE */
villemejane 0:4762540bcced 10 /****************************************************************************/
villemejane 0:4762540bcced 11
villemejane 0:4762540bcced 12 #include "mbed.h"
villemejane 0:4762540bcced 13 #include "MOD24_NRF.h"
villemejane 0:4762540bcced 14 #define TRANSFER_SIZE 8
villemejane 0:4762540bcced 15
villemejane 0:4762540bcced 16 nRF24L01P my_mod(PC_12, PC_11, PC_10, PH_1, PH_0, PD_2);
villemejane 0:4762540bcced 17 // MOSI, MISO, SCK, CSN, CE, IRQ
villemejane 0:4762540bcced 18
villemejane 0:4762540bcced 19 Serial pc(USBTX, USBRX);
villemejane 0:4762540bcced 20 DigitalIn my_bp(USER_BUTTON);
villemejane 0:4762540bcced 21
villemejane 0:4762540bcced 22 char k;
villemejane 0:4762540bcced 23 char dataToSend[TRANSFER_SIZE] = {0xAA, 0x01, 0x10, 0xF0,0xAA, 0x01, 0x10, 0xF0};
villemejane 0:4762540bcced 24 char dataReceived[TRANSFER_SIZE] = {0};
villemejane 0:4762540bcced 25 char rxDataCnt;
villemejane 0:4762540bcced 26
villemejane 0:4762540bcced 27 int main() {
villemejane 0:4762540bcced 28 pc.printf("Test\r\n");
villemejane 0:4762540bcced 29 my_mod.setRfFrequency(2400);
villemejane 0:4762540bcced 30 wait_ms(100);
villemejane 0:4762540bcced 31 my_mod.powerUp();
villemejane 0:4762540bcced 32
villemejane 0:4762540bcced 33 // Display the (default) setup of the nRF24L01+ chip
villemejane 0:4762540bcced 34 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_mod.getRfFrequency() );
villemejane 0:4762540bcced 35 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_mod.getRfOutputPower() );
villemejane 0:4762540bcced 36 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_mod.getAirDataRate() );
villemejane 0:4762540bcced 37
villemejane 0:4762540bcced 38 pc.printf( "Transfers are grouped into %d characters\r\n", TRANSFER_SIZE );
villemejane 0:4762540bcced 39
villemejane 0:4762540bcced 40 my_mod.setTransferSize( TRANSFER_SIZE );
villemejane 0:4762540bcced 41
villemejane 0:4762540bcced 42 my_mod.setReceiveMode();
villemejane 0:4762540bcced 43 my_mod.enable();
villemejane 0:4762540bcced 44
villemejane 0:4762540bcced 45 while(1) {
villemejane 0:4762540bcced 46 if ( my_mod.readable() ) {
villemejane 0:4762540bcced 47
villemejane 0:4762540bcced 48 // ...read the data into the receive buffer
villemejane 0:4762540bcced 49 rxDataCnt = my_mod.read( NRF24L01P_PIPE_P0, dataReceived, TRANSFER_SIZE);
villemejane 0:4762540bcced 50
villemejane 0:4762540bcced 51 // Display the receive buffer contents via the host serial link
villemejane 0:4762540bcced 52 pc.printf("\tD = ");
villemejane 0:4762540bcced 53 for ( int i = 0; i < rxDataCnt; i++ ) {
villemejane 0:4762540bcced 54 pc.printf(" %x \t", dataReceived[i]);
villemejane 0:4762540bcced 55 }
villemejane 0:4762540bcced 56 pc.printf("\r\n");
villemejane 0:4762540bcced 57 }
villemejane 0:4762540bcced 58 if(my_bp == 0){
villemejane 0:4762540bcced 59 my_mod.setRfFrequency(2400);
villemejane 0:4762540bcced 60 my_mod.write( NRF24L01P_PIPE_P0, dataToSend, TRANSFER_SIZE );
villemejane 0:4762540bcced 61 pc.printf( "SENDED\r\n");
villemejane 0:4762540bcced 62 wait_ms(100);
villemejane 0:4762540bcced 63 }
villemejane 0:4762540bcced 64 }
villemejane 0:4762540bcced 65 }