1 | /*******************************************************************/
|
2 | /* INITIALISIERUNG */
|
3 | /*******************************************************************/
|
4 | /* Start manipulating CAN0 registrys */
|
5 | CAN0->CCCR.bit.INIT = 1;
|
6 | CAN0->CCCR.bit.CCE = 1;
|
7 |
|
8 | /* MESSAGE RAM CONFIGURATION */
|
9 | // Tx Fifo and Buffer allocation
|
10 | CAN0->TXBC.bit.TBSA = (uint32_t) txBufferElem;
|
11 | CAN0->TXBC.bit.NDTB = 16;
|
12 | CAN0->TXBC.bit.TFQS = 16;
|
13 | CAN0->TXEFC.bit.EFSA = (uint32_t) txEvFivoElem;
|
14 | CAN0->TXEFC.bit.EFS = 32;
|
15 |
|
16 |
|
17 | // Size of Data reserved for Can Data messages
|
18 | CAN0->TXESC.bit.TBDS = 0x7; // 64-Byte data-length
|
19 |
|
20 | /* Set Configurations on Module */
|
21 | // Can nominal Prescaler:
|
22 | CAN0->NBTP.bit.NBRP = 11;//96Mhz / (11+1) = 8Mhz, 8Mhz/16 = 500kHz
|
23 | CAN0->NBTP.bit.NSJW = 3;
|
24 | CAN0->NBTP.bit.NTSEG1 = 10;
|
25 | CAN0->NBTP.bit.NTSEG2 = 3;
|
26 | // Can-fd databit Prescaler:
|
27 | CAN0->DBTP.bit.DBRP = 2; //96Mhz / (2+1) = 32Mhz, 32Mhz/16 = 2Mhz
|
28 | CAN0->DBTP.bit.DSJW = 3;
|
29 | CAN0->DBTP.bit.DTSEG1 = 10;
|
30 | CAN0->DBTP.bit.DTSEG2 = 3;
|
31 | CAN0->DBTP.bit.TDC = 0;
|
32 |
|
33 | /* CCCR - Can Configuration Control*/
|
34 | /* Transmit Pause */
|
35 | CAN0->CCCR.bit.TXP = 1; /* default: 0; The CAN pauses for two CAN bit times before starting next transmission
|
36 | after itself has successfully tramitted a frame. */
|
37 | /* Edge filtering during Bus Integration */
|
38 | CAN0->CCCR.bit.EFBI = 1; // default: 0; Two consecutive dominant tq required to detect an edge for hard synchronization
|
39 | /* Protocol Exception Handling Disabled*/
|
40 | CAN0->CCCR.bit.PXHD = 1; // default: 0;Protocol exception handling disabled.
|
41 | /* Enable CAN-FD */
|
42 | CAN0->CCCR.bit.FDOE = 1; // default: 0; Enable CAN-FD
|
43 | /* Bit Rate Switching Enable */
|
44 | CAN0->CCCR.bit.BRSE = 1; // default: 0; Enable Bit Rate Switching
|
45 | /* GFC- Global Filter Configuration */
|
46 | /* Accept non matching Frames standard */
|
47 | CAN0->GFC.bit.ANFS = 2; // default: 0; Reject non matching frames Standard
|
48 | /* Accept non matching Frames extended */
|
49 | CAN0->GFC.bit.ANFE = 2; // default: 0; Reject non matching frames Extended
|
50 | /* Reject Remote Frames Standard */
|
51 | CAN0->GFC.bit.RRFS = 1; // default: 0; Reject all remote frames with 11-bit Standard IDs.
|
52 | /* Reject Remote Frames Extended */
|
53 | CAN0->GFC.bit.RRFE = 1; // default: 0; Reject all remote frames with 29-bit Extended IDs.
|
54 | /* Rx FIFO 0 Configuration */
|
55 | /* Fifo 0 Operation Mode */
|
56 | CAN0->RXF0C.bit.F0OM = 0; // default: 0; FIFO 0 blocking mode(0), overwrite mode(1).
|
57 | /* Rx FIFO 1 Configuration */
|
58 | /* Fifo 1 Operation Mode */
|
59 | CAN0->RXF1C.bit.F1OM = 0; // default: 0; FIFO 1 blocking mode(0), overwrite mode(1).
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | /* Finish Default Initialisation */
|
65 | CAN0->CCCR.bit.INIT = 0;
|
66 | while(CAN0->CCCR.bit.INIT);
|