KSDK2.0 K64F Flexcan_loopback example not trasmitting

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KSDK2.0 K64F Flexcan_loopback example not trasmitting

1,279 Views
wfwf
Contributor II

Hello,

I'm working on a k64f proprietary board whit, among the others, CAN bus. I'm trying to make the sdk2.0 work with a flexcan_loopback example. The example itself works fine but, as I try to connect to a real CAN peripheral, I get stuck on the trasmit procedure, in particular on the "while(!FLEXCAN_GetMbStatusFlags)" loop. The receive procedure works fine and I can succesfully read a CAN message sent from outside, so I guess that the pin configuration and CAN parameters are ok. I tryed either the example loopback procedure and the "only send" procedure suggested on the SDK2 API page (below), but they both stop at the same point.

Any hint would be appreciated,

regards

Walter

BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();

PRINTF("\r\n==FlexCAN loopback functional example -- Start.==\r\n\r\n");

/* Init FlexCAN module. */
/*
* flexcanConfig.clksrc=kFLEXCAN_ClkSrcOsc;
* flexcanConfig.baudRate = 125000U;
* flexcanConfig.maxMbNum = 16;
* flexcanConfig.enableLoopBack = false;
* flexcanConfig.enableSelfWakeup = false;
* flexcanConfig.enableIndividMask = false;
* flexcanConfig.enableDoze = false;
*/
FLEXCAN_GetDefaultConfig(&flexcanConfig);
flexcanConfig.clksrc=kFLEXCAN_ClkSrcPeri;
flexcanConfig.enableLoopBack = false; //THIS WAS TRUE!
FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig, CLOCK_GetFreq(EXAMPLE_CAN_CLKSRC));

/* Enable FlexCAN module. */
FLEXCAN_Enable(EXAMPLE_CAN, true); //THIS LINE WASN'T THERE

/* Setup Rx Message Buffer. */
mbConfig.format = kFLEXCAN_FrameFormatStandard;
mbConfig.type = kFLEXCAN_FrameTypeData;
mbConfig.id = FLEXCAN_ID_STD(0x123);
FLEXCAN_SetRxMbConfig(EXAMPLE_CAN, RX_MESSAGE_BUFFER_NUM, &mbConfig, true);

/* Setup Tx Message Buffer. */
FLEXCAN_SetTxMbConfig(EXAMPLE_CAN, TX_MESSAGE_BUFFER_NUM, true); //W true

/* Enable Rx Message Buffer interrupt. */
FLEXCAN_EnableMbInterrupts(EXAMPLE_CAN, 1 << RX_MESSAGE_BUFFER_NUM);
EnableIRQ(EXAMPLE_FLEXCAN_IRQn);

/* Prepare Tx Frame for sending. */
txFrame.format = kFLEXCAN_FrameFormatStandard;
txFrame.type = kFLEXCAN_FrameTypeData;
txFrame.id = FLEXCAN_ID_STD(0x223); //I CHANGED THE MB ID
txFrame.length = 8;
txFrame.dataWord0 = CAN_WORD0_DATA_BYTE_0(0x11) | CAN_WORD0_DATA_BYTE_1(0x22) | CAN_WORD0_DATA_BYTE_2(0x33) |
CAN_WORD0_DATA_BYTE_3(0x44);
txFrame.dataWord1 = CAN_WORD1_DATA_BYTE_4(0x55) | CAN_WORD1_DATA_BYTE_5(0x66) | CAN_WORD1_DATA_BYTE_6(0x77) |
CAN_WORD1_DATA_BYTE_7(0x88);

PRINTF("Send message from MB%d to MB%d\r\n", TX_MESSAGE_BUFFER_NUM, RX_MESSAGE_BUFFER_NUM);
PRINTF("tx word0 = 0x%x\r\n", txFrame.dataWord0);
PRINTF("tx word1 = 0x%x\r\n", txFrame.dataWord1);

/* Send data through Tx Message Buffer using polling function. */
FLEXCAN_TransferSendBlocking(EXAMPLE_CAN, TX_MESSAGE_BUFFER_NUM, &txFrame);

==== HERE IT STOPS , no tx message and so no flag====
PRINTF("sent tx word1 = 0x%x\r\n", txFrame.dataWord1);
/* Waiting for Message receive finish. */
while (!rxComplete)
{
}

PRINTF("\r\nReceved message from MB%d\r\n", RX_MESSAGE_BUFFER_NUM);
PRINTF("rx word0 = 0x%x\r\n", rxFrame.dataWord0);
PRINTF("rx word1 = 0x%x\r\n", rxFrame.dataWord1);

/* Stop FlexCAN Send & Receive. */
FLEXCAN_DisableMbInterrupts(EXAMPLE_CAN, 1 << RX_MESSAGE_BUFFER_NUM);

PRINTF("\r\n==FlexCAN loopback functional example -- Finish.==\r\n");

while (1)
{
__WFI();
}
}

Procedure from the SDK2 API page

 flexcan_config_t flexcanConfig;
 flexcan_frame_t txFrame;
 /* Initialize board hardware. */
 BOARD_InitPins();
 BOARD_BootClockRUN();
 BOARD_InitDebugConsole();

 PRINTF("\r\n==WW FlexCAN loopback functional example WW-- Start.==\r\n\r\n");
 /* Init FlexCAN module. */
 FLEXCAN_GetDefaultConfig(&flexcanConfig);
 flexcanConfig.clksrc=kFLEXCAN_ClkSrcPeri;
 flexcanConfig.enableSelfWakeup = true;     //Originally "false", tested both
 //FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig);
 FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig, CLOCK_GetFreq(EXAMPLE_CAN_CLKSRC));
 /* Enable FlexCAN module. */
 FLEXCAN_Enable(EXAMPLE_CAN, true);
 /* Sets up the transmit message buffer. */
 FLEXCAN_SetTxMbConfig(EXAMPLE_CAN, TX_MESSAGE_BUFFER_INDEX, true);
 /* Prepares the transmit frame for sending. */
 txFrame.format = kFLEXCAN_FrameFormatStandard;
 txFrame.type = kFLEXCAN_FrameTypeData;
 txFrame.id = FLEXCAN_ID_STD(0x123);
 txFrame.length = 8;
 txFrame.dataWord0 = CAN_WORD0_DATA_BYTE_0(0x11) |
 CAN_WORD0_DATA_BYTE_1(0x22) |
 CAN_WORD0_DATA_BYTE_2(0x33) |
 CAN_WORD0_DATA_BYTE_3(0x44);
 txFrame.dataWord1 = CAN_WORD1_DATA_BYTE_4(0x55) |
 CAN_WORD1_DATA_BYTE_5(0x66) |
 CAN_WORD1_DATA_BYTE_6(0x77) |
 CAN_WORD1_DATA_BYTE_7(0x88);
 /* Writes a transmit message buffer to send a CAN Message. */
 FLEXCAN_WriteTxMb(EXAMPLE_CAN, TX_MESSAGE_BUFFER_INDEX, &txFrame);
 /* Waits until the transmit message buffer is empty. */
 while (!FLEXCAN_GetMbStatusFlags(EXAMPLE_CAN, 1 << TX_MESSAGE_BUFFER_INDEX))
==== HERE IT STOPS, no tx message and so no flag====
 /* Cleans the transmit message buffer empty status. */
 FLEXCAN_ClearMbStatusFlags(EXAMPLE_CAN, 1 << TX_MESSAGE_BUFFER_INDEX);
 __asm("nop");
Labels (1)
0 Kudos
6 Replies

774 Views
wfwf
Contributor II

Hello,

I finally make it work by playing with the CAN baudrate: I'm enable to receive until a speed of 125kb/s and to trasmit until a speed of 50kb/s. I was able to use the same device until a speed of 250kb/s with KDS 3.0.0 and KSDK 1.3.0 with PEx. Is there any reason why I cannot use the "loopback example" on the same HW over that frequency??

Is it a consequence of a wrong configuration? what about the speed tables of the CAN module?

thank you

0 Kudos

774 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi wf wf,

    Did you test it in the FRDM-K64 board with KSDK2.0-FRDM-K64 code which can be downloaded from this link:

Welcome to Kinetis Expert | Kinetis Expert

I have run the code :SDK_2.0_FRDM-K64F\boards\frdmk64f\driver_examples\flexcan\loopback  directly on my FRDM-K64 board, it works ok on my side.

flexcanConfig.enableLoopBack = true;

The test result is:

pastedImage_1.png

  KSDK2.0-FRDM-K64 is for FRDM-K64 board, this board is using the external 50Mhz clock, so please also check your board, whether it is caused by the clock configuration, or you also can use the external 50Mhz clock input to pin PTA18/EXTAL0


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

774 Views
wfwf
Contributor II

Hi Kerry,

thanks for your answer. The example itself works fine and the loopback is ok. The problem arise when I try to connect to a real CAN device (so loopback=false). The clock come from a 50MHz source connected to the right pin, so maybe the problem resides in clock configuration? By looking at which files may I give you some detailed informations?

thank you

walter

0 Kudos

774 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi wf wf,

    How did you connect the real CAN device? As you know K64 don't have the internal CAN controller, you need to add the external CAN controller to transform the voltage, then another CAN node still need to connect to the CAN controller, then use CAN_H and CAN_L to connect to the bus.

    Please check your connection at first. Besides, then FRDM-K64 board don't have the on board CAN controller.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

774 Views
wfwf
Contributor II

Hi Kerry,

I'm using my own k64f board, and I'm connecting to the CANbus through a SN65HVD234D transceiver (CanTx/Rx on CPU side and CAN_H/CAN_L on other side). Without FreeRTOS I can communicate up to 250Kbit/s on the same CAN line, otherwise the fastest speed is 50Kbit/s

thank you

0 Kudos

774 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi wf wf,

   Do you mean, your problem only happens in the FreeRTOS? Normal bare mental code have no problem?

   If yes, please create a post for FreeRTOS CAN question, we will have the according expert to help you for the FreeRTOS question, I am the bare mental engineer.

   Thanks a lot for your understanding.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos