EasyManuals Logo

Microchip Technology dsPIC33 series User Manual

Microchip Technology dsPIC33 series
116 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #74 background imageLoading...
Page #74 background image
dsPIC33/PIC24 Family Reference Manual
DS70005340A-page 74 2018 Microchip Technology Inc.
Example 6-1: Message Transmission Code Example (Continued)
/* CAN TX Message Object*/
typedef union _CANFD_TX_MSGOBJ {
struct {
CANFD_MSGOBJ_ID id;
CANFD_TX_MSGOBJ_CTRL ctrl;
CANFD_MSG_TIMESTAMP timeStamp;
} bF;
unsigned int word[4];
unsigned char byte[8];
} CANFD_TX_MSGOBJ;
int main(void)
{
unsigned char index;
/* 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.ON = 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) &CanTxBuffer;
/* Set up the CANFD module for 1Mbps of Nominal bit rate speed and 2Mbps of Data bit rate. */
C1NBTCFGH = 0x003E;
C1NBTCFGL = 0x0F0F;
C1DBTCFGH = 0x001E;
C1DBTCFGL = 0x0707;
C1TDCH = 0x0002; //TDCMOD is Auto
C1TDCL = 0x1F00;
/* Configure CANFD module to enable Transmit Queue and BRS*/
C1CONLbits.BRSDIS = 0x0;
C1CONHbits.STEF = 0x0; //Don't save transmitted messages in TEF
C1CONHbits.TXQEN = 0x1;
/* Configure TXQ to transmit 1 message*/
C1TXQCONHbits.FSIZE = 0x0; // single message
C1TXQCONHbits.PLSIZE = 0x7; // 64 bytes of data
/* Configure FIFO1 to transmit 2 messages*/
C1FIFOCON1Hbits.FSIZE = 0x1; //2 messages
C1FIFOCON1Hbits.PLSIZE = 0x2; //16 bytes of data
C1FIFOCON1Lbits.TXEN = 0x1; // Set TXEN bit ,transmit fifo
/* Place the CAN module in Normal mode. */
C1CONHbits.REQOP = 0;
while(C1CONHbits.OPMOD != 0);

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Microchip Technology dsPIC33 series and is the answer not in the manual?

Microchip Technology dsPIC33 series Specifications

General IconGeneral
BrandMicrochip Technology
ModeldsPIC33 series
CategoryMotherboard
LanguageEnglish

Related product manuals