Hi,
I am planning to add CAN2 to SLN_LOCAL2 and I am able to initialise the CAN communication but not able to transmit can message and it gets struck at this line "while (!FLEXCAN_GetMbStatusFlags(CAN2, 1 << FrameTx));"
/*******************************************************************************
* Initialise CAN
******************************************************************************/
void CAN_INIT()
{
/* Initialise CAN */
flexcan_config_t flexcanConfig;
flexcanConfig.clksrc=kFLEXCAN_ClkSrc0;
flexcanConfig.baudRate = 50000U;
flexcanConfig.maxMbNum = 16;
flexcanConfig.enableLoopBack = false;
flexcanConfig.enableSelfWakeup = false;
flexcanConfig.enableIndividMask = false;
flexcanConfig.disableSelfReception = false;
flexcanConfig.enableListenOnlyMode = false;
flexcanConfig.enableDoze = false;
FLEXCAN_Init(CAN2, &flexcanConfig, 80000000UL);
configPRINTF(("\r\nCAN initialized"));
/* Enable FlexCAN module. */
FLEXCAN_Enable(CAN2, true);
}
/*******************************************************************************
* CAN Transmit Function
******************************************************************************/
void CAN_SEND(long CANID,char m1,char m2,char m3,char m4,char m5,char m6,char m7,char m8,int CANDLC)
{
status_t status1;
flexcan_frame_t txFrame;
/* Enable FlexCAN module. */
uint8_t FrameTx=1UL;
FLEXCAN_Enable(CAN2, true);
/* Sets up the transmit message buffer. */
FLEXCAN_SetTxMbConfig(CAN2, FrameTx, true);
/* Prepares the transmit frame for sending. */
txFrame.format = kFLEXCAN_FrameFormatStandard;
txFrame.type = kFLEXCAN_FrameTypeData;
txFrame.id = FLEXCAN_ID_STD(CANID);
txFrame.length = CANDLC;
txFrame.dataWord0 = CAN_WORD0_DATA_BYTE_0(m1) |
CAN_WORD0_DATA_BYTE_1(m2) |
CAN_WORD0_DATA_BYTE_2(m3) |
CAN_WORD0_DATA_BYTE_3(m4);
txFrame.dataWord1 = CAN_WORD1_DATA_BYTE_4(m5) |
CAN_WORD1_DATA_BYTE_5(m6) |
CAN_WORD1_DATA_BYTE_6(m7) |
CAN_WORD1_DATA_BYTE_7(m8);
/* Writes a transmit message buffer to send a CAN Message. */
status1=FLEXCAN_WriteTxMb(CAN2, FrameTx, &txFrame);
configPRINTF(("\r\nCAN Message sent %d",status1));
/* Waits until the transmit message buffer is empty. */
while (!FLEXCAN_GetMbStatusFlags(CAN2, 1 << FrameTx));
/* Cleans the transmit message buffer empty status. */
FLEXCAN_ClearMbStatusFlags(CAN2, 1 << FrameTx);
}
This is the example code from SDK. I was having proble in initialise CAN clock and initialised UART clock and the problem dissapeard is it something to do with it.
Does any one has sample or example code in FreeRTOS?