iforce2d Chris
/
nRF24L01SimpleExample
Basic port of the gcopeland nRF24L01 library
main.cpp@2:75a5b58b2338, 2019-03-25 (annotated)
- Committer:
- iforce2d
- Date:
- Mon Mar 25 07:35:02 2019 +0000
- Revision:
- 2:75a5b58b2338
- Parent:
- 1:5be2682710c6
Basic port of gcopeland nRF24L01 library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Owen | 0:a51a6e7da590 | 1 | #include "mbed.h" |
iforce2d | 2:75a5b58b2338 | 2 | #include "nRF24L01.h" |
iforce2d | 2:75a5b58b2338 | 3 | #include "RF24.h" |
Owen | 0:a51a6e7da590 | 4 | |
iforce2d | 2:75a5b58b2338 | 5 | //Serial pc(USBTX, USBRX); // tx, rx |
iforce2d | 2:75a5b58b2338 | 6 | Serial pc(PA_9, PA_10); |
iforce2d | 2:75a5b58b2338 | 7 | |
iforce2d | 2:75a5b58b2338 | 8 | RF24 radio(PB_5, PB_4, PB_3, PB_7, PB_6); // mosi, miso, sck, csn, ce |
Owen | 0:a51a6e7da590 | 9 | |
iforce2d | 2:75a5b58b2338 | 10 | struct MyData { |
iforce2d | 2:75a5b58b2338 | 11 | float voltage; |
iforce2d | 2:75a5b58b2338 | 12 | float current; |
iforce2d | 2:75a5b58b2338 | 13 | }; |
iforce2d | 2:75a5b58b2338 | 14 | |
iforce2d | 2:75a5b58b2338 | 15 | MyData data; |
Owen | 0:a51a6e7da590 | 16 | |
iforce2d | 2:75a5b58b2338 | 17 | void resetData() |
iforce2d | 2:75a5b58b2338 | 18 | { |
iforce2d | 2:75a5b58b2338 | 19 | data.voltage = 12; |
iforce2d | 2:75a5b58b2338 | 20 | data.current = 34; |
iforce2d | 2:75a5b58b2338 | 21 | } |
iforce2d | 2:75a5b58b2338 | 22 | |
iforce2d | 2:75a5b58b2338 | 23 | const uint64_t pipeOut = 0xE8E8F0F0E1LL; |
Owen | 0:a51a6e7da590 | 24 | |
Owen | 0:a51a6e7da590 | 25 | int main() { |
iforce2d | 2:75a5b58b2338 | 26 | |
iforce2d | 2:75a5b58b2338 | 27 | resetData(); |
iforce2d | 2:75a5b58b2338 | 28 | |
iforce2d | 2:75a5b58b2338 | 29 | radio.begin(); |
iforce2d | 2:75a5b58b2338 | 30 | radio.setAutoAck(false); |
iforce2d | 2:75a5b58b2338 | 31 | radio.setDataRate(RF24_250KBPS); |
iforce2d | 2:75a5b58b2338 | 32 | radio.openWritingPipe(pipeOut); |
Owen | 0:a51a6e7da590 | 33 | |
iforce2d | 2:75a5b58b2338 | 34 | radio.printDetails(pc); |
Owen | 0:a51a6e7da590 | 35 | |
Owen | 0:a51a6e7da590 | 36 | while (1) { |
iforce2d | 2:75a5b58b2338 | 37 | |
iforce2d | 2:75a5b58b2338 | 38 | radio.write( (char*)&data, sizeof(data) ); |
iforce2d | 2:75a5b58b2338 | 39 | |
iforce2d | 2:75a5b58b2338 | 40 | //wait( 0.01 ); |
Owen | 0:a51a6e7da590 | 41 | } |
Owen | 0:a51a6e7da590 | 42 | } |