User manual

mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
261
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
CAN1Initialize(1,3,3,3,1,Can_Init_Flags) ‘ initialize CAN
CAN1SetOperationMode(_CAN_MODE_CONFIG,0xFF) ‘ set CONFIGURATION mode
CAN1SetMask(_CAN_MASK_B1, -1, _CAN_CONFIG_MATCH_MSG_TYPE and _CAN_CONFIG_XTD_MSG)
‘ set all mask1 bits to ones
CAN1SetMask(_CAN_MASK_B2, -1, _CAN_CONFIG_MATCH_MSG_TYPE and _CAN_CONFIG_XTD_MSG)
‘ set all mask2 bits to ones
CAN1SetFilter(_CAN_FILTER_B1_F1,ID_1st,_CAN_CONFIG_XTD_MSG) set id of lter_B1_F1
to 1st node ID
CAN1SetOperationMode(_CAN_MODE_NORMAL,0xFF) ‘ set NORMAL mode
while TRUE
Msg_Rcvd = CAN1Read(Rx_ID , RxTx_Data , Rx_Data_Len, Can_Rcv_Flags)
if ((Rx_ID = ID_1st) and (Msg_Rcvd <> 0)) <> 0 then
PORTB = RxTx_Data[0] ‘ output data at portB
RxTx_Data[0] = RxTx_Data[0] + 1
CAN1Write(ID_2nd, RxTx_Data, 1, Can_Send_Flags) ‘ send incremented data back
end if
wend
end.