2015-04-09 03:22 AM
I am using SPC560D-DIS Discovery board for development and SPC5 studio.
I have imported test application 'SPC560Dxx OS-Less CAN Test Application for Discovery' for FlexCAN testing. In this FlexCAN0 is used in loop back mode. It is working in loop back mode. But after disabling loop back mode, it is not transmitting data on CANTx. The code for TX mailbox remain as 0x0C and error handler is generating. Error flags for TWRNINT, BIT0ERR, BOFFINT and ERRINT are set. I used below structure to transmit data, /* CAN TX Message structure */ txmsg.IDE = CAN_IDE_EXT; txmsg.RTR = CAN_RTR_DATA; txmsg.LENGTH = 8; txmsg.data32[0] = 0x55AA55AA; txmsg.data32[1] = 0x00FF00FF;And initialization routine is as below, uint8_t mb_index = 0; uint8_t id = 0; /* Entering initialization mode. */ canp->state = CAN_STARTING; /* Clock activation.*/#if SPC5_CAN_USE_FLEXCAN0 /* Set peripheral clock mode.*/ if(&CAND1 == canp) { SPC5_FLEXCAN0_ENABLE_CLOCK();#if !SPC5_CAN_FLEXCAN0_USE_EXT_CLK canp->flexcan->CR.R |= CAN_CTRL_CLK_SRC;#endif } /* Enable the device.*/ canp->flexcan->MCR.R &= ~CAN_MCR_MDIS; /* * Individual filtering per MB, disable frame self reception, * disable the FIFO, enable SuperVisor mode. */#if SPC5_CAN_USE_FLEXCAN0 if(&CAND1 == canp) canp->flexcan->MCR.R |= CAN_MCR_SUPV | CAN_MCR_MAXMB(SPC5_FLEXCAN0_MB - 1);#endif canp->flexcan->CR.R |= CAN_CTRL_TSYN | CAN_CTRL_RJW(3); /* TX MB initialization.*/#if SPC5_CAN_USE_FLEXCAN0 if(&CAND1 == canp) { for(mb_index = 0; mb_index < (SPC5_FLEXCAN0_MB - CAN_RX_MAILBOXES); mb_index++) { canp->flexcan->BUF[mb_index + CAN_RX_MAILBOXES].CS.B.CODE = 8U; } }#endif /* Unlock Message buffers.*/ (void) canp->flexcan->TIMER.R; /* MCR initialization.*/ canp->flexcan->MCR.R |= canp->config->mcr; /* CTRL initialization.*/ canp->flexcan->CR.R |= canp->config->ctrl; /* Interrupt sources initialization.*/ canp->flexcan->MCR.R |= CAN_MCR_WRN_EN; canp->flexcan->CR.R |= CAN_CTRL_BOFF_MSK | CAN_CTRL_ERR_MSK | CAN_CTRL_TWRN_MSK | CAN_CTRL_RWRN_MSK; /* RX MB initialization.*/ for (id = 0; id < CAN_RX_MAILBOXES; id++) { canp->flexcan->BUF[id].CS.B.CODE = 0U; if (canp->config->RxFilter[id].scale) { canp->flexcan->BUF[id].CS.B.IDE = 1U; canp->flexcan->BUF[id].ID.R = canp->config->RxFilter[id].register1; } else { canp->flexcan->BUF[id].CS.B.IDE = 0U; canp->flexcan->BUF[id].ID.B.STD_ID = canp->config->RxFilter[id].register1; canp->flexcan->BUF[id].ID.B.EXT_ID = 0U; } /* RX MB initialization.*/ canp->flexcan->BUF[id].CS.B.CODE = 4U; } canp->flexcan->RXGMASK.R = 0x0FFFFFFF; /* Enable MBs interrupts.*/#if SPC5_CAN_USE_FLEXCAN0 if(&CAND1 == canp) { if(SPC5_FLEXCAN0_MB == 32) { canp->flexcan->IMRL.R = 0xFFFFFFFF; } else if(SPC5_FLEXCAN0_MB == 64) { canp->flexcan->IMRL.R = 0xFFFFFFFF; canp->flexcan->IMRH.R = 0xFFFFFFFF; } }#endif /* CAN BUS synchronization.*/ canp->flexcan->MCR.B.HALT = 0;Is any configuration is missing / wrong in this?Also on FlexCAN Buad, I used bus clk of 48MHz, and PRESDIV=3, PSEG1=2, PSEG2=7 and PROPSEG=2. Then Sclock will be 48MHz/(3+1) = 12MHz and FlexCAN buad is 12MHz/15 = 800kbps. Is this correct?2015-04-09 09:39 AM
Hello Megha ,
Did you you try to configure on the Pinmap Wizard CAN0RX and CAN0TX ?We should seen your CAN Frames by oscilloscope.Anyway, as soon as possible, we will post an application without LOOBACK mode. Best Regards Erwan2015-04-10 01:52 AM
2015-04-13 06:28 AM
Hello Megha
I Have this like this problem in can i guess the can Clock not worked correctlly i use this buadrate for my board please set these prameters : Set your CAN Clock in External Clock Oscillator = 16.00 MHz PressDive =1 , PropSeg=0 , PSEG1=5 , PSEG2=7 Baudrate =500k i do not know what is your chip model but if your MCU have a multi Pin For CANRX you can set the CANRX Pin in other pin's with setPSMI0_3 Register.
( you can find in Page 338 of Refrence manual RM0017).
Best Regards Nazerian Vanima