c

Committer:
tecnosys
Date:
Wed Jun 16 12:31:39 2010 +0000
Revision:
3:12c2fd911f22

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tecnosys 3:12c2fd911f22 1 // Flip an LED every time we see the rising edge interrupt on a pin
tecnosys 3:12c2fd911f22 2 #include "mbed.h"
tecnosys 3:12c2fd911f22 3 #include "CAN3.h"
tecnosys 3:12c2fd911f22 4 #include "mcp2515.h"
tecnosys 3:12c2fd911f22 5 #include "mcp2515_can.h"
tecnosys 3:12c2fd911f22 6
tecnosys 3:12c2fd911f22 7
tecnosys 3:12c2fd911f22 8
tecnosys 3:12c2fd911f22 9
tecnosys 3:12c2fd911f22 10 DigitalOut led_can(LED1);
tecnosys 3:12c2fd911f22 11 DigitalOut led_serial(LED2);
tecnosys 3:12c2fd911f22 12 DigitalOut led_analog(LED3);
tecnosys 3:12c2fd911f22 13 DigitalOut led_status(LED4);
tecnosys 3:12c2fd911f22 14 Serial console(USBTX, USBRX); // tx, rx
tecnosys 3:12c2fd911f22 15
tecnosys 3:12c2fd911f22 16 //InterruptIn can3_int(p16);
tecnosys 3:12c2fd911f22 17
tecnosys 3:12c2fd911f22 18 //mcp2515 can3(p5, p6, p7, p11);
tecnosys 3:12c2fd911f22 19 SPI spi1(p5, p6, p7);
tecnosys 3:12c2fd911f22 20
tecnosys 3:12c2fd911f22 21 CAN3 can3(spi1, p19, p11);
tecnosys 3:12c2fd911f22 22 CAN3 can4(spi1, p20, p12);
tecnosys 3:12c2fd911f22 23 //CAN3 can5(spi1, p21, p23);
tecnosys 3:12c2fd911f22 24
tecnosys 3:12c2fd911f22 25 CAN can2(p30, p29);
tecnosys 3:12c2fd911f22 26
tecnosys 3:12c2fd911f22 27 Ticker mbed_can_ticker;
tecnosys 3:12c2fd911f22 28 Ticker mcp2515_s1_can_ticker;
tecnosys 3:12c2fd911f22 29 Ticker mcp2515_s2_can_ticker;
tecnosys 3:12c2fd911f22 30 //Ticker mcp2515_s3_can_ticker;
tecnosys 3:12c2fd911f22 31
tecnosys 3:12c2fd911f22 32 char testbytes[] = { 0xA1, 0xA2, 0xAA, 0xAA, 0x00, 0x00, 0x00, 0xF0 };
tecnosys 3:12c2fd911f22 33
tecnosys 3:12c2fd911f22 34 void send() {
tecnosys 3:12c2fd911f22 35 static char counter = 0;
tecnosys 3:12c2fd911f22 36 if (can2.write(CANMessage(0x200, &counter, 1))) {
tecnosys 3:12c2fd911f22 37 printf("\n\rCAN2 CanTx--> id: 0x200 dlc: 1 data: %x\n\r", counter);
tecnosys 3:12c2fd911f22 38 counter++;
tecnosys 3:12c2fd911f22 39 }
tecnosys 3:12c2fd911f22 40 // toggle led1 after every transmission
tecnosys 3:12c2fd911f22 41 led_status = !led_status;
tecnosys 3:12c2fd911f22 42 }
tecnosys 3:12c2fd911f22 43
tecnosys 3:12c2fd911f22 44 void sendSPICAN3() {
tecnosys 3:12c2fd911f22 45
tecnosys 3:12c2fd911f22 46
tecnosys 3:12c2fd911f22 47 CANMessage test(0x300, testbytes, 8);
tecnosys 3:12c2fd911f22 48 can3.send(&test);
tecnosys 3:12c2fd911f22 49
tecnosys 3:12c2fd911f22 50 }
tecnosys 3:12c2fd911f22 51
tecnosys 3:12c2fd911f22 52 void sendSPICAN4() {
tecnosys 3:12c2fd911f22 53
tecnosys 3:12c2fd911f22 54
tecnosys 3:12c2fd911f22 55 CANMessage test(0x400, testbytes, 8);
tecnosys 3:12c2fd911f22 56 can4.send(&test);
tecnosys 3:12c2fd911f22 57
tecnosys 3:12c2fd911f22 58 }
tecnosys 3:12c2fd911f22 59
tecnosys 3:12c2fd911f22 60 void sendSPICAN5() {
tecnosys 3:12c2fd911f22 61
tecnosys 3:12c2fd911f22 62
tecnosys 3:12c2fd911f22 63 CANMessage test(0x500, testbytes, 8);
tecnosys 3:12c2fd911f22 64 can4.send(&test);
tecnosys 3:12c2fd911f22 65
tecnosys 3:12c2fd911f22 66 }
tecnosys 3:12c2fd911f22 67 ///////
tecnosys 3:12c2fd911f22 68 void canmsg1() {
tecnosys 3:12c2fd911f22 69
tecnosys 3:12c2fd911f22 70 led_can=!led_can;
tecnosys 3:12c2fd911f22 71
tecnosys 3:12c2fd911f22 72 if ( ( can4.can_checkReceive() == CAN_MSGAVAIL ) ) {
tecnosys 3:12c2fd911f22 73 printf("\n\n\rrecieved some shit on can4\n \r");
tecnosys 3:12c2fd911f22 74 can4.process_CANMessages();
tecnosys 3:12c2fd911f22 75 }
tecnosys 3:12c2fd911f22 76 }
tecnosys 3:12c2fd911f22 77
tecnosys 3:12c2fd911f22 78 /*
tecnosys 3:12c2fd911f22 79 void canmsg2() {
tecnosys 3:12c2fd911f22 80
tecnosys 3:12c2fd911f22 81 led_can=!led_can;
tecnosys 3:12c2fd911f22 82
tecnosys 3:12c2fd911f22 83 if ( ( can5.can_checkReceive() == CAN_MSGAVAIL ) ) {
tecnosys 3:12c2fd911f22 84 printf("\n\n\rrecieved some shit on can5\n \r");
tecnosys 3:12c2fd911f22 85 can5.process_CANMessages();
tecnosys 3:12c2fd911f22 86 }
tecnosys 3:12c2fd911f22 87 }
tecnosys 3:12c2fd911f22 88 */
tecnosys 3:12c2fd911f22 89 void canmsg() {
tecnosys 3:12c2fd911f22 90
tecnosys 3:12c2fd911f22 91 led_can=!led_can;
tecnosys 3:12c2fd911f22 92 printf("\n\n\rrecieved some shit on can3\n \r");
tecnosys 3:12c2fd911f22 93 if ( ( can3.can_checkReceive() == CAN_MSGAVAIL ) ) {
tecnosys 3:12c2fd911f22 94 can3.process_CANMessages();
tecnosys 3:12c2fd911f22 95 }
tecnosys 3:12c2fd911f22 96 canmsg1();//canmsg2();
tecnosys 3:12c2fd911f22 97
tecnosys 3:12c2fd911f22 98 }
tecnosys 3:12c2fd911f22 99
tecnosys 3:12c2fd911f22 100
tecnosys 3:12c2fd911f22 101 int main() {
tecnosys 3:12c2fd911f22 102
tecnosys 3:12c2fd911f22 103
tecnosys 3:12c2fd911f22 104 // console.baud(57600);
tecnosys 3:12c2fd911f22 105 console.printf("\nStarting\n\n");
tecnosys 3:12c2fd911f22 106
tecnosys 3:12c2fd911f22 107 spi1.frequency(5000000); // anything above 5000000 5MHZ works
tecnosys 3:12c2fd911f22 108
tecnosys 3:12c2fd911f22 109 can2.frequency(125000);//(500000); 50KBPS 1250000
tecnosys 3:12c2fd911f22 110
tecnosys 3:12c2fd911f22 111 console.printf("\n\r\rCAN3 \n\r");
tecnosys 3:12c2fd911f22 112 can3.frequency(CAN_125KBPS);
tecnosys 3:12c2fd911f22 113
tecnosys 3:12c2fd911f22 114 console.printf("\n\r\rCAN4 \n\r");
tecnosys 3:12c2fd911f22 115 can4.frequency(CAN_125KBPS);
tecnosys 3:12c2fd911f22 116
tecnosys 3:12c2fd911f22 117 console.printf("\n\r\rCAN3 \n\r");
tecnosys 3:12c2fd911f22 118 can3.frequency(CAN_125KBPS);
tecnosys 3:12c2fd911f22 119
tecnosys 3:12c2fd911f22 120 console.printf("\n\r\rCAN4 \n\r");
tecnosys 3:12c2fd911f22 121 can4.frequency(CAN_125KBPS);
tecnosys 3:12c2fd911f22 122
tecnosys 3:12c2fd911f22 123
tecnosys 3:12c2fd911f22 124 console.printf("\n\r\rCAN5 \n\r");
tecnosys 3:12c2fd911f22 125 //can5.frequency(CAN_125KBPS);
tecnosys 3:12c2fd911f22 126
tecnosys 3:12c2fd911f22 127
tecnosys 3:12c2fd911f22 128 wait(.1);
tecnosys 3:12c2fd911f22 129 led_can=0;
tecnosys 3:12c2fd911f22 130 led_serial=0;
tecnosys 3:12c2fd911f22 131 led_analog=0;
tecnosys 3:12c2fd911f22 132 led_status=0;
tecnosys 3:12c2fd911f22 133
tecnosys 3:12c2fd911f22 134
tecnosys 3:12c2fd911f22 135 //can3._spi.frequency(5000000); // anything above 5000000 5MHZ works
tecnosys 3:12c2fd911f22 136
tecnosys 3:12c2fd911f22 137 can3.fall(&canmsg);
tecnosys 3:12c2fd911f22 138 can4.fall(&canmsg1);
tecnosys 3:12c2fd911f22 139 //can5.fall(&canmsg2);
tecnosys 3:12c2fd911f22 140
tecnosys 3:12c2fd911f22 141
tecnosys 3:12c2fd911f22 142 printf("\n\r\n\r\n\r\n\r\n\r");
tecnosys 3:12c2fd911f22 143 wait(.1);
tecnosys 3:12c2fd911f22 144 mbed_can_ticker.attach(&send, 3);
tecnosys 3:12c2fd911f22 145 mcp2515_s1_can_ticker.attach(&sendSPICAN3, 2);
tecnosys 3:12c2fd911f22 146 mcp2515_s2_can_ticker.attach(&sendSPICAN4, 3);
tecnosys 3:12c2fd911f22 147 //mcp2515_s3_can_ticker.attach(&sendSPICAN5, 1);
tecnosys 3:12c2fd911f22 148
tecnosys 3:12c2fd911f22 149 while (1) {
tecnosys 3:12c2fd911f22 150
tecnosys 3:12c2fd911f22 151
tecnosys 3:12c2fd911f22 152 wait(1);
tecnosys 3:12c2fd911f22 153
tecnosys 3:12c2fd911f22 154 // canmsg1();
tecnosys 3:12c2fd911f22 155 /*
tecnosys 3:12c2fd911f22 156 //MODE_NORMAL
tecnosys 3:12c2fd911f22 157 if ( ( can3.can_checkReceive() == CAN_MSGAVAIL ) ) {
tecnosys 3:12c2fd911f22 158 can3.process_CANMessages();
tecnosys 3:12c2fd911f22 159 }
tecnosys 3:12c2fd911f22 160 //MODE_NORMAL
tecnosys 3:12c2fd911f22 161 if ( ( can4.can_checkReceive() == CAN_MSGAVAIL ) ) {
tecnosys 3:12c2fd911f22 162 can4.process_CANMessages();
tecnosys 3:12c2fd911f22 163 }
tecnosys 3:12c2fd911f22 164 */
tecnosys 3:12c2fd911f22 165 //can3.dumpExtendedStatus();
tecnosys 3:12c2fd911f22 166
tecnosys 3:12c2fd911f22 167 }
tecnosys 3:12c2fd911f22 168
tecnosys 3:12c2fd911f22 169
tecnosys 3:12c2fd911f22 170 }