Bus Can example

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

Bus Can example

1,427 Views
xavierbuhot
Contributor II

Hello,

I try to use the bus can example "can_loopback_node" on my K60 kinetis.

It seems there is a problem with the driver. This is what I get on the pin on logical level:

20151119135307 - HostingPics.net - Hébergement d'images gratuit

The data don't seem to be correctly send.

I try on different ports and on CAN0 and CAN1 but I still have this result.

Does someone have already get that problem?

Best regard.

0 Kudos
3 Replies

999 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Xavier BUHOT,

     Could you tell me the full name of your tower boad? TWR-K60D100M or TWR-K60N512?

    If you are using TWR-K60D100M, you can use the KSDK1.3.0, there has the according CAN code, that code can work ok.

    After you install the KSDK1.3.0, you will find the sample code from this folder:C:\Freescale\KSDK_1.3.0\examples\twrk60d100m\driver_examples\flexcan\flexcan_loopback

Please refer to Kinetis SDK v.1.3 Demo Applications User's Guide.pdf which you can find from this path:

C:\Freescale\KSDK_1.3.0\doc

Chapter 44 FlexCAN Example

Wish it helps you!

If you have any question when you use the KSDK CAN code, please let me know!

Have a great day,

Jingjing

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

0 Kudos

999 Views
ndavies
Contributor V

Are you trying to send a CAN frame of all zeros? This could be a correct waveform for all Zeros. CAN will flip the polarity of every 5th bit if all 5 bits are the same. this is designed this way to keep sync. (Bit Stuffing)

Unfortunately you haven't given enough information for anyone to help you. More information on the screen shot would be helpful.

1. which pin is the scope connected too?

2. What are the scope settings? time /div

3. What baud rate do you want to transmit at?

4. What data are putting into the CAN data registers to send?

Are you really using a "loopback demo"? Most loopback demos never transmit anything due to the loopback bit being set in CAN register CTRL1.

With the number of CAN loopback examples coming with different compilers and SDKs, You will need to be more specific in the example code you used.

If you transmitted all zeros, turned off the loopback bit in CTRL1, the signal is only coming out of the CAN transmit pin and only comes out when you scheduled it (No frames continuously repeated, back to back with no time in between), Your CAN bus is working correctly.

0 Kudos

999 Views
xavierbuhot
Contributor II

The data I send is 5 bytes of 0xA5.

So I have a K60DN512 twrkit.

I tried to send on CAN0 and CAN1 which pin areCAN0_USE_PTB18_19 (for CAN0) and CAN1_USE_PTE24_25 (for CAN1).

I alway put 5 bytes of 0xA5 at 83 Khz.

Here is the configuration file  can_config.h:

<CODE>

/*=================================================================================================================*/

// Definition of FlexCAN control bits

#define FLEXCAN_CLOCK_SOURCE      1       /* clock source for FlexCAN: 0 -- external oscillator, 1 -- bus clock from PLL */

#define FLEXCAN_SELF_RECEPTION    0       /* enable self-reception: 0 - disable self-reception; 1 -- enable self-reception */

#define FLEXCAN_SCAN_PRIORITY     0       /* scan prio: 0 -- RxFIFO first, 1 -- MB first */

#define FLEXCAN_STORE_RTR         0       /* remote request storing: 0 -- do not store RTR, 1 -- store RTR as data frame */

#define FLEXCAN_ENTIRE_ARB_CMP    0       /* entire frame arbitration filed comparision including IDE,RTR, excluding RxFIFO

                                           * 0 -- always compare ID of Rx MB regardless of masks, but not compare RTR

                                           * 1 -- mask compare both Rx MB ID and RTR

                                           */   

#define FLEXCAN_INDIVIDUAL_MASK   0       /* individual Rx Masking and queue enable:

                                           * 0 -- message queue is enabled, and masking with RXMGMASK/RX14MASK/RX15MASK,RXFGMASK

                                           * 1 -- message queue is disabled, and individual masking with RXIMRn

                                           */

#define FLEXCAN_LOCAL_PRIO        0       /* local priority enable: 0 -- disabled, 1 -- enabled */

#define FLEXCAN_LOOP_BACK         0       /* loop back for single node: 0 -- no loopback, 1 -- loopback */

/* NOTE: if use LOOPBACK, self-reception must be enabled by defining*/

//#define FLEXCAN_SELF_RECEPTION  1

#define FLEXCAN_NO_RXFIFO_FILTERS 0//8       /* # of Rx FIFO filters: 0 -- Rx FIFO disabled, or 8/16/24/32/40 */

#define FLEXCAN_ID_TAB_FORMAT     0       /* Rx FIFO ID table format: 0 -- Format A, 1 -- Format B, 2 -- Format C, 3 -- Format D */

// Configuration of MBs

#define NUMBER_OF_RX_MB        12        /* # of Receive MBs, can be changed per application */

#define NUMBER_OF_TX_MB        (NUMBER_OF_MB-NUMBER_OF_RX_MB)    /* # of MBs are  for Transmit MBs */

// Definition of Receive MBs index

#define    FLEXCAN_RX_MB_START    0 //0                           /* start # of Rx MB */

#define    FLEXCAN_RX_MB_END    0 //(NUMBER_OF_RX_MB-1)         /* end # of Rx MB */

// Definition of Transmit MBs index

#define FLEXCAN_TX_MB_START    1 //(FLEXCAN_RX_MB_END+1)

#define    FLEXCAN_TX_MB_END    (NUMBER_OF_MB-1)

// Definition of max # of custom mails

#define MAX_RX_MAILS      20

#define MAX_TX_MAILS      20

#define MAX_RXFIFO_MAILS  10

</CODE>

The scope settings 1V/Div and 500us/div.

0 Kudos