/* Initialize CAN Controller */ uint32_t ClkInitTable[2] = { 0x00000000UL, // CANCLKDIV 0x00001C57UL // CAN_BTR }; |
for (;;) { msg_obj.msgobj = 1; // 1 -> means Standard Frame receive (Standard == 11 bit) msg_obj.mode_id = 0x400; // start ID == 0x400 msg_obj.mask = 0x700; // mask ID == 0x700 -> stop ID == 0x4FF (*rom)->pCAND->config_rxmsgobj(&msg_obj); // configure message object 1 to receive all 11-bit messages 0x400-0x4FF (*rom)->pCAND->can_receive(&msg_obj); // load up the msg_obj structure with the CAN message if (msg_obj.mode_id == 0x401) { LPC_GPIO0->DATA |= (1<<7); // LED 1 ON LPC_GPIO2->DATA &=~(1<<10); // LED 2 OFF delay (500); } if (msg_obj.mode_id == 0x402) { LPC_GPIO0->DATA &=~(1<<7); // LED 1 OFF LPC_GPIO2->DATA |= (1<<10); // LED 2 ON delay (500); } else { LPC_GPIO0->DATA |=(1<<7); // LED 1 OFF LPC_GPIO2->DATA |=(1<<10); // LED 2 OFF } } |
msg_obj.msgobj = 1; // 1 -> means Standard Frame receive (Standard == 11 bit) msg_obj.mode_id = 0x400; // start ID == 0x400 msg_obj.mask = 0x700; // mask ID == 0x700 -> stop ID == 0x4FF (*rom)->pCAND->config_rxmsgobj(&msg_obj); // configure message object 1 to receive all 11-bit messages 0x400-0x4FF for (;;) { (*rom)->pCAND->can_receive(&msg_obj); // load up the msg_obj structure with the CAN message if (msg_obj.mode_id == 0x401) { LPC_GPIO0->DATA |= (1<<7); // LED 1 ON LPC_GPIO2->DATA &=~(1<<10); // LED 2 OFF delay (500); } if (msg_obj.mode_id == 0x402) { LPC_GPIO0->DATA &=~(1<<7); // LED 1 OFF LPC_GPIO2->DATA |= (1<<10); // LED 2 ON delay (500); } else { LPC_GPIO0->DATA |=(1<<7); // LED 1 OFF LPC_GPIO2->DATA |=(1<<10); // LED 2 OFF } } } |
/* Configure message object 1 to receive all 11-bit messages 0x400-0x4FF */ msg_obj.msgobj = 1; msg_obj.mode_id = 0x400; msg_obj.mask = 0x700; (*rom)->pCAND->config_rxmsgobj(&msg_obj); |
/* CAN receive callback */ /* Function is executed by the Callback handler after a CAN message has been received */ void CAN_rx(uint8_t msg_obj_num){ /* Determine which CAN message has been received */ msg_obj.msgobj = msg_obj_num; /* Now load up the msg_obj structure with the CAN message */ (*rom)->pCAND->can_receive(&msg_obj); if (msg_obj_num == 1) { //INSERT ID check here /* Simply transmit CAN frame (echo) with with ID +0x100 via buffer 2 */ msg_obj.msgobj = 2; msg_obj.mode_id += 0x100; (*rom)->pCAND->can_transmit(&msg_obj); } return; } |