Peter Cooper
/
diags
test code for our MBED board
can.c
- Committer:
- lolpcc
- Date:
- 2010-01-12
- Revision:
- 0:9edfcca7cd25
- Child:
- 1:6877bb99aa17
File content as of revision 0:9edfcca7cd25:
#include "mbed.h" #include "diags.h" #include "CAN.h" Ticker ticker; // 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); // We use can on mbed pins 29(CAN_TXD) and 30(CAN_RXD). CAN can(p30, p29); int can_cnt=0; /******************************************/ /* */ /* Can Bus Tests */ /* */ /* */ /* */ /* */ /******************************************/ void send() { static char counter = 0; if (can.write(CANMessage(0x200, &counter, 1))) { printf("CanTx--> id: 0x200 dlc: 1 data: %x\n\r", counter); counter++; } else { printf("CanTx--> id: 0x200 dlc: 1 data: %x ERROR\n\r", counter); can.reset(); } if(can_cnt==0){ led_on(3); can_cnt=1; } else { led_off(3); can_cnt=0; } // toggle led1 after every transmission } void test_can(int loop) { // 500kbit/s can.frequency(500000); // activate external can transceiver can_Pca82c250SlopePin = 0; can_cnt=loop; // every 500ms ticker.attach(&send, 0.5); printf("CAN message ticker started\n\r"); }