test

Dependencies:   F7_Ethernet mbed BSP_DISCO_F746NG SDFileSystem RF24

Files at this revision

API Documentation at this revision

Comitter:
lowlowry
Date:
Tue Jun 08 16:21:16 2021 +0000
Parent:
2:72880ce754af
Commit message:
test final

Changed in this revision

RF24.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RF24.lib	Tue Jun 08 16:21:16 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/hudakz/code/RF24/#d96c2056bf37
--- a/main.cpp	Tue Jun 08 14:43:29 2021 +0000
+++ b/main.cpp	Tue Jun 08 16:21:16 2021 +0000
@@ -6,6 +6,23 @@
 #include "NTPClient.h"
 
 
+#include "RF24.h"
+const uint64_t  ADDRESS = 0xF0F0F0F0F0F0F001L;
+
+RF24            radio(A2, A3, A4, D4, D2);    // SPI5 mosi, miso, sck, csn, ce (irq unused)
+
+struct MyData 
+{
+    uint8_t  board;
+    uint8_t counter;
+    uint8_t temperature;
+
+};
+
+MyData data;
+
+
+
 
 
 
@@ -24,13 +41,23 @@
 }
 
 
-int main() { 
+int main(void) { 
     
     int temp_array[1]; // Nur zum Test
     temp_array[0]= 123; // Nur zum Test
     temp_array[1]= 124;// Nur zum Test
     
     
+    if (!radio.begin()) {
+        printf("Failed to initialize nRF24L01. Check whether connected.\r\n");
+        return -1;  // Exit the program
+    }
+    radio.setPALevel(RF24_PA_LOW);
+    radio.setRetries(5, 15);
+    radio.setPayloadSize(sizeof(MyData));
+    radio.setAutoAck(true);
+    radio.openReadingPipe(0, ADDRESS);  // use pipe 0 of this slave to receive messsages and send back auto acknowledge
+    radio.startListening();
     
     
     
@@ -60,9 +87,31 @@
     
         
     int x;
-     for (x=1; x<6;x++){
      
      
+     // for (x=1; x<6;x++){
+         
+         
+         while (1) {
+        
+        printf("laeuft\r\n");
+        wait(1);
+         
+            if (radio.available()) {
+            radio.read(&data, sizeof(MyData)); // read message and send acknowledge back to the master
+            //led = payload;
+             
+             printf("------------------------\r\n");
+             printf("Received from Board: %d \r\n", data.board);
+
+             printf( "counter: %d \r\n", data.counter);
+             printf( "temperature: %d \r\n", data.temperature);
+             printf( "board: %d \r\n", data.board);
+             printf("------------------------\r\n\n");
+
+            
+        
+    /*
      
      
        fp = fopen("/sd/test.txt", "a");
@@ -98,7 +147,7 @@
      fclose (fp); 
    
         
-    } // for end
+    } 
    
     
         fp = fopen("/sd/test.txt", "r");
@@ -118,4 +167,8 @@
         // file close
         fclose(fp);
         
+        */
+        }
+        
 }
+}