-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnrf_recieve.ino
66 lines (51 loc) · 1.15 KB
/
nrf_recieve.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <SPI.h>
const int cs = 10;
const int ce = 9;
const int channel = 3;
const int addr = 0xB50000l; //101101010000000000000000
void setup() {
Serial.begin(115200);
NRF_init();
}
void loop() {
digitalWrite(cs, LOW);
SPI.transfer(0x07);
byte n = SPI.transfer(0x00);
digitalWrite(cs, HIGH);
Serial.println(n);
if (n && 00000010){
digitalWrite(ce, LOW);
digitalWrite(cs, LOW);
SPI.transfer(B01100001);
unsigned int i = SPI.transfer(0x00);
digitalWrite(cs, HIGH);
Serial.println(i);}
}
void NRF_init(){
pinMode(cs, OUTPUT);
pinMode(ce, OUTPUT);
digitalWrite(cs, HIGH);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
// set PRIM_RX
digitalWrite(cs, LOW);
SPI.transfer(0x00&B00100000);
SPI.transfer(1);
digitalWrite(cs, HIGH);
// set EN_RXADDR
digitalWrite(cs, LOW);
SPI.transfer(0x02&B00100000);
SPI.transfer(B11111100);
// set AW
digitalWrite(cs, LOW);
SPI.transfer(0x03&B00100000);
SPI.transfer(B01000000);
digitalWrite(cs, HIGH);
// set RX_ADDR_P0
digitalWrite(cs, LOW);
SPI.transfer(0x0A&B00100000);
SPI.transfer(addr);
digitalWrite(cs, HIGH);
// recieve
digitalWrite(ce, HIGH);
}