This tests the CAN interface between two LISA C027 MBED Boards. By connecting the two boards, pins 1,2,3 respectively on the CAN interface, and loading and executing this code on BOTH boards, CAN messages will be received, and printed, on the PC-USB console interface of both devices.

Dependencies:   C027-REVB UbloxUSBModem mbed

Fork of C027_ModemTransparentUSBCDC_revb by Stephen Dickey

Files at this revision

API Documentation at this revision

Comitter:
dixter1
Date:
Sat Dec 14 00:24:59 2013 +0000
Parent:
1:15b5edb4a91f
Child:
3:048ec5c2dc14
Commit message:
First revision working, messages going between two LISA C027 boards across the CAN interface.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Dec 13 23:37:54 2013 +0000
+++ b/main.cpp	Sat Dec 14 00:24:59 2013 +0000
@@ -1,93 +1,46 @@
 #include "mbed.h"
 #include "C027.h"
-#include "WANDongle.h"
-#include "USBSerialStream.h"
-#include "UbloxCDMAModemInitializer.h"
-#include "UbloxGSMModemInitializer.h"
-
-DigitalOut mdm_activity(LED);
 
-int main() 
-{
-    int led_toggle_count = 5;
+Ticker ticker;
+DigitalOut led1(LED);
+DigitalOut led2(LED1);
+CAN can1(CANRD, CANTD);
+Serial pc(USBTX, USBRX);
 
-    // the instantiation of the type, calls C027::C027
-    C027 c027;
-    
-    c027.mdmPower(true,false);
-    
-    // enable the GPS, and connect it 
-    // to the m3.
-    c027.gpsPower(true, false);
+char counter = 0;
 
-#if 0
-    while(1) {
-        mdm_activity = !mdm_activity;
-        wait(0.2);
-    }
-#else
-    while( led_toggle_count-- > 0 )
-    {
-        mdm_activity = !mdm_activity;
-        wait(0.2);
+void send() {
+    if(can1.write(CANMessage(1337, &counter, 1))) {
+        pc.printf("Message sent: %d\r\n", counter);
+        counter++;
     }
-#endif
-        
-    // open the mdm serial port
-    WANDongle mdmDongle;
-    USBSerialStream mdmStream(mdmDongle.getSerial(1/* the CDC usually 0 or 1, LISA-C requires CDC1*/));
-    USBHost* host = USBHost::getHostInst();
-    mdmDongle.addInitializer(new UbloxCDMAModemInitializer(host));
-    mdmDongle.addInitializer(new UbloxGSMModemInitializer(host));
-   
-    // open the PC serial port and (use the same baudrate)
-    Serial pc(USBTX, USBRX);
+    led1 = !led1;
+}
+
+int main() {
+
+    DigitalOut can_standby(CANS);
+    
+    // enable the CAN interface
+    //   take it out of standby
+    can_standby = 0;
+    
     pc.baud(MDMBAUD);
     
-    pc.printf( "M3->USB CDC connection ready\n");
-    
-    while (1)
-    {
-        uint8_t buf[64];
-        size_t len;
-        int i;
-        
-        if (!mdmDongle.connected())
-        {
-            mdmDongle.tryConnect();
+    pc.printf( "Starting CAN Testing\r\n");
+
+    CANMessage msg;
+    while(1) {
+
+        if(can1.read(msg)) {
+            pc.printf("Message received: %d\r\n", msg.data[0]);
+            led2 = !led2;
         }
-        else
-        {
         
-            // transfer data from pc to modem
-            len = mdmStream.space();
-            if (len>0)
-            {
-                if (len > sizeof(buf))
-                    len = sizeof(buf);
-                for (i = 0; (i < len) && pc.readable(); )
-                    buf[i++] = pc.getc();
-                if (OK == mdmStream.write(buf, i))
-                    /* do something? */;
-            }
-            // transfer data from modem to pc
-            len = mdmStream.available();
-            if ((len>0) && pc.writeable())
-            {
-                if (len > sizeof(buf))
-                    len = sizeof(buf);
-                if (OK == mdmStream.read(buf, &len, len))
-                {
-                    for (i = 0; (i < len); ) 
-                    {
-                        mdm_activity=!mdm_activity;
-                        pc.putc(buf[i++]);
-                    }
-                    
-                    // default the led to off 
-                    mdm_activity=0;
-                }
-            }
-        }
+        wait(0.2);
+        
+        send();
     }
 }
+
+