SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | * Project: nRF905 AVR/Arduino Library/Driver | |
3 | * Author: Zak Kemble, contact@zakkemble.co.uk | |
4 | * Copyright: (C) 2013 by Zak Kemble | |
5 | * License: GNU GPL v3 (see License.txt) | |
6 | * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/ | |
7 | */ | |
8 | ||
9 | /* | |
10 | * Wait for data and reply. | |
11 | * Output power is set to the lowest setting, receive sensitivity is lowered. | |
12 | * | |
13 | * 7 -> CE | |
14 | * 8 -> PWR | |
15 | * 9 -> TXE | |
16 | * 2 -> CD | |
17 | * 3 -> DR | |
18 | * 10 -> CSN | |
19 | * 12 -> SO | |
20 | * 11 -> SI | |
21 | * 13 -> SCK | |
22 | */ | |
23 | ||
24 | #include <nRF905.h> | |
25 | #include <SPI.h> | |
26 | ||
27 | - | #define RXADDR {0x58, 0x6F, 0x2E, 0x10} // Address of this device (4 bytes) |
27 | + | |
28 | - | #define TXADDR {0xFE, 0x4C, 0xA6, 0xE5} // Address of device to send to (4 bytes) |
28 | + | |
29 | // Start up | |
30 | nRF905_init(); | |
31 | ||
32 | // Put into receive mode | |
33 | nRF905_receive(); | |
34 | - | |
34 | + | |
35 | - | // Set address of this device |
35 | + | |
36 | - | byte addr[] = RXADDR; |
36 | + | |
37 | - | nRF905_setRXAddress(addr); |
37 | + | |
38 | } | |
39 | - | // Lowest transmit level -10db |
39 | + | |
40 | - | nRF905_setTransmitPower(NRF905_PWR_n10); |
40 | + | |
41 | { | |
42 | - | // Reduce receive sensitivity to save a few mA |
42 | + | |
43 | - | nRF905_setLowRxPower(NRF905_LOW_RX_ENABLE); |
43 | + | |
44 | // Make buffer for data | |
45 | char buffer[NRF905_MAX_PAYLOAD]; | |
46 | ||
47 | // Wait for data | |
48 | while(!nRF905_getData(buffer, sizeof(buffer))); | |
49 | ||
50 | Serial.println(F("Got ping")); | |
51 | ||
52 | // Set payload data (reply with data received) | |
53 | nRF905_setData(buffer, sizeof(buffer)); | |
54 | ||
55 | Serial.println(F("Sending reply...")); | |
56 | ||
57 | // Send payload (send fails if other transmissions are going on, keep trying until success) | |
58 | while(!nRF905_send()); | |
59 | ||
60 | // Put back into receive mode | |
61 | nRF905_receive(); | |
62 | ||
63 | Serial.println(F("Reply sent")); | |
64 | ||
65 | - | // Set address of device to send to |
65 | + | |
66 | - | byte addr[] = TXADDR; |
66 | + | |
67 | - | nRF905_setTXAddress(addr); |
67 | + | |
68 | Serial.println(); | |
69 | ||
70 | // Printout ping contents | |
71 | - | |
71 | + | |
72 | ||
73 | if(strncmp(buffer, "test test", sizeof(buffer)) == 0) | |
74 | Serial.println("OK"); | |
75 | else | |
76 | Serial.println("Fail"); | |
77 | } |