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.
Dependencies: nRF24L01P_Hello_World nRF24L01P
main.cpp
00001 #include "main.h" 00002 #include "mbed.h" 00003 #include "nRF24L01P.h" 00004 #include "circularBuffer.h" 00005 00006 UnbufferedSerial pc(USBTX, USBRX, 115200); // tx, rx, baudrate 00007 00008 nRF24L01P my_nrf24l01p(SPI3_MOSI, SPI3_MISO, SPI3_SCLK, CSN, CE, IRQ); // mosi, miso, sck, csn, ce, irq 00009 00010 DigitalOut myled1(D4); 00011 DigitalOut myled2(D5); 00012 00013 char sendFlag = 0; 00014 00015 int main() 00016 { 00017 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's 00018 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) 00019 // only handles 4 byte transfers in the ATMega code. 00020 char txData[TRANSFERT_SIZE]; 00021 00022 //Interruption sur réception Port Série 00023 pc.attach(&usbRxInterrupt, SerialBase::RxIrq); 00024 00025 00026 my_nrf24l01p.powerUp(); 00027 00028 //Configuration nRF24101P 00029 my_nrf24l01p.setRfFrequency(NRF24L01P_MIN_RF_FREQUENCY); 00030 my_nrf24l01p.setAirDataRate(NRF24L01P_DATARATE_2_MBPS); 00031 my_nrf24l01p.setRfOutputPower(-6); 00032 my_nrf24l01p.setTxAddress(0xFFA); 00033 my_nrf24l01p.setRxAddress(0xFFE); 00034 my_nrf24l01p.setTransferSize(TRANSFERT_SIZE); 00035 my_nrf24l01p.setTransmitMode(); 00036 00037 my_nrf24l01p.enable(); 00038 00039 00040 //Infinite Loop 00041 while (1) 00042 { 00043 // Si une trame est prête (4 octets) 00044 if (sendFlag) 00045 { 00046 sendFlag = 0; 00047 int i; 00048 00049 //On récupère la trame du buffer 00050 for (i = 0; i < TRANSFERT_SIZE; i++) 00051 txData[i] = cbTxGetOne(); 00052 00053 // Send the transmitbuffer via the nRF24L01+ 00054 my_nrf24l01p.write(NRF24L01P_PIPE_P0, txData, TRANSFERT_SIZE); 00055 00056 // Toggle LED1 (to help debug Host -> nRF24L01+ communication) 00057 myled1 = !myled1; 00058 } 00059 } 00060 } 00061 00062 void usbRxInterrupt() 00063 { 00064 //On a reçu un octet, on le récupère et on le met dans le buffer 00065 char c; 00066 if(pc.read(&c, 1)) 00067 { 00068 cbTxAddOne(c); 00069 //S'il y a 4 octets dans le buffer, on peut les envoyer (passage du flag à 1) 00070 if (cbTxGetDataSize() >= 4) 00071 sendFlag = 1; 00072 } 00073 }
Generated on Wed Jul 13 2022 03:07:10 by
1.7.2