I am using ECAN on P24EP512GU810. It is connected to an existing bus with two other nodes. If I set mode to NORMAL it decodes ok.
I want to use Listen Only mode so that my node is passive ( doesn't send and packets - including ACK ). I have attached the example code which works fine.
By changing the last line from
ECAN1SetOperationMode(_ECAN_MODE_NORMAL, 0xFF); // set NORMAL mode
to
ECAN1SetOperationMode(_ECAN_MODE_LISTEN, 0xFF);
I was hoping to change operation to passive but still decode packets.
Any help appreciated.
Andy
Code: Select all
/* Clear Interrupt Flags */
IFS0=0;
IFS1=0;
IFS2=0;
IFS3=0;
IFS4=0;
/* Enable ECAN1 Interrupt */
IEC2bits.C1IE = 1; // enable ECAN1 interrupts
C1INTEbits.TBIE = 1; // enable ECAN1 tx interrupt
C1INTEbits.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 flags
Can_Rcv_Flags = 0; //
Can_Send_Flags = _ECAN_TX_PRIORITY_0 & // form value to be used
_ECAN_TX_XTD_FRAME & // with CANSendMessage
_ECAN_TX_NO_RTR_FRAME;
Can_Init_Flags = _ECAN_CONFIG_SAMPLE_THRICE & // form value to be used
_ECAN_CONFIG_PHSEG2_PRG_ON & // with CANInitialize
_ECAN_CONFIG_XTD_MSG &
_ECAN_CONFIG_MATCH_MSG_TYPE &
_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 & _ECAN_CONFIG_XTD_MSG); // set all mask1 bits to ones
ECAN1SetMask(_ECAN_MASK_1, -1, _ECAN_CONFIG_MATCH_MSG_TYPE & _ECAN_CONFIG_XTD_MSG); // set all mask2 bits to ones
ECAN1SetMask(_ECAN_MASK_2, -1, _ECAN_CONFIG_MATCH_MSG_TYPE & _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 filter10 to 2nd node ID
// assign mask2 to filter10
// assign buffer7 to filter10
ECAN1SetOperationMode(_ECAN_MODE_NORMAL, 0xFF); // set NORMAL mode