Hi All,
I want to implement the CAN1 in the evaluation board. I tested CAN0 code with example program it's working. For CAN1, i change the CAN0 pointer to CAN1, pin assignment and MB nos. But i was not working. I was observing the CAN pin PTA12/PTA13 with oscilloscope, the pin was not toggling as like CAN0 pins. Below is my code
void CANT_Init(uint16 bps)
{
uint32_t i=0;
PCC->PCCn[PCC_PORTA_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable clock for PORTE */
PCC->PCCn[PCC_FlexCAN1_INDEX] |= PCC_PCCn_CGC_MASK; /* CGC=1: enable clock to FlexCAN0 */
PORTA->PCR[12] |= PORT_PCR_MUX(3); /* Port A12: MUX = ALT3, CAN1_RX */
PORTA->PCR[13] |= PORT_PCR_MUX(3); /* Port A13: MUX = ALT3, CAN1_TX */
CAN1->MCR |= CAN_MCR_MDIS_MASK; /* MDIS=1: Disable module before selecting clock */
CAN1->CTRL1 &= ~CAN_CTRL1_CLKSRC_MASK; /* CLKSRC=0: Clock Source = oscillator (8 MHz) */
CAN1->MCR &= ~CAN_MCR_MDIS_MASK; /* MDIS=0; Enable module config. (Sets FRZ, HALT)*/
while (!((CAN1->MCR & CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT)) {}
/* Good practice: wait for FRZACK=1 on freeze mode entry/exit */
CAN1->CTRL1 = 0x00DB0006; /* Configure for 500 KHz bit time */
/* Time quanta freq = 16 time quanta x 500 KHz bit time= 8MHz */
/* PRESDIV+1 = Fclksrc/Ftq = 8 MHz/8 MHz = 1 */
/* so PRESDIV = 0 */
/* PSEG2 = Phase_Seg2 - 1 = 4 - 1 = 3 */
/* PSEG1 = PSEG2 = 3 */
/* PROPSEG= Prop_Seg - 1 = 7 - 1 = 6 */
/* RJW: since Phase_Seg2 >=4, RJW+1=4 so RJW=3. */
/* SMP = 1: use 3 bits per CAN sample */
/* CLKSRC=0 (unchanged): Fcanclk= Fosc= 8 MHz */
for(i=0; i<64; i++ ) { /* CAN0: clear 32 msg bufs x 4 words/msg buf = 128 words*/
CAN1->RAMn[i] = 0; /* Clear msg buf word */
}
for(i=0; i<16; i++ ) { /* In FRZ mode, init CAN0 16 msg buf filters */
CAN1->RXIMR[i] = 0xFFFFFFFF; /* Check all ID bits for incoming messages */
}
CAN1->RXMGMASK = 0x1FFFFFFF; /* Global acceptance mask: check all ID bits */
CAN1->RAMn[ 4*MSG_BUF_SIZE + 0] = 0x04000000; /* Msg Buf 4, word 0: Enable for reception */
/* EDL,BRS,ESI=0: CANFD not used */
/* CODE=4: MB set to RX inactive */
/* IDE=0: Standard ID */
/* SRR, RTR, TIME STAMP = 0: not applicable */
CAN1->RAMn[ 4*MSG_BUF_SIZE + 1] = 0x14440000; /* Msg Buf 4, word 1: Standard ID = 0x111 */
/* PRIO = 0: CANFD not used */
CAN1->MCR = 0x0000001F; /* Negate FlexCAN 1 halt state for 32 MBs */
while ((CAN1->MCR && CAN_MCR_FRZACK_MASK) >> CAN_MCR_FRZACK_SHIFT) {}
/* Good practice: wait for FRZACK to clear (not in freeze mode) */
while ((CAN1->MCR && CAN_MCR_NOTRDY_MASK) >> CAN_MCR_NOTRDY_SHIFT) {}
/* Good practice: wait for NOTRDY to clear (module ready) */
}
void FLEXCAN1_transmit_msg(void) { /* Assumption: Message buffer CODE is INACTIVE */
CAN1->IFLAG1 = 0x00000001; /* Clear CAN 0 MB 0 flag without clearing others*/
CAN1->RAMn[ 0*MSG_BUF_SIZE + 2] = 0xA5112233; /* MB0 word 2: data word 0 */
CAN1->RAMn[ 0*MSG_BUF_SIZE + 3] = 0x44556677; /* MB0 word 3: data word 1 */
CAN1->RAMn[ 0*MSG_BUF_SIZE + 1] = 0x15540000; /* MB0 word 1: Tx msg with STD ID 0x555 */
CAN1->RAMn[ 0*MSG_BUF_SIZE + 0] = 0x0C400000 | 8 <<CAN_WMBn_CS_DLC_SHIFT; /* MB0 word 0: */
/* EDL,BRS,ESI=0: CANFD not used */
/* CODE=0xC: Activate msg buf to transmit */
/* IDE=0: Standard ID */
/* SRR=1 Tx frame (not req'd for std ID) */
/* RTR = 0: data, not remote tx request frame*/
/* DLC = 8 bytes */
}
I have referred the below post also
CAN1 Does not work with example code
CAN1 not work,CAN0 is ok
https://community.nxp.com/message/995504?commentID=995504#comment-995504
Here, i have attached the application note containing example code .
Kindly resolve the issue , thanks in advance.
Regards,
Vairamani.V