MKS22FN128 - Issue with CAN BUS

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

MKS22FN128 - Issue with CAN BUS

420 Views
john_keates
Contributor I

We have been trying to get the CAN 1 running on the KS22 micro, the data is being sent but we get nothing but can bus errors.

When we examine the ID on the transmitted message its zero? We used the example code and this is the same.

We noticed a note in the documentation which seems to infer that we need an external oscillator, we are currently using the internal and have not used an external osc. Do we need an external osc? we have tried all methods of bit timing, rewritten the config several times.

We have never had an issue of this sort before having worked mainly on the S32 and LPC229xx  we are concerned that this micro may have an issue.We have used a very simple setup below and just concentrating on CAN1, but I am out of ideas?

flexcan_config_t flexcanConfig;
flexcan_rx_mb_config_t mbConfig;

/* Initialize board hardware. */
BOARD_InitBootPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();

/* 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 = true;
flexcanConfig.baudRate = 500000U;
//FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig, CLOCK_GetFreq(EXAMPLE_CAN_CLKSRC));
FLEXCAN_Init(EXAMPLE_CAN1, &flexcanConfig, CLOCK_GetFreq(EXAMPLE_CAN_CLKSRC));

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

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

/* Create FlexCAN handle structure and set call back function. */
//FLEXCAN_TransferCreateHandle(EXAMPLE_CAN, &flexcanHandle, flexcan_callback, NULL);
FLEXCAN_TransferCreateHandle(EXAMPLE_CAN1, &flexcanHandle, flexcan_callback, NULL);

/* Start receive data through Rx Message Buffer. */
rxXfer.frame = &rxFrame;
rxXfer.mbIdx = RX_MESSAGE_BUFFER_NUM;
FLEXCAN_TransferReceiveNonBlocking(EXAMPLE_CAN1, &flexcanHandle, &rxXfer);

 

/* Prepare Tx Frame for sending. */
txFrame.format = kFLEXCAN_FrameFormatStandard;
txFrame.type = kFLEXCAN_FrameTypeData;
txFrame.id = FLEXCAN_ID_STD(0x223);
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);

/* Send data through Tx Message Buffer. */
txXfer.frame = &txFrame;
txXfer.mbIdx = TX_MESSAGE_BUFFER_NUM;
FLEXCAN_TransferSendNonBlocking(EXAMPLE_CAN1, &flexcanHandle, &txXfer);

Any suggestions or help would be really appreciated - otherwise we are going to have to redesign on an alternative process, whcih we would rather not do.

0 Kudos
1 Reply

393 Views
_Leo_
NXP TechSupport
NXP TechSupport

Thank you so much for your interest in our products and for using our community.

I have noticed that you have another ticket with the same topic, please consult the follow-up in this last one that I mention.

Have a nice day!

0 Kudos