Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 9 months ago.
nRF24L01 to nRF24L01 not working
HI,
I have 2 FRDM K64f boards that have the nRF24L01 connected.
Using this library I have been trying to simply transmit a message typed on my pc through the board to the second board and print to another terminal.
The first code is for the board that is sending the message:
Transceiver
#include "mbed.h" #include "nRF24L01P.h" Serial pc(USBTX, USBRX); // tx, rx nRF24L01P my_nrf24l01p(PTD6, PTD7, PTD5, PTD4, PTC12, PTC18); DigitalOut myled(LED1); DigitalOut myled1(LED2); DigitalOut myled2(LED3); int main() { #define TRANSFER_SIZE 4 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; int txDataCnt = 0; int rxDataCnt = 0; my_nrf24l01p.powerUp(); my_nrf24l01p.setRfFrequency(2500); my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); my_nrf24l01p.setRxAddress(); my_nrf24l01p.setTxAddress(); my_nrf24l01p.setReceiveMode(); my_nrf24l01p.enable(); my_nrf24l01p.setRfFrequency(); pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); pc.printf( "nRF24L01+ Transfer Size : %d MHz\r\n", my_nrf24l01p.getTransferSize() ); pc.printf( "nRF24L01+ RX Address : %d \r\n", my_nrf24l01p.getRxAddress() ); pc.printf( "nRF24L01+ TxAddress : %d \r\n", my_nrf24l01p.getTxAddress() ); pc.printf("Transceiver"); while(1) { if ( pc.readable() ) { // ...add it to the transmit buffer txData[txDataCnt++] = pc.getc(); pc.printf("%d\r\n", txData); // If the transmit buffer is full if ( txDataCnt >= sizeof( txData ) ) { pc.printf("Sending Message"); // Send the transmitbuffer via the nRF24L01+ my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); pc.printf("Message Sent"); txDataCnt = 0; } pc.printf("Toggle Led"); // Toggle LED1 (to help debug Host -> nRF24L01+ communication) myled1 = !myled1; } } }
This code is for the board receiving it:
Receiver
#include "mbed.h" #include "nRF24L01P.h" Serial pc(USBTX, USBRX); // tx, rx nRF24L01P my_nrf24l01p(PTD6, PTD7, PTD5, PTD4, PTC12, PTC18); DigitalOut myled(LED1); DigitalOut myled1(LED2); DigitalOut myled2(LED3); int main() { #define TRANSFER_SIZE 4 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; int txDataCnt = 0; int rxDataCnt = 0; my_nrf24l01p.powerUp(); my_nrf24l01p.setRfFrequency(2500); my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); my_nrf24l01p.setRxAddress(); my_nrf24l01p.setTxAddress(); my_nrf24l01p.setReceiveMode(); my_nrf24l01p.enable(); my_nrf24l01p.setRfFrequency(); pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); pc.printf( "nRF24L01+ Transfer Size : %d MHz\r\n", my_nrf24l01p.getTransferSize() ); pc.printf( "nRF24L01+ RX Address : %d \r\n", my_nrf24l01p.getRxAddress() ); pc.printf( "nRF24L01+ TxAddress : %d \r\n", my_nrf24l01p.getTxAddress() ); pc.printf("Receiver"); while(1) { if(my_nrf24l01p.readable()){ myled = 0; myled1 = 1; pc.printf("Entered If Statement"); rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { pc.putc( rxData[i] ); pc.printf("Message Received: %d", rxData[i]); } }else{ myled=1; } } }
When I type the messages the first board prints out the confirmation the message is sending, but it is never received on the other board and never reaches the print statement to confirm the message has been sent.
I can not figure out what is causing this, any help would be appreciated?
Question relating to:
1 Answer
8 years, 9 months ago.
May be one must be use with my_nrf24l01p.setReceiveMode(); and the other with my_nrf24l01p.setTransmitMode();
because nrf are not full duplex... so from one must be wait to receive since the other is trying to send.
Not sure if the answer is the good one, but you can try...
Try sending a couple of random characters in line 45 before the while(1) and see if it transmits to the receiver.
e.g.
my_nrf24l01p.write( NRF24L01P_PIPE_P0, "ab", 2 );
posted by Paul Staron 01 Feb 2016Just tried this and nothing was received. Starting to think it may be something to do with the actual soldering of the component if nothing it being received at all.
posted by Jiffy Boogle 01 Feb 2016