-
Notifications
You must be signed in to change notification settings - Fork 11
/
arduino-at86rf233.ino
73 lines (61 loc) · 1.75 KB
/
arduino-at86rf233.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
67
68
69
70
71
72
73
#include <SPI.h>
#include "at86rf2xx.h"
int received = 0;
int IRQ = 2;
int RESET = 8;
int SLP_TR = 7;
int SEL = 6;
void setup() {
Serial.begin(115200);
at86rf2xx.init(SEL, IRQ, SLP_TR, RESET);
at86rf2xx.set_chan(26); // set channel to 26
}
void loop() {
if (at86rf2xx.events)
at86rf2xx_eventHandler();
return;
}
void at86rf2xx_eventHandler() {
/* One less event to handle! */
at86rf2xx.events--;
/* If transceiver is sleeping register access is impossible and frames are
* lost anyway, so return immediately.
*/
byte state = at86rf2xx.get_status();
if(state == AT86RF2XX_STATE_SLEEP)
return;
/* read (consume) device status */
byte irq_mask = at86rf2xx.reg_read(AT86RF2XX_REG__IRQ_STATUS);
/* Incoming radio frame! */
if (irq_mask & AT86RF2XX_IRQ_STATUS_MASK__RX_START)
Serial.println("[at86rf2xx] EVT - RX_START");
/* Done receiving radio frame; call our receive_data function.
*/
if (irq_mask & AT86RF2XX_IRQ_STATUS_MASK__TRX_END)
{
if(state == AT86RF2XX_STATE_RX_AACK_ON || state == AT86RF2XX_STATE_BUSY_RX_AACK) {
Serial.println("[at86rf2xx] EVT - RX_END");
at86rf2xx_receive_data();
}
}
}
void at86rf2xx_receive_data() {
/* print the length of the frame
* (including the header)
*/
size_t pkt_len = at86rf2xx.rx_len();
Serial.print("Frame length: ");
Serial.print(pkt_len);
Serial.println(" bytes");
/* Print the frame, byte for byte */
Serial.println("Frame dump (ASCII):");
uint8_t data[pkt_len];
at86rf2xx.rx_read(data, pkt_len, 0);
for (int d=0; d<pkt_len; d++)
Serial.print((char)data[d]);
Serial.println();
/* How many frames is this so far? */
Serial.print("[[Total frames received: ");
Serial.print(++received);
Serial.println("]]\n");
}