User manual

316
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
IFS2 = 0
IFS3 = 0
IFS4 = 0
‘ Enable ECAN1 Interrupt
IEC2.C1IE = 1 ‘ enable ECAN1 interrupts
C1INTE.TBIE = 1 ‘ enable ECAN1 tx interrupt
C1INTE.RBIE = 1 ‘ enable ECAN1 rx interrupt
PORTB = 0 ‘ clear PORTB
TRISB = 0 ‘ set PORTB as output,
‘ for received message data displaying
Can_Init_Flags = 0 ‘
Can_Send_Flags = 0 ‘ clear ags
Can_Rcv_Flags = 0 ‘
Can_Send_Flags = _ECAN_TX_PRIORITY_0 and ‘ form value to be used
_ECAN_TX_XTD_FRAME and ‘ with CANSendMessage
_ECAN_TX_NO_RTR_FRAME
Can_Init_Flags = _ECAN_CONFIG_SAMPLE_THRICE and ‘ form value to be used
_ECAN_CONFIG_PHSEG2_PRG_ON and ‘ with CANInitialize
_ECAN_CONFIG_XTD_MSG and
_ECAN_CONFIG_MATCH_MSG_TYPE and
_ECAN_CONFIG_LINE_FILTER_OFF
RxTx_Data[0] = 9 ‘ set initial data to be sent
ECAN1DmaChannelInit(0, 1, @ECAN1RxTxRAMBuffer) ‘ init dma channel 0 for
‘ dma to ECAN peripheral transfer
ECAN1DmaChannelInit(2, 0, @ECAN1RxTxRAMBuffer) ‘ init dma channel 2 for
‘ ECAN peripheral to dma transfer
ECAN1Initialize(1, 3, 3, 3, 1, Can_Init_Flags) ‘ initialize ECAN
ECAN1SetBufferSize(ECAN1RAMBUFFERSIZE) ‘ set number of rx+tx buffers in DMA RAM
ECAN1SelectTxBuffers(0x000F) ‘ select transmit buffers
‘ 0x000F = buffers 0:3 are transmit buffers
ECAN1SetOperationMode(_ECAN_MODE_CONFIG,0xFF) ‘ set CONFIGURATION mode
ECAN1SetMask(_ECAN_MASK_0, -1, _ECAN_CONFIG_MATCH_MSG_TYPE and _ECAN_CONFIG_XTD_MSG)
‘ set all mask1 bits to ones
ECAN1SetMask(_ECAN_MASK_1, -1, _ECAN_CONFIG_MATCH_MSG_TYPE and _ECAN_CONFIG_XTD_MSG)
‘ set all mask2 bits to ones
ECAN1SetMask(_ECAN_MASK_2, -1, _ECAN_CONFIG_MATCH_MSG_TYPE and _ECAN_CONFIG_XTD_MSG)
‘ set all mask3 bits to ones
ECAN1SetFilter(_ECAN_FILTER_10, ID_2nd, _ECAN_MASK_2, _ECAN_RX_BUFFER_7, _ECAN_CONFIG_
XTD_MSG) ‘ set id of lter10 to 2nd node ID
‘ assign mask2 to lter10
‘ assign buffer7 to lter10
ECAN1SetOperationMode(_ECAN_MODE_NORMAL, 0xFF) ‘ set NORMAL mode