k20 FLEXCAN example set to loopback, setup

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

k20 FLEXCAN example set to loopback, setup

Jump to solution
619 Views
Cdn_aye
Senior Contributor I

Hi

I have been trying to get the flexcan example to run in loopback on our board without success. I have a 60 ohm resistor on each CAN-H and CAN-L pair and have tied CAN-H to CAN-L.

I looped the TCAN-H and CAN-L pins in order to follow the suggestion on this forum (twr-k20d72m and can) to allow the Tx line to toggle. I added a separate ISR for the Rx and Tx. What I need  to do is to check the HW functionality at this point using a single board and verify the signal levels.

I checked the init_gpio.c and we are using the default settings for the port pins PTA12 & PTA13 so no changes were needed. I didn't see any setting to enable the FLEXCAN modules in user_config.h. I can step through the init fcns for the CAN system and they do not return any error however I don't see any activity on the Tx line even when I set the code to loop transmitting the text string. I do get one single Tx interrupt but thats it.

So I am wondering if there is another setting somewhere I have missed. The k20dx256 is the same bsp as the k40dx256 so I used the example code for the k40.

I am trying to run this on MQX 4.01. Is loopback a reasonable mode to set the code to run in?

Can anyone tell me my error please. I can try the newer MQX 4.2 but would prefer to get this working under MQX 4.0.1 before expanding the project and potential problems.

Any advice would be appreciated.

Thanks

Robert

0 Kudos
1 Solution
366 Views
Cdn_aye
Senior Contributor I

I found the error on my side. Here are the results in case someone else falls into the same trap.

The CAN_DEVICE definition is in test.h for the 4.0 flexcan example, and is set based on the processor. The bsp has a setting for the processor derivative in a header file, and our compile resulted in CAN_DEVICE to be 1.

In tracing the code there is a case statement in mqx that sets up the CAN pins based on the CAN_DEVICE # using a switch statement. Our define and therefore the switch was set for 1 causing the wrong pin assignments; after changing the device to 0 selected the correct pins and the example worked correctly.

You need first to set the correct pins in init_gpio.c to point to the mux config pin setting you are using on your board. Then I would recommend just defining the CAN_DEVICE to be the actual device you are using manually, ie #define CAN_DEVICE 0    (in our case).

Robert Lewis

View solution in original post

0 Kudos
1 Reply
367 Views
Cdn_aye
Senior Contributor I

I found the error on my side. Here are the results in case someone else falls into the same trap.

The CAN_DEVICE definition is in test.h for the 4.0 flexcan example, and is set based on the processor. The bsp has a setting for the processor derivative in a header file, and our compile resulted in CAN_DEVICE to be 1.

In tracing the code there is a case statement in mqx that sets up the CAN pins based on the CAN_DEVICE # using a switch statement. Our define and therefore the switch was set for 1 causing the wrong pin assignments; after changing the device to 0 selected the correct pins and the example worked correctly.

You need first to set the correct pins in init_gpio.c to point to the mux config pin setting you are using on your board. Then I would recommend just defining the CAN_DEVICE to be the actual device you are using manually, ie #define CAN_DEVICE 0    (in our case).

Robert Lewis

0 Kudos