EtherCAT slave that reads 3 Xsens IMU's connected to a Xbus Master

Dependencies:   MODSERIAL mbed KL25Z_ClockControl

Fork of EtherCAT by First Last

Revision:
18:6629e8c5d59e
Parent:
17:c5946a0fde83
Child:
19:8ead12aec8d5
--- a/soes.cpp	Thu Mar 05 22:22:47 2015 +0000
+++ b/soes.cpp	Thu Mar 05 23:08:58 2015 +0000
@@ -60,12 +60,16 @@
 uint8           TXPDOsize,RXPDOsize;
 uint16          wd_ok = 1, wd_cnt = wd_reset;
 
+uint8_t copy_new_data = 0;
+uint8_t copydata;
+
 DigitalOut led(LED_PIN);
 DigitalOut et1100_ss(ET1100_SS);
 DigitalIn  et1100_miso(ET1100_MISO);
 SPI et1100_spi(ET1100_MOSI,ET1100_MISO,ET1100_SCK);
-MODSERIAL xbus(PTC4,PTC3);
-struct xbus_struct xbus_master;
+MODSERIAL xbus_serial(PTC4,PTC3);
+xbus_t xbus_master;
+
 
 /* Private function prototypes -----------------------------------------------*/
 /* Private functions ---------------------------------------------------------*/
@@ -180,20 +184,22 @@
     // Don't allow the letter "A" go into the RX buffer.
     // Basically acts as a filter to remove the letter "A" 
     // if it goes into the RX buffer.
-    XbusReceiveState(&xbus_master,c);
+	XbusReceiveState((xbus_t *)&xbus_master, (uint8_t)copydata);
+	if(xbus_master.rx.message_complete && xbus_master.rx.checksum_ok)
+    {
+    	xbus_master.rx.checksum_ok = 0;
+    	if(xbus_master.rx.buffer[2] == 0x32)
+    	{
+			copy_new_data = 1;
+		}
+	}
+	
         // Note, we call the MODSERIAL_IRQ_INFO::rxDiscardLastChar() public function which
         // is permitted access to the protected version of MODSERIAL::rxDiscardLastChar()
         // within MODSERIAL (because they are friends). This ensures rxDiscardLastChar()
         // can only be called within an rxCallback function. 
     info->rxDiscardLastChar(); 
-    if(xbus_master.rx.message_complete && xbus_master.rx.checksum_ok)
-    {
-    	xbus_master.rx.checksum_ok = 0;
-    	if(xbus_master.rx.buffer[2] == 0x32)
-    	{
-    		memcpy(&Rb.first.acc[0],&buffer[4],60);
-    	}
-    }
+ 
 }
 
 int main(void)
@@ -225,6 +231,11 @@
 // application run loop
     while (1)
     {
+        if(copy_new_data)
+        {   
+        	memcpy(&Rb.first.acc[0],&xbus_master.rx.buffer[4],60);
+    		copy_new_data = 0;
+    	}
         ESC_read(ESCREG_LOCALTIME, &ESCvar.Time, sizeof(ESCvar.Time), &ESCvar.ALevent);
         ESC_ALevent();
         ESC_state();