Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 RawSerial pc(PA_2, PA_3,9600 ); 00004 00005 00006 nRF24L01P my_nrf24l01p(D11, D12, D13, D10, D9,D8); // mosi, miso, sck, csn, ce, irq 00007 //nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq 00008 00009 //DigitalOut myled1(LED1); 00010 //DigitalOut myled2(D3); 00011 00012 int main() { 00013 00014 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's 00015 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) 00016 // only handles 4 byte transfers in the ATMega code. 00017 #define TRANSFER_SIZE 4 00018 00019 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; 00020 int txDataCnt = 0; 00021 int rxDataCnt = 0; 00022 int i=0; 00023 my_nrf24l01p.powerUp(); 00024 my_nrf24l01p.setRfFrequency(NRF24L01P_MIN_RF_FREQUENCY);//2400-2525 00025 my_nrf24l01p.setRfOutputPower(NRF24L01P_TX_PWR_ZERO_DB);//mAX 0 -6 -12 -18 00026 my_nrf24l01p.setAirDataRate(NRF24L01P_DATARATE_250_KBPS);//250k,1000,2000K 00027 // Display the (default) setup of the nRF24L01+ chip 00028 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00029 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00030 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00031 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00032 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00033 00034 pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); 00035 my_nrf24l01p.setTransferSize( TRANSFER_SIZE );//mAX 4 00036 00037 my_nrf24l01p.setReceiveMode(); 00038 my_nrf24l01p.enable(); 00039 00040 while (1) { 00041 00042 // If we've received anything over the host serial link... 00043 if ( pc.readable() ) { 00044 00045 // ...add it to the transmit buffer 00046 txData[txDataCnt++] = pc.getc(); 00047 00048 // If the transmit buffer is full 00049 if ( txDataCnt >= sizeof( txData ) ) { 00050 00051 // Send the transmitbuffer via the nRF24L01+ 00052 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); 00053 00054 txDataCnt = 0; 00055 } 00056 00057 // Toggle LED1 (to help debug Host -> nRF24L01+ communication) 00058 // myled1 = !myled1; 00059 } 00060 txData[0]='A'; 00061 txData[1]='B'; 00062 txData[2]='C'; 00063 txData[3]='0' + (i++ & 0x0f); 00064 #if defined ( TARGET_NUCLEO_L053R8 ) 00065 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, 4 ); 00066 #endif 00067 // If we've received anything in the nRF24L01+... 00068 if ( my_nrf24l01p.readable() ) { 00069 00070 // ...read the data into the receive buffer 00071 rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); 00072 00073 // Display the receive buffer contents via the host serial link 00074 for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { 00075 00076 pc.putc( rxData[i] ); 00077 } 00078 00079 // Toggle LED2 (to help debug nRF24L01+ -> Host communication) 00080 // myled1 = !myled1; 00081 } 00082 } 00083 }
Generated on Tue Jul 26 2022 13:14:27 by
1.7.2