Advertisement
Guest User

Untitled

a guest
May 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include "mbed.h"
  2. #include "nRF24L01P.h"
  3.  
  4. Serial pc(USBTX, USBRX); // tx, rx
  5.  
  6. nRF24L01P my_nrf24l01p(PTD6, PTE3, PTE2, PTB8, PTB9, PTD0); // mosi, miso, sck, csn, ce, irq
  7.  
  8. DigitalOut myled1(LED1);
  9. DigitalOut myled2(LED2);
  10.  
  11. int main() {
  12.  
  13. // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
  14. // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
  15. // only handles 4 byte transfers in the ATMega code.
  16. #define TRANSFER_SIZE 4
  17.  
  18. char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
  19. int txDataCnt = 0;
  20. int rxDataCnt = 0;
  21.  
  22. my_nrf24l01p.powerUp();
  23.  
  24. // Display the (default) setup of the nRF24L01+ chip
  25. pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
  26. pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
  27. pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
  28. pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
  29. pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
  30. /*
  31. pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
  32.  
  33. my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
  34.  
  35. my_nrf24l01p.setReceiveMode();*/
  36. my_nrf24l01p.enable();
  37.  
  38. while (1) {
  39.  
  40. // If we've received anything in the nRF24L01+...
  41. if ( my_nrf24l01p.readable() ) {
  42.  
  43. // ...read the data into the receive buffer
  44. rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) );
  45.  
  46. // Display the receive buffer contents via the host serial link
  47. pc.printf( "Detected and printing message!\r\n" );
  48. for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) {
  49.  
  50. pc.putc( rxData[i] );
  51. }
  52.  
  53. // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
  54. pc.printf( "End Message\r\n");
  55.  
  56. myled2 = !myled2;
  57. }
  58. pc.printf( "Received Nothing!\r\n");
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement