Hello world example for the nRF2401A Library

Dependencies:   mbed nRF2401A

Files at this revision

API Documentation at this revision

Comitter:
TheChrisyd
Date:
Fri Oct 04 16:24:29 2013 +0000
Child:
1:fc964ee17649
Commit message:
First commit for week 1 update

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF2401A.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 04 16:24:29 2013 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "nRF2401A.h"
+
+// comment these out depending on the job of the mbed. If your only using one mbed leave both uncommented.
+#define TX
+#define RX
+
+DigitalOut  myled(LED1);
+#ifdef TX
+nRF2401A    rf1(p10, p11, p12, p13, p14);
+#endif
+#ifdef RX
+nRF2401A    rf2(p21, p22, p23, p24, p25);
+#endif
+
+Serial pc(USBTX, USBRX);
+
+int main() {
+
+    wait(0.005);
+
+    pc.printf("Hello nRF2401A\n\r");
+#ifdef TX    
+    rf1.setDataPayloadLength(4 << 3)
+       .setAddress(0x0, 0x0, 0xa6, 0xa6, 0xa6, 3 << 3)
+       .setCRCMode(nRF2401A::NO_CRC)
+       .setDataRate(nRF2401A::BIT_RATE_250KBITS)
+       .setChannel(0x02);
+       
+    rf1.printControlPacket(pc);
+
+#endif
+#ifdef RX   
+    rf2.setDataPayloadLength(4 << 3)
+       .setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3)
+       .setCRCMode(nRF2401A::NO_CRC)
+       .setDataRate(nRF2401A::BIT_RATE_250KBITS)
+       .setChannel(0x02);
+       
+    rf2.printControlPacket(pc);
+    
+#endif
+#ifdef TX    
+    rf1.flushControlPacket();
+#endif
+#ifdef RX
+    rf2.flushControlPacket();
+#endif
+#ifdef TX   
+    nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53};
+    uint8_t msg[] = {0x01, 0x01, 0x01, 0x01};
+    uint32_t *msg32 = (uint32_t *) msg;
+#endif
+      
+    while(1) {
+#ifdef TX             
+        rf1.sendMsg(rf2_addr, 3 << 3, msg, 4 << 3);
+        *msg32 += 1;
+#endif
+        myled = 1;
+        wait(0.25);
+#ifdef RX        
+        rf2.printDataPacket(pc);
+#endif           
+        myled = 0;
+        wait(0.25);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 04 16:24:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF2401A.lib	Fri Oct 04 16:24:29 2013 +0000
@@ -0,0 +1,1 @@
+nRF2401A#8c57f88ff574