CAN communication interruption problem with FRDM-KV11Z

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

CAN communication interruption problem with FRDM-KV11Z

Jump to solution
2,513 Views
HL_G
Contributor III

When testing the FRDM-KV11Z development board with the SDK provided by the official, it was found that the CAN communication could not enter the interrupt. The SDK routines are used with FreeMASTER software. I don't have this device around, so I ported it myself. The following is my code:

static void init_CAN(void)
{
status_t status;
flexcan_config_t flexcanConfig;
flexcan_timing_config_t timing_config;
uint32_t canSrcClock = CLOCK_GetFreq(kCLOCK_CoreSysClk);

/* Init FlexCAN module. */
/*
* flexcanConfig.clksrc=kFLEXCAN_ClkSrcOsc;
* flexcanConfig.baudRate = 1000000U;
* flexcanConfig.baudRateFD = 2000000U;
* flexcanConfig.maxMbNum = 16;
* flexcanConfig.enableLoopBack = false;
* flexcanConfig.enableSelfWakeup = false;
* flexcanConfig.enableIndividMask = false;
* flexcanConfig.enableDoze = false;
*/
FLEXCAN_GetDefaultConfig(&flexcanConfig);

flexcanConfig.clksrc=kFLEXCAN_ClkSrcPeri;
flexcanConfig.baudRate = 100000U;

/* Update the improved timing configuration */
if (FLEXCAN_CalculateImprovedTimingValues(CAN0, flexcanConfig.baudRate, canSrcClock, &timing_config))
flexcanConfig.timingConfig = timing_config;

FLEXCAN_Init(CAN0, &flexcanConfig, canSrcClock);
/* Enable CAN interrupt. */
EnableIRQ(CAN0_IRQn);

}

void CAN0_IRQHandler(void)
{
uint32_t isrFlags = FLEXCAN_GetStatusFlags(CAN0);
uint32_t isrFlagsMB = FLEXCAN_GetMbStatusFlags(CAN0, 0xFFFFFFFFUL);

count++;

if (isrFlags != 0U)
{
FLEXCAN_ClearStatusFlags(CAN0, isrFlags);
}

if (isrFlagsMB != 0U)
{
/* Read or Write */
if ((isrFlagsMB & (1UL << (FMSTR_FLEXCAN_RXMB))) != 0U)
{

/* Is any data received? */
if (FLEXCAN_GetMbStatusFlags(CAN0, 1UL << (FMSTR_FLEXCAN_RXMB)) == 0U)
{
return;
}
/* Try to read data, when successful, the MB is acknowledged and set for next receive */
status_t s = FLEXCAN_ReadRxMb(CAN0, FMSTR_FLEXCAN_RXMB, &CAN_Rxmsg);
}
if ((isrFlagsMB & (1UL << (FMSTR_FLEXCAN_TXMB))) != 0U)
{
/* Acknowledge frame transmission */
CAN_Txmsg.length = 0U;

}

/* Clear all interrupt flags */
FLEXCAN_ClearMbStatusFlags(CAN0, isrFlagsMB);

}
}

int main(void)
{
status_t status_can;

/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
init_CAN();
PRINTF("SPI DAM Init OK.\r\n");
CAN_Txmsg.format = 1; //扩展帧ID
CAN_Txmsg.timestamp = 1000; //超时时间
CAN_Txmsg.type = 0; //数据帧
CAN_Txmsg.length = 8; //数据长度
CAN_Txmsg.id = 0x123; //帧ID
/* 8位数据 */
CAN_Txmsg.dataByte0 = 0x0;
CAN_Txmsg.dataByte1 = 0x1;
CAN_Txmsg.dataByte2 = 0x2;
CAN_Txmsg.dataByte3 = 0x3;
CAN_Txmsg.dataByte4 = 0x4;
CAN_Txmsg.dataByte5 = 0x5;
CAN_Txmsg.dataByte6 = 0x6;
CAN_Txmsg.dataByte7 = 0x7;


/* 发送数据 */
FLEXCAN_WriteTxMb(CAN0, 0, &CAN_Txmsg);

while (1)
{
status_can = FLEXCAN_WriteTxMb(CAN0, 0, &CAN_Txmsg);
if(status_can != kStatus_Fail)
PRINTF("CAN Write success %d\r\n", count);
else
PRINTF("CAN Write fail %d\r\n", count);
SDK_DelayAtLeastUs(1000000, BOARD_BOOTCLOCKRUN_CORE_CLOCK); //延时1秒

}
}

The data can now be successfully sent. But there is no interrupt to enter, and there is no interrupt to receive data.

0 Kudos
Reply
1 Solution
2,456 Views
HL_G
Contributor III

您好 XuZhang

感谢您提供的支持。

我已经解决这个问题了

View solution in original post

0 Kudos
Reply
2 Replies
2,487 Views
Joey_z
NXP Employee
NXP Employee

hi,HL_G

Thank you for your interest in NXP Semiconductor products and the opportunity to serve you, I will gladly help you with this.

Please confirm whether the development board CAN connect to FreeMASTER through Freemaster-over-can. Please conduct connection test in the following way.

XuZhang_0-1728715517072.png

You can then Enable CAN interrupt by modifying the following program in the SDK's frdmkv11z_fmstr_example_can demo.

XuZhang_1-1728715528707.png

Besides, are you saying you don't have any FreeMaster tools? Below is the download link.

FreeMASTER tool 3.2 (includes Lite 1.3) – Windows installer (nxp.com.cn)

Wish it helps you.

If you still have question about it,please kindly let me know.

 

BR

Xu Zhang

0 Kudos
Reply
2,457 Views
HL_G
Contributor III

您好 XuZhang

感谢您提供的支持。

我已经解决这个问题了

0 Kudos
Reply