 unsigned int err_o = 0; //cumulative number of MPU/DMP reads that had overflow bit set
 
 void loop() {
-    ret = mympu_update();
 
+    byte buffer [10];
+
+    byte received = recvMsg (fAvailable, fRead, buffer, sizeof (buffer));
+
+    if (received != 0)
+      {
+      if (buffer [0] != SLAVE_ID)
+        return;  // not my device
+
+      //TODO: remove
+      if (buffer [1] != 2)
+        return;  // unknown command
+
+      ret = mympu_update(); // get new sensor data
+      delay (2);  // give the master a moment to prepare to receive
+
+      float2bytes ypr0;
+      float2bytes ypr1;
+      float2bytes ypr2;
+      float2bytes gyro0;
+      float2bytes gyro1;
+      float2bytes gyro2;
+      float2bytes accel0;
+      float2bytes accel1;
+      float2bytes accel2;
+
+      ypr0.f = mympu.ypr[0];
+      ypr1.f = mympu.ypr[1];
+      ypr2.f = mympu.ypr[2];
+      gyro0.f = mympu.gyro[0];
+      gyro1.f = mympu.gyro[1];
+      gyro2.f = mympu.gyro[2];
+      accel0.f = mympu.accel[0];
+      accel1.f = mympu.accel[1];
+      accel2.f = mympu.accel[2];
+
+//receiving on stm32:
+//       for ( int i=0; i < sizeof(float); i++ )
+//         f2b.b[i] = read_byte();
+//       x = f2b.f;
+
+      byte msg [] = {
+         0,  // send to master
+		 SLAVE_ID, // sent from SLAVE_ID
+         ypr0.b[0],
+		 ypr0.b[1],
+		 ypr0.b[2],
+		 ypr0.b[3],
+		 ypr1.b[0],
+		 ypr1.b[1],
+		 ypr1.b[2],
+		 ypr1.b[3],
+		 ypr2.b[0],
+		 ypr2.b[1],
+		 ypr2.b[2],
+		 ypr2.b[3],
+		 gyro0.b[0],
+		 gyro0.b[1],
+		 gyro0.b[2],
+		 gyro0.b[3],
+		 gyro1.b[0],
+		 gyro1.b[1],
+		 gyro1.b[2],
+		 gyro1.b[3],
+		 gyro2.b[0],
+		 gyro2.b[1],
+		 gyro2.b[2],
+		 gyro2.b[3],
+		 accel0.b[0],
+		 accel0.b[1],
+		 accel0.b[2],
+		 accel0.b[3],
+		 accel1.b[0],
+		 accel1.b[1],
+		 accel1.b[2],
+		 accel1.b[3],
+		 accel2.b[0],
+		 accel2.b[1],
+		 accel2.b[2],
+		 accel2.b[3],
+      };
+
+      digitalWrite (ENABLE_PIN, HIGH);  // enable sending
+      sendMsg (fWrite, msg, sizeof msg);
+      Serial.flush();
+      digitalWrite (ENABLE_PIN, LOW);  // disable sending
+
+     }
+
+#ifdef DMP_DEBUG
     switch (ret) {
 	case 0: c++; break;
 	case 1: np++; return;

#include "freeram.h"

#include "mpu.h"
#include "I2Cdev.h"

int ret;
void setup() {
    Fastwire::setup(400,0);
    Serial.begin(38400);
    ret = mympu_open(200);
    Serial.print("MPU init: "); Serial.println(ret);
    Serial.print("Free mem: "); Serial.println(freeRam());

}

unsigned int c = 0; //cumulative number of successful MPU/DMP reads

	    Serial.print(" a2: "); Serial.print(mympu.accel[1]);
	    Serial.print(" a3: "); Serial.println(mympu.accel[2]);
    }
#endif
}
