User manual

286
mikoC PRO for dsPIC
MikroElektronika
CAN_FILTER Constants
CAN_FILTER constants dene lter codes. Function CANxSetFilter expects one of these as its argument:
Copy Code To Clipboard
const unsigned int
_CAN_FILTER_B1_F1 = 0,
_CAN_FILTER_B1_F2 = 1,
_CAN_FILTER_B2_F1 = 2,
_CAN_FILTER_B2_F2 = 3,
_CAN_FILTER_B2_F3 = 4,
_CAN_FILTER_B2_F4 = 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
unsigned int Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags; // can ags
unsigned int Rx_Data_Len; // received data length in
bytes
char RxTx_Data[8]; // can rx/tx data buffer
char Msg_Rcvd; // reception ag
unsigned long Tx_ID, Rx_ID; // can rx and tx ID
void main() {
ADPCFG = 0xFFFF;
PORTB = 0;
TRISB = 0;
Can_Init_Flags = 0; //
Can_Send_Flags = 0; // clear ags
Can_Rcv_Flags = 0; //
Can_Send_Flags = _CAN_TX_PRIORITY_0 & // Form value to be used
_CAN_TX_XTD_FRAME & // with CAN2Write
_CAN_TX_NO_RTR_FRAME;
Can_Init_Flags = _CAN_CONFIG_SAMPLE_THRICE & // Form value to be used
_CAN_CONFIG_PHSEG2_PRG_ON & // with CAN2Initialize
_CAN_CONFIG_XTD_MSG &
_CAN_CONFIG_DBL_BUFFER_ON &
_CAN_CONFIG_MATCH_MSG_TYPE &
_CAN_CONFIG_LINE_FILTER_OFF;