Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "CAN.h" 00003 00004 LocalFileSystem local("local"); 00005 00006 Ticker ticker; 00007 00008 DigitalOut led1(LED1); 00009 DigitalOut led2(LED2); 00010 DigitalOut led3(LED3); 00011 DigitalOut led4(LED4); 00012 00013 00014 // CAN_RS pin at Philips PCA82C250 can bus controller. 00015 // activate transceiver by pulling this pin to GND. 00016 // (Rise and fall slope controlled by resistor R_s) 00017 // (+5V result in tranceiver standby mode) 00018 // For further information see datasheet page 4 00019 //DigitalOut can_Pca82c250SlopePin(p28); 00020 00021 // second can controller on these pins. Not used here. 00022 // CAN can1(p9, p10); 00023 00024 // We use can on mbed pins 29(CAN_TXD) and 30(CAN_RXD). 00025 CAN can2(p30, p29); 00026 Serial pc(p13,p14); 00027 00028 FILE *fp ; 00029 unsigned int flag=0; 00030 00031 void send() { 00032 static char counter = 0; 00033 if (can2.write(CANMessage(0x200, &counter, 1))) { 00034 00035 // LPC_CAN2->CMR &= 0xEF; // stop back Tx 00036 pc.printf("CanTx--> id: 0x200 dlc: 1 data: %x\n\r", counter); 00037 counter++; 00038 } 00039 // toggle led1 after every transmission 00040 led1 = !led1; 00041 00042 } 00043 00044 int main() { 00045 // 500kbit/s 00046 can2.frequency(500000); 00047 // every 500ms 00048 ticker.attach(&send, 0.5); 00049 /// create message object for message reception 00050 CANMessage can_MsgRx; 00051 pc.baud(38400); 00052 pc.format(8,Serial::None,1); 00053 while (1) { 00054 // send received messages to the pc via serial line (9k6, 8n1) 00055 if (can2.read(can_MsgRx)) { 00056 00057 led3= can_MsgRx.data[0]&0x01; 00058 led4= (can_MsgRx.data[0]&0x02)>>1; 00059 // any incoming message: toggle led2 00060 pc.printf("Receive %3x %2u\n\r",can_MsgRx.id,can_MsgRx.len); 00061 led2 = !led2; 00062 } 00063 } 00064 }
Generated on Fri Jul 22 2022 02:08:15 by
1.7.2