François .
/
testcanOK
Revision 0:d40cebe2b64e, committed 2011-08-24
- Comitter:
- bouguereau
- Date:
- Wed Aug 24 09:45:21 2011 +0000
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/can01.cpp Wed Aug 24 09:45:21 2011 +0000 @@ -0,0 +1,70 @@ +#include "can01.h" + + Ticker ticker; + + DigitalOut led1(LED1); + DigitalOut led2(LED2); + + // 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 can1(p9, p10); + + // We use can on mbed pins 29(CAN_TXD) and 30(CAN_RXD). + CAN can2(p30, p29); + + +void tCan01 :: send() + { + static char counter = 0; + if (can2.write(CANMessage(0x200, &counter, 1))) { + printf("CanTx--> id: 0x200 dlc: 1 data: %x\n\r", counter); + counter++; + } + // toggle led1 after every transmission + led1 = !led1; + } + + +void tCan01 :: ConfigurerCan2Envoie() +{ + char compteur=1; + // 500kbit/s + can2.frequency(10000); + // activate external can transceiver + can_Pca82c250SlopePin = 0; + // every 500ms + ticker.attach(&send, 0.5); + /// create message object for message reception + CANMessage can_MsgRx; + can2.write(CANMessage(0x200, &compteur, 1)); + while (1) + { + // send received messages to the pc via serial line (9k6, 8n1) + if (can2.read(can_MsgRx)) + { + printf("CanRx--> id: 0x%x dlc: %d data: ", can_MsgRx.id, can_MsgRx.len); + for (char i=0; i<can_MsgRx.len; i++) + { + printf("%x ", can_MsgRx.data[i]); + } + printf("\n\r"); + // any incoming message: toggle led2 + led2 = !led2; + } + } +} + +/*void tcan01 ::Can1Recoit() +{ + static char msg=0; + if (can1.read(CANMessage(0x200,msg))) + { + printf("CanTx + } +}*/ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/can01.h Wed Aug 24 09:45:21 2011 +0000 @@ -0,0 +1,19 @@ +#ifndef CAN01_H +#define CAN01_H + +#include "mbed.h" +#include "CAN.h" + +class tCan01 +{ + +private: + +public: + void send() ; + void Can1Recoit() ; + void ConfigurerCan2Envoie(); + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Aug 24 09:45:21 2011 +0000 @@ -0,0 +1,13 @@ +#include "can01.h" + + //Can2Envoie + + + + int main() + { + tCan01 obj; + obj.send(); + obj.ConfigurerCan2Envoie(); + + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Aug 24 09:45:21 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9a9732ce53a1