Testing getting PJON working on mbed https://github.com/gioblu/PJON

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
earlz
Date:
Sat Jan 16 15:51:23 2016 +0000
Parent:
1:bd0ee507dd4c
Commit message:
Attempting to make things work, but it currently just freezes for some reason

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
pjon.cpp Show annotated file Show diff for this revision Revisions of this file
pjon.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jan 10 09:41:00 2016 +0000
+++ b/main.cpp	Sat Jan 16 15:51:23 2016 +0000
@@ -23,7 +23,7 @@
 int fail;
 
 // network(Arduino pin used, selected device id)
-PJON network(p13, 45);
+PJON network(p21, 45);
 Serial serial(USBTX, USBRX);
 Timer timer;
 int packet;
@@ -37,6 +37,7 @@
 }
 
 void loop() {
+  Timer t2;
   long time = timer.read_ms();
   while(timer.read_ms() - time < 10000) {
  
@@ -54,7 +55,7 @@
       busy++;
     if(response == FAIL)
       fail++;
-    wait_us(14);
+    wait_us(50);
   }
   
   serial.printf("Absolute com speed: ");
--- a/pjon.cpp	Sun Jan 10 09:41:00 2016 +0000
+++ b/pjon.cpp	Sat Jan 16 15:51:23 2016 +0000
@@ -222,11 +222,22 @@
 
   /* Receive byte for an initial BIT_SPACER bit + standard bit total duration.
      (freak condition used to avoid micros() overflow bug) */
-  while(response == FAIL && !(t.read_us() >= BIT_SPACER + BIT_WIDTH))
+     int time = 0;
+  while(response == FAIL && !(t.read_us() >= BIT_SPACER + BIT_WIDTH)){
     response = this->receive_byte();
+if(t.read_us() >= 101 && t.read_us() <= time){
+                DigitalOut myled2(LED4);
+    myled2 = 1;
+}
+time = t.read_us();
+    }
 
   t.stop();
-  if (response == ACK || response == NAK) return response;
+  if (response == ACK || response == NAK) {
+      DigitalOut myled(LED2);
+    myled = 1;
+      return response;
+    }
 
   return FAIL;
 };
@@ -361,13 +372,16 @@
   /* Do nothing until the pin stops to be HIGH or passed more time than
      BIT_SPACER duration (freak condition used to avoid micros() overflow bug) */ //MBED needed?
   while (_input_pin && !(t.read_us() >= BIT_SPACER));
+
   /* Save how much time passed */
   time = t.read_us();
   /* is for sure less than BIT_SPACER, and if is more than ACCEPTANCE
      (a minimum HIGH duration) and what is coming after is a LOW bit
      probably a byte is coming so try to receive it. */
-     t.stop();
+  t.stop();
   if(time >= ACCEPTANCE && !this->syncronization_bit()){
+    DigitalOut myled(LED3);
+    myled = 1;
     return (int)this->read_byte();
   }
 
--- a/pjon.h	Sun Jan 10 09:41:00 2016 +0000
+++ b/pjon.h	Sat Jan 16 15:51:23 2016 +0000
@@ -64,11 +64,16 @@
   #define  COMPATIBILITY_MODE true
 
 //mbed (needs tweaking)
-      #define BIT_WIDTH 45
-      #define BIT_SPACER 115
-      #define ACCEPTANCE 39
-      #define READ_DELAY 25
-
+/*
+      #define BIT_WIDTH 52
+      #define BIT_SPACER 121
+      #define ACCEPTANCE 51
+      #define READ_DELAY 29
+  */
+       #define BIT_WIDTH 45
+      #define BIT_SPACER 113
+      #define ACCEPTANCE 45
+      #define READ_DELAY 23    
   /* The following constants setup are quite conservative and determined only
      with a huge amount of time and blind testing (without oscilloscope)
      tweaking values and analysing results. Theese can be changed to obtain
@@ -148,15 +153,18 @@
   uint8_t device_id;
   char *content;
   uint8_t length;
-  unsigned long registration;
+  uint32_t registration;
   int state;
-  unsigned long timing;
+  uint32_t timing;
 };
 
 typedef void (* receiver)(uint8_t length, uint8_t *payload);
 typedef void (* pjon_error)(uint8_t code, uint8_t data);
 
-static void dummy_error_handler(uint8_t code, uint8_t data) {};
+static void dummy_error_handler(uint8_t code, uint8_t data) {
+    DigitalOut myled(LED1);
+    myled = 1;
+    };
 
 class PJON {