Angel David Yaguana Hernandez
/
0_TUTO_CAN_to_CAN
(CAN) using any type of character and strings with a maxim of 8 bits
Revision 1:328932c34ba1, committed 2013-01-08
- Comitter:
- sherckuith
- Date:
- Tue Jan 08 06:44:56 2013 +0000
- Parent:
- 0:8ef426505c79
- Commit message:
- (CAN) using any type of character and strings with a maxim of 8 bits
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8ef426505c79 -r 328932c34ba1 main.cpp --- a/main.cpp Tue Jan 08 06:15:53 2013 +0000 +++ b/main.cpp Tue Jan 08 06:44:56 2013 +0000 @@ -20,10 +20,12 @@ can1.frequency(125000); can2.frequency(125000); while(1) { - if(can2.read(msg)) + if(can1.read(msg)) led1 = 1; + if(can2.read(msg)) + led2 = 1; - /***********inicio de comunicacion****************************/ + /***********inicio de comunicacion CAN1 -> CAN2 ****************************/ pc.printf("************************************\n\r"); can1.write(CANMessage(01, &a[0], 8)); pc.printf("write a: %s ",&a[0]); @@ -31,25 +33,96 @@ led1 = 1;led2 = 0;led3 = 0;led4 = 0; pc.printf("read a:-%s-\n",&msg.data[0]); } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + can1.write(CANMessage(01, &b[0], 4)); pc.printf("write b: %s ",&b[0]); if(can2.read(msg)) { - led1 = 0;led2 = 2;led3 = 0;led4 = 0; + led1 = 0;led2 = 1;led3 = 0;led4 = 0; pc.printf("read b:-%s-\n",&msg.data[0]); } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + can1.write(CANMessage(01, &c[0], 8)); pc.printf("write c: %s ",&c[0]); if(can2.read(msg)) { - led1 = 0;led2 = 0;led3 = 3;led4 = 0; + led1 = 0;led2 = 0;led3 = 1;led4 = 0; pc.printf("read c:-%s-\n",&msg.data[0]); } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + can1.write(CANMessage(01, &d[0], 8)); pc.printf("write d: %s ",&d[0]); if(can2.read(msg)) { - led1 = 0;led2 = 0;led3 = 0;led4 = 4; + led1 = 0;led2 = 0;led3 = 0;led4 = 1; pc.printf("read d:-%s-\n",&msg.data[0]); } - //wait(0.25); + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + + //wait(1); + led1 = 0;led2 = 0;led3 = 0;led4 = 0; + + /************************fin**********************************/ + + /***********inicio de comunicacion CAN2 -> CAN1 ****************************/ + pc.printf("************************************\n\r"); + can2.write(CANMessage(01, &a[0], 8)); + pc.printf("write a: %s ",&a[0]); + if(can1.read(msg)) { + led1 = 0;led2 = 0;led3 = 0;led4 = 1; + pc.printf("read a:-%s-\n",&msg.data[0]); + } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + + can2.write(CANMessage(01, &b[0], 4)); + pc.printf("write b: %s ",&b[0]); + if(can1.read(msg)) { + led1 = 0;led2 = 0;led3 = 1;led4 = 0; + pc.printf("read b:-%s-\n",&msg.data[0]); + } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + + can2.write(CANMessage(01, &c[0], 8)); + pc.printf("write c: %s ",&c[0]); + if(can1.read(msg)) { + led1 = 0;led2 = 1;led3 = 0;led4 = 0; + pc.printf("read c:-%s-\n",&msg.data[0]); + } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + + can2.write(CANMessage(01, &d[0], 8)); + pc.printf("write d: %s ",&d[0]); + if(can1.read(msg)) { + led1 = 1;led2 = 0;led3 = 0;led4 = 0; + pc.printf("read d:-%s-\n",&msg.data[0]); + } + else { + printf("CAN1 RD error: %d, TD error: %d\r\n", can1.rderror(), can1.tderror() ); + printf("CAN2 RD error: %d, TD error: %d\r\n", can2.rderror(), can2.tderror() ); + } + + //wait(1); led1 = 0;led2 = 0;led3 = 0;led4 = 0; /************************fin**********************************/