IO spi

Revision:
0:c06c791ca345
Child:
1:1052d6227111
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 10 09:28:30 2020 +0000
@@ -0,0 +1,131 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2019 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+
+#include "MiWiApp.h"
+
+// Blinking rate in milliseconds
+#define BLINKING_RATE_MS                                                    200
+
+
+
+
+DigitalIn b2(SW2);
+
+
+
+char tx_niz[] = { 7,0,1,2,3, 4, 5 , 6, 7, 8};
+
+void consolafun( void );
+Thread th_consola( consolafun );
+
+int main()
+{
+    // Initialise the digital pin LED1 as an output
+printf("\n\n\r ____________ POCETAK MiWI RX_______________\n\r");
+
+    inic_MiWi( );
+    
+    DigitalOut led(LED1,1);
+    DigitalOut ledB(LED3,1);
+
+
+
+   set_mode( 3 );   //prijem
+ 
+ 
+ //for( int i=0; i<10; i++)
+ {
+      char r = readMiWiReg( 0x14 );  // read GCONFIG
+  printf("rssi = %d\n\r", r );
+  print_regs();
+}
+ 
+int b = b2;
+ 
+   
+    while (true) 
+    {
+ //       led = !led;
+
+extern DigitalIn pin_irq0, pin_irq1;
+//
+//   unsigned char r = readMiWiReg( 0x14 );  // read GCONFIG
+//  printf("rssi = %d   ", r );
+//  printf(" irq0=%d  irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() ); fflush(stdout);
+////if( r> 50 )
+
+    if( get_mode( ) == 3 )
+    {
+        if( pin_irq0.read() )
+        {
+             led = 0; 
+                print_regs();
+                while( pin_irq0.read() )
+                   {
+                        printf(" %x ", readMiWiData( ));  
+               //         printf("\n\r irq0=%d  irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() );
+                    }
+                printf("\n\r");
+                print_regs();
+        }
+        else        { if(!led )  led = 1; }
+    }
+//    else
+    {
+         
+        if( b!= b2)
+        {
+            b = b2;
+        if( b ) {/*set_mode( 1 );*/ ledB = 1;}
+        else    { ledB = 0; txMiWi( tx_niz ); }
+        }
+   
+    }
+
+
+
+        thread_sleep_for(BLINKING_RATE_MS);
+    }
+}
+
+
+
+
+void consolafun( void )
+{
+    while( true )
+    {
+     
+     char uc = getchar( );
+     switch( (unsigned char) uc )
+     {
+         case 'r': case 'R':  
+         
+            printf("\n\rcitanje registra, unesi broj:\n\r");
+            int r;
+            scanf("%x", &r);
+            printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
+        
+            break;
+         case 'w': case 'W':  
+         {
+            printf("\n\rupis registra, unesi broj registra:");
+            int r;
+            scanf("%x", &r);
+            printf( " %x", r );
+            printf("\n\runesi vrednost registra:");
+            int v;
+            scanf("%x", &v);
+            printf( " %x", v );
+            printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
+        }
+            break;
+     }
+        
+    }
+}