V1

Fork of 446STM32_Print_PC_I2CS by Hsieh JenYun

Revision:
2:764981c589b6
Parent:
1:51fb8c086992
Child:
3:4d977dd77a4b
diff -r 51fb8c086992 -r 764981c589b6 main.cpp
--- a/main.cpp	Mon Nov 06 06:05:09 2017 +0000
+++ b/main.cpp	Mon Nov 06 08:23:22 2017 +0000
@@ -1,58 +1,43 @@
-#include <mbed.h>
- 
-I2CSlave slave(PC_9, PA_8);
+#include "mbed.h"
+
 DigitalOut myled(LED1);
-Thread thread;
 Serial pc(USBTX, USBRX);
- 
-void slave_thread(){
+I2CSlave slave(PC_9, PA_8);
+
+int main() {
     char buffer[128];
-    while(true){
-        Thread::signal_wait(1);
-        
+      char all_buf[]="i'm here!";
+   char buf[20];
+   char msg[] = "Hi Master!";
+   slave.address(0xA0);
+
+    while(1){ 
         if(pc.readable()) {  
             slave.stop();
             pc.gets(buffer, 128);
             pc.printf("I got '%s'\n", buffer);
-            printf("get_state osStatus: %d\n",thread.get_state ());
         }
-    }
-}
-int main() {
-   char all_buf[]="i'm here!";
-   char buf[20];
-   char msg[] = "Hi Master!, this is 0xA0 response";
-   slave.address(0xA0);
-   thread.start(slave_thread);
-   while (1) {
-       int i = slave.receive();
-       if(i==1||i==2||i==3){
-        thread.signal_clr(0);
-        switch (i) {
+        int i = slave.receive();
+       switch (i) {
            case I2CSlave::ReadAddressed:
                if(!slave.write(msg, strlen(msg) + 1)) // Includes null char
                 slave.stop();
                 printf("ReadAddressed\n");
                 //slave.stop();
-                thread.signal_set(1);
                break;
            case I2CSlave::WriteGeneral:
                if(!slave.write(all_buf, strlen(all_buf) + 1)) // Includes null char
                 slave.stop();
                 printf("i've received the command...\n");
-                thread.signal_set(1);
                break;
            case I2CSlave::WriteAddressed:
                slave.read(buf, 20);
+               //slave.stop();
                printf("master write to A: %s\n", buf);
-               thread.signal_set(1);
                break;
        }
-       }else{
-          //thread.signal_set(1); 
-        } 
        for(int i = 0; i < 10; i++) {
            buf[i] = 0;    // Clear buffer
            }
-   }
+    }
 }
\ No newline at end of file