User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
257
CAN_FILTER Constants
CAN_FILTER constants dene lter codes. Function CANxSetFilter expects one of these as its argument:
Copy Code To Clipboard
const
_CAN_FILTER_B1_F1 : word = 0;
_CAN_FILTER_B1_F2 : word = 1;
_CAN_FILTER_B2_F1 : word = 2;
_CAN_FILTER_B2_F2 : word = 3;
_CAN_FILTER_B2_F3 : word = 4;
_CAN_FILTER_B2_F4 : word = 5;
Library Example
The example demonstrates CAN protocol. The 1st node initiates the communication with the 2nd node by sending
some data to its address. The 2nd node responds by sending back the data incremented by 1. The 1st node then does
the same and sends incremented data back to the 2nd node, etc.
Code for the rst CAN node:
Copy Code To Clipboard
program CAN_1st;
var Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags, Rx_Data_Len : word;
RxTx_Data : array[8] of byte;
Rx_ID : longint;
Msg_Rcvd : word;
const ID_1st : longint = 12111;
const ID_2nd : longint = 3; // node IDs
begin
ADPCFG := 0xFFFF;
PORTB := 0;
TRISB := 0;
Can_Init_Flags := 0;
Can_Send_Flags := 0;
Can_Rcv_Flags := 0;
Can_Send_Flags := _CAN_TX_PRIORITY_0 and // form value to be used
_CAN_TX_XTD_FRAME and // with CANSendMessage
_CAN_TX_NO_RTR_FRAME;
Can_Init_Flags := _CAN_CONFIG_SAMPLE_THRICE and // form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON and // with CANInitialize
_CAN_CONFIG_XTD_MSG and
_CAN_CONFIG_DBL_BUFFER_ON and
_CAN_CONFIG_MATCH_MSG_TYPE and
_CAN_CONFIG_LINE_FILTER_OFF;