From d6fc89518a6a3a21d53823d83d2a8cf64957d678 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Mon, 28 Mar 2022 19:52:23 +0000
Subject: [PATCH] Added test interrupt code.

---
 documentation/project_progress.tex                                          |   38 ++++++++++++++++++
 firmware/debug_receiver_interrupt/receiver_interrupt/receiver_interrupt.ino |   40 ++++++++++++++++++++
 firmware/trigger_firmware/trigger_firmware.ino                              |    2 
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/documentation/project_progress.tex b/documentation/project_progress.tex
index 0338f55..15e43a9 100644
--- a/documentation/project_progress.tex
+++ b/documentation/project_progress.tex
@@ -60,7 +60,7 @@
 \end{figure}
 
 
-The connector has pinout shown in the data table. According to the \cite{productFamilyDatasheet}, pins 5 and 9 shoud be used for synchronization. From the pinout, pin number 8 could be used to power up electronics. However, no data about electrical characteristics of power supply is given (max current?).
+The connector has pinout shown in the data table. According to the \cite{productFamilyDatasheet}, pins 5 and 9 shoud be used for synchronization. From the pinout, pin number 8 could be used to power up electronics. However, no data about electrical characteristics of power supply is given (max current?). \textbf{The cables in use, have a red wire at pin 1.}
  
 
 
@@ -212,6 +212,42 @@
 radio.write( &dataToSend, sizeof(dataToSend) );
 \end{verbatim}
 
+\subsection{Debug receiver}
 
+To measure trigger delay and for other debugging purposes, A simple debug receiver can be programmed. On this receiver, the nRF21l01 must be connected the same way as on trasmitter. The following code works as debug interface. The code can also be a reference for receiver design.
+
+\begin{verbatim}
+#include <RF24_config.h>
+#include <nRF24L01.h>
+#include <RF24.h>
+#include <printf.h>
+
+RF24 radio(22, 21); // CE, CSN
+const byte address[6] = {'R','E','C','V', '1'};
+char val[4];
+
+void setup() {
+  Serial.begin(115200);
+  radio.begin();
+  radio.openReadingPipe(0, address);
+  radio.setPALevel(RF24_PA_MIN);
+  radio.startListening();
+
+}
+
+void loop() {
+  delay(5);
+  radio.startListening();
+  if ( radio.available()) {
+    while (radio.available()) {
+
+      radio.read(&val, sizeof(val));
+      Serial.print("Received = ");
+      Serial.println(val);
+    }
+  }
+
+}
+\end{verbatim}
 \end{document}
 
diff --git a/firmware/debug_receiver_interrupt/receiver_interrupt/receiver_interrupt.ino b/firmware/debug_receiver_interrupt/receiver_interrupt/receiver_interrupt.ino
new file mode 100644
index 0000000..ca5c040
--- /dev/null
+++ b/firmware/debug_receiver_interrupt/receiver_interrupt/receiver_interrupt.ino
@@ -0,0 +1,40 @@
+#include <RF24_config.h>
+#include <nRF24L01.h>
+#include <RF24.h>
+#include <printf.h>
+
+#define IRQ_PIN 17
+
+
+RF24 radio(22, 21); // CE, CSN
+const byte address[6] = {'R','E','C','V', '1'};
+char val[4];
+
+
+void isrCallbackFunction() {
+  bool tx_ds, tx_df, rx_dr;
+  radio.whatHappened(tx_ds, tx_df, rx_dr); // resets the IRQ pin to HIGH
+  if ( radio.available()) {
+    while (radio.available()) {
+      radio.read(&val, sizeof(val));
+      Serial.print("Received = ");
+      Serial.println(val);
+    }
+  }
+}
+ 
+void setup() {
+  pinMode(IRQ_PIN, INPUT);
+  attachInterrupt(digitalPinToInterrupt(IRQ_PIN), isrCallbackFunction, FALLING);
+  Serial.begin(115200);
+  radio.begin();
+  radio.openReadingPipe(0, address);
+  radio.setPALevel(RF24_PA_MAX);
+  radio.maskIRQ(1, 1, 0);
+  radio.startListening();
+}
+
+void loop() {
+  // put your main code here, to run repeatedly:
+
+}
diff --git a/firmware/trigger_firmware/trigger_firmware.ino b/firmware/trigger_firmware/trigger_firmware.ino
index ff8993a..996053d 100644
--- a/firmware/trigger_firmware/trigger_firmware.ino
+++ b/firmware/trigger_firmware/trigger_firmware.ino
@@ -37,7 +37,7 @@
 
   radio.begin();
   radio.openWritingPipe(address);
-  radio.setPALevel(RF24_PA_MIN);
+  radio.setPALevel(RF24_PA_MAX);
   //radio.setDataRate( RF24_250KBPS );
 
   pinMode(IN_TRIGGER, INPUT_PULLUP);

--
Gitblit v1.9.3