see: https://developer.mbed.org/users/okini3939/notebook/necnfc/

Dependencies:   NECnfc mbed

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Tue Sep 15 06:33:01 2015 +0000
Commit message:
sample build;

Changed in this revision

NECnfc.lib Show annotated file Show diff for this revision Revisions of this file
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
diff -r 000000000000 -r b5fa611b8d7d NECnfc.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NECnfc.lib	Tue Sep 15 06:33:01 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/okini3939/code/NECnfc/#07e752ff8dce
diff -r 000000000000 -r b5fa611b8d7d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Sep 15 06:33:01 2015 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+#include "NECnfc.h"
+
+DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);
+Serial pc(USBTX, USBRX);
+NECnfc rf(p9, p10, p13, p14, p15, 38400, NECnfc::TYPE_920MHz); // tx, rx, reset, wakeup, mode
+DigitalOut rts(p11);
+Ticker timer;
+
+void isr_recv () {
+    char buf[NEC_MAXLENGTH + 1];
+    int i, dest, src;
+    i = rf.readData(&dest, &src, buf, sizeof(buf));
+    if (i <= 0) return;
+    buf[i] = 0;
+    printf("recv to:%08x from:%08x '%s'\r\n", dest, src, buf);
+    led4 = !led4;
+}
+
+int main() {
+    Timer t;
+    unsigned int id;
+
+    rts = 0;
+    led1 = 1;
+    pc.baud(115200);
+    pc.printf("*** NEC\r\n");
+    wait(0.5);
+
+    rf.attach(&isr_recv);
+    rf.setRfConfig(NECnfc::PWR_MAX, 24, NECnfc::BAUD_50k);
+
+    id = rf.getId();
+    pc.printf(" id %08x\r\n", id);
+
+    t.start();
+    while(1) {
+        rf.poll();
+
+        if (pc.readable()) {
+            char c = pc.getc();
+            if (c == ' ') {
+                led2 = 1;
+                rf.send(NECnfc::NECMSG_SEND_NOACK, NEC_DUMMYID, "Hello mbed", 10);
+            }
+        }
+
+        if (t.read() >= 5) {
+            led3 = 1;
+            t.reset();
+            rf.send(NECnfc::NECMSG_SEND_NOACK, NEC_DUMMYID, "Hello World", 11);
+        }
+
+        led1 = !led1;
+        led2 = 0;
+        led3 = 0;
+        wait(0.1);
+    }
+}
diff -r 000000000000 -r b5fa611b8d7d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Sep 15 06:33:01 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf
\ No newline at end of file