KW38 flexcan example not working

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

KW38 flexcan example not working

1,708 Views
ravi00ei51
Contributor II

Hi,

I am trying to get CAN comms working on KW38 kit. I tries two examples and on both I am facing same issue. 

1. flexcan interrupt transfer

2. flexcan loopback transfer

In the loopback example it works fine if I leave it as loopback. But if I modify the loopback example to only transmit on the real bus by disabling the loopback flag as flase and only checking txcomplete in the while loop in the end. In this case while(!txcomple){...} never exits as txcomplete flag never becomes true.

Same issue is occurring with flexcan interrupt transfer example.

I am not sure what I am doing wrong. I have supplied 12V via J32 connector and have connected CAN-K and CAN-L pin to MCP2515 CAN2SPI board and I am trying to read tx data on CAN bus over SPI on arduino board. 

There is no issue with arduino setup as When I try to connect with a CAN logger it also does not see anything. Please let me know if there is anything I am missing here.

Labels (2)
0 Kudos
3 Replies

1,668 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello,

Which baudrate are you using ?

Could you please help me check the clock source for the CAN module in the example ?  

In case it is defined with the bus clock as source as in this lines

#define EXAMPLE_CAN_CLKSRC kCLOCK_BusClk
#define EXAMPLE_CAN_CLK_FREQ CLOCK_GetFreq(kCLOCK_BusClk)

Could you please try to change it to the following configuration ?

#define EXAMPLE_CAN_CLKSRC kCLOCK_Osc0ErClk
#define EXAMPLE_CAN_CLK_FREQ CLOCK_GetFreq(kCLOCK_Osc0ErClk)/2

Also, could you please help me check this other post [KW36] FlexCAN Bit Timing Parameters Setup and verify the bit setup ?

Regards,

Estephania

0 Kudos

1,668 Views
ravi00ei51
Contributor II

Hi,

As per your suggestion I have changed the clock macros and changes the default baud rate to 500000u in the code as suggested in the link. I am still having the same problem. When I did some debugging I found that when flexcan_callback() function is called the status within the function is 5310(decimal) which is status for ERROR. THen I checked the ESR1 register value by reading CAN_Type * base argument. The ESR1 register has value 0x242752. 

The value of ESR register shows there are some errors on CAN bus. But I am not sure why that would happen as Arduino is working fine with other boards I have tested with CAN. 

Do you have any idea which direction I should debug this?

0 Kudos

1,668 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello,

I would recommend you to try checking the CAN communication wit a logic analyzer and verify both the frame and the baud rate that you are configuring your device.

If the baud rate you configure is the one that you are getting I would do the same on the other side to ensure that both devices communicate with the same baud rate, once you ensure that from both sides .  Check the filtering and mask configured in your code and make sure that both matched for the receiver and transceiver.

Regards,
Estephania

0 Kudos