Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
062d8334
Commit
062d8334
authored
Jul 08, 2011
by
maniacbug
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now both roles use the IRQ. Thanks to Mike Denzien for testing & troubleshooting.
parent
85495668
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
42 deletions
+53
-42
examples/pingpair_irq/pingpair_irq.pde
examples/pingpair_irq/pingpair_irq.pde
+53
-42
No files found.
examples/pingpair_irq/pingpair_irq.pde
View file @
062d8334
...
@@ -85,12 +85,6 @@ void setup(void)
...
@@ -85,12 +85,6 @@ void setup(void)
printf
(
"
\n\r
RF24/examples/pingpair_irq/
\n\r
"
);
printf
(
"
\n\r
RF24/examples/pingpair_irq/
\n\r
"
);
printf
(
"ROLE: %s
\n\r
"
,
role_friendly_name
[
role
]);
printf
(
"ROLE: %s
\n\r
"
,
role_friendly_name
[
role
]);
//
// Attach interrupt handler to interrupt #0 (using pin 2)
//
attachInterrupt
(
0
,
check_radio
,
FALLING
);
//
//
// Setup and configure rf radio
// Setup and configure rf radio
//
//
...
@@ -100,14 +94,17 @@ void setup(void)
...
@@ -100,14 +94,17 @@ void setup(void)
// We will be using the Ack Payload feature, so please enable it
// We will be using the Ack Payload feature, so please enable it
radio
.
enableAckPayload
();
radio
.
enableAckPayload
();
// Pick a high channel
// Optional: Increase CRC length for improved reliability
radio
.
setCRCLength
(
RF24_CRC_16
);
// Optional: Pick a high channel
radio
.
setChannel
(
110
);
radio
.
setChannel
(
110
);
//
//
// Open pipes to other nodes for communication
// Open pipes to other nodes for communication
//
//
// This simple sketch opens a single pipe
s
for these two nodes to communicate
// This simple sketch opens a single pipe for these two nodes to communicate
// back and forth. One listens on it, the other talks to it.
// back and forth. One listens on it, the other talks to it.
if
(
role
==
role_sender
)
if
(
role
==
role_sender
)
...
@@ -131,13 +128,19 @@ void setup(void)
...
@@ -131,13 +128,19 @@ void setup(void)
//
//
radio
.
printDetails
();
radio
.
printDetails
();
//
// Attach interrupt handler to interrupt #0 (using pin 2)
// on BOTH the sender and receiver
//
attachInterrupt
(
0
,
check_radio
,
FALLING
);
}
}
static
uint32_t
message_count
=
0
;
static
uint32_t
message_count
=
0
;
void
loop
(
void
)
void
loop
(
void
)
{
{
//
//
// Sender role. Repeatedly send the current time
// Sender role. Repeatedly send the current time
//
//
...
@@ -152,34 +155,10 @@ void loop(void)
...
@@ -152,34 +155,10 @@ void loop(void)
// Try again soon
// Try again soon
delay
(
2000
);
delay
(
2000
);
}
}
//
//
// Receiver role
. Receive each packet, dump it out, add ack payload for next time
// Receiver role
: Does nothing! All the work is in IRQ
//
//
if
(
role
==
role_receiver
)
{
// if there is data ready
if
(
radio
.
available
()
)
{
// Dump the payloads until we've gotten everything
static
unsigned
long
got_time
;
boolean
done
=
false
;
while
(
!
done
)
{
// Fetch the payload, and see if this was the last one.
done
=
radio
.
read
(
&
got_time
,
sizeof
(
unsigned
long
)
);
// Spew it
printf
(
"Got payload %lu
\n
"
,
got_time
);
}
// Add an ack packet for the next time around. This is a simple
// packet counter
radio
.
writeAckPayload
(
1
,
&
message_count
,
sizeof
(
message_count
)
);
++
message_count
;
}
}
}
}
...
@@ -188,23 +167,55 @@ void check_radio(void)
...
@@ -188,23 +167,55 @@ void check_radio(void)
// What happened?
// What happened?
bool
tx
,
fail
,
rx
;
bool
tx
,
fail
,
rx
;
radio
.
whatHappened
(
tx
,
fail
,
rx
);
radio
.
whatHappened
(
tx
,
fail
,
rx
);
// Have we successfully transmitted?
if
(
tx
)
if
(
tx
)
{
{
radio
.
powerDown
();
if
(
role
==
role_sender
)
printf
(
"Send:OK
\n\r
"
);
printf
(
"Send:OK
\n\r
"
);
if
(
role
==
role_receiver
)
printf
(
"Ack Payload:Sent
\n\r
"
);
}
}
// Have we failed to transmit?
if
(
fail
)
if
(
fail
)
{
{
radio
.
powerDown
();
if
(
role
==
role_sender
)
printf
(
"Send:Failed
\n\r
"
);
printf
(
"Send:Failed
\n\r
"
);
if
(
role
==
role_receiver
)
printf
(
"Ack Payload:Failed
\n\r
"
);
}
}
// Transmitter can power down for now, because
// the transmission is done.
if
(
(
tx
||
fail
)
&&
(
role
==
role_sender
)
)
radio
.
powerDown
();
// Did we receive a message?
if
(
rx
)
if
(
rx
)
{
{
radio
.
read
(
&
message_count
,
sizeof
(
message_count
));
// If we're the sender, we've received an ack payload
printf
(
"Ack:%lu
\n\r
"
,
message_count
);
if
(
role
==
role_sender
)
{
radio
.
read
(
&
message_count
,
sizeof
(
message_count
));
printf
(
"Ack:%lu
\n\r
"
,
message_count
);
}
// If we're the receiver, we've received a time message
if
(
role
==
role_receiver
)
{
// Get this payload and dump it
static
unsigned
long
got_time
;
radio
.
read
(
&
got_time
,
sizeof
(
got_time
)
);
printf
(
"Got payload %lu
\n\r
"
,
got_time
);
// Add an ack packet for the next time around. This is a simple
// packet counter
radio
.
writeAckPayload
(
1
,
&
message_count
,
sizeof
(
message_count
)
);
++
message_count
;
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment