Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
bouguereau
Date:
Wed Aug 24 09:47:13 2011 +0000
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 96c0a1b1070f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 24 09:47:13 2011 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "CAN.h"
+ 
+ Ticker ticker;
+ 
+ DigitalOut led1(LED1);
+ DigitalOut led2(LED2);
+ 
+ LocalFileSystem local("local");
+ 
+ // CAN_RS pin at Philips PCA82C250 can bus controller.
+ // activate transceiver by pulling this pin to GND.
+ // (Rise and fall slope controlled by resistor R_s)
+ // (+5V result in tranceiver standby mode)
+ // For further information see datasheet page 4
+ DigitalOut can_Pca82c250SlopePin(p28);
+  
+ // second can controller on these pins. Not used here.
+ CAN can2(p9, p10);
+ 
+ // We use can on mbed pins 29(CAN_TXD) and 30(CAN_RXD).
+// CAN can2(p30, p29);
+
+ void send() {
+     static char counter = 0;
+     if (can2.write(CANMessage(0x300, &counter, 1))) {
+         printf("CanTx--> id: 0x200  dlc: 1  data: %x\n\r", counter);
+         counter++;
+     }
+     // toggle led1 after every transmission
+     led1 = !led1;
+ }
+
+ int main() {
+ 
+  FILE *test1 = fopen("/local/test.txt", "w");
+ 
+  bool flag = false;
+  int i =0 ;
+ 
+     // 500kbit/s
+     can2.frequency(500000);
+     // activate external can transceiver
+     can_Pca82c250SlopePin = 0;
+     // every 500ms
+     ticker.attach(&send, 0.5);
+     /// create message object for message reception
+     CANMessage can_MsgRx;
+   while(i<10)
+   {     
+         while (flag!=true)
+        {
+             // send received messages to the pc via serial line (9k6, 8n1)
+                 if (can2.read(can_MsgRx))
+                {
+                      led2 = !led2;
+                      flag = true;
+                }
+      
+         
+        }
+      
+       fprintf(test1,"%d-%d-%c%c%c%c%c%c%c%c\r",can_MsgRx.len,can_MsgRx.id,can_MsgRx.data[0],can_MsgRx.data[1],can_MsgRx.data[2],can_MsgRx.data[3],can_MsgRx.data[4],can_MsgRx.data[5],can_MsgRx.data[6],can_MsgRx.data[7]);
+       flag = false ;
+       i++;
+    }  
+       fclose(test1);
+}
diff -r 000000000000 -r 96c0a1b1070f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Aug 24 09:47:13 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912