/* CANFD RX Message ID*/
typedef struct _CANFD_MSGOBJ_ID {
unsigned SID:11;
unsigned long EID:18;
unsigned SID11:1;
unsigned unimplemented1:2;
} CANFD_MSGOBJ_ID;
/* CANFD RX Message Object */
typedef union _CANFD_RX_MSGOBJ {
struct {
CANFD_MSGOBJ_ID id;
CANFD_RX_MSGOBJ_CTRL ctrl;
CANFD_MSG_TIMESTAMP timeStamp;
} bF;
unsigned int word[4];
unsigned char byte[8];
} CANFD_RX_MSGOBJ;
int main(void)
{
/* Place code to set device speed here. For this example the device speed should be set at 40 MHz
(i.e., the device is operating at 40 MIPS). */
ConfigureDeviceClockFor40MIPS(); // FCY = 40MIPS
/* The dsPIC33CH device features I/O remap. This I/O remap configuration for the CAN FD module
can be performed here. */
SetIORemapForECANModule();
/* Set up the CAN clock generator for 40 MIPS and enable the CAN clock generator. */
ConfigureCanfdClockFor40MIPS();
/* Enable the CANFD module */
C1CONLbits.CON = 1;
/* Place CAN module in configuration mode */
C1CONHbits.REQOP = 4;
while(C1CONHbits.OPMOD != 4);
/* Initialize the C1FIFOBA with the start address of the CAN FIFO message buffer area. */
C1FIFOBAL = (unsigned int) &CanRxBuffer;
/* Set up the CANFD module for 1 Mbps of Nominal bit rate speed and 2 Mbps of Data bit rate. */
C1NBTCFGH = 0x003E;
C1NBTCFGL = 0x0F0F;
C1DBTCFGH = 0x001E;
C1DBTCFGL = 0x0707;
C1TDCH = 0x0002; //TDCMOD is Auto
C1TDCL = 0x1F00;
/* Configure CANFD module to enable BRS */
C1CONLbits.BRSDIS = 0x0;
C1CONHbits.STEF = 0x0; //Don't save transmitted messages in TEF
C1CONHbits.TXQEN = 0x0; // No TXQ
/* Configure FIFO1 to Receive 2 messages*/
C1FIFOCON1Hbits.FSIZE = 0x1; //2 messages
C1FIFOCON1Hbits.PLSIZE = 0x7; //64 bytes of data
C1FIFOCON1Lbits.TXEN = 0x0; //Receive fifo