NRF
Dependencies: NRF2401P
main.cpp@0:13c54823e005, 2015-06-12 (annotated)
- Committer:
- Woffle
- Date:
- Fri Jun 12 11:42:36 2015 +0000
- Revision:
- 0:13c54823e005
Working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Woffle | 0:13c54823e005 | 1 | #include "mbed.h" |
Woffle | 0:13c54823e005 | 2 | #include "NRF2401P.h" |
Woffle | 0:13c54823e005 | 3 | #include "nRF24l01.h" |
Woffle | 0:13c54823e005 | 4 | |
Woffle | 0:13c54823e005 | 5 | int main(){ |
Woffle | 0:13c54823e005 | 6 | |
Woffle | 0:13c54823e005 | 7 | long long addr1=0xAB01CD; // setup address - any 5 byte number - same as TX |
Woffle | 0:13c54823e005 | 8 | int channel =0x10; // [0-126] setup channel, must be same as TX |
Woffle | 0:13c54823e005 | 9 | bool txOK; |
Woffle | 0:13c54823e005 | 10 | char msg[32]; |
Woffle | 0:13c54823e005 | 11 | char ackData[32]; |
Woffle | 0:13c54823e005 | 12 | char len; |
Woffle | 0:13c54823e005 | 13 | |
Woffle | 0:13c54823e005 | 14 | // Setup |
Woffle | 0:13c54823e005 | 15 | NRF2401P nrf1(PTD2,PTD3, PTD1,PTD5,PTD0); //mosi, miso, sclk, csn, ce) |
Woffle | 0:13c54823e005 | 16 | nrf1.quickRxSetup(channel, addr1); // sets nrf24l01+ as receiver, using pipe 1 |
Woffle | 0:13c54823e005 | 17 | |
Woffle | 0:13c54823e005 | 18 | printf("Set up complete!\n\r"); |
Woffle | 0:13c54823e005 | 19 | |
Woffle | 0:13c54823e005 | 20 | // set ack data |
Woffle | 0:13c54823e005 | 21 | sprintf(ackData,"Acknowledge data"); |
Woffle | 0:13c54823e005 | 22 | |
Woffle | 0:13c54823e005 | 23 | printf("Ack data set.\n\r"); |
Woffle | 0:13c54823e005 | 24 | |
Woffle | 0:13c54823e005 | 25 | while (1) { |
Woffle | 0:13c54823e005 | 26 | // receive |
Woffle | 0:13c54823e005 | 27 | while (! nrf1.isRxData()); // note this blocks until RX data |
Woffle | 0:13c54823e005 | 28 | |
Woffle | 0:13c54823e005 | 29 | len= nrf1.getRxData(msg); // gets the message, len is length of msg |
Woffle | 0:13c54823e005 | 30 | msg[len] = 0; |
Woffle | 0:13c54823e005 | 31 | printf("%s",msg); |
Woffle | 0:13c54823e005 | 32 | nrf1.acknowledgeData(ackData, strlen(ackData),1); // ack for pipe 1 |
Woffle | 0:13c54823e005 | 33 | } |
Woffle | 0:13c54823e005 | 34 | } |