CAN BUS communication for MK20DN512VLL10

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

CAN BUS communication for MK20DN512VLL10

3,194 Views
kiemvo
Contributor II

We are developing a motion control board using the below processor

K20DN512VLL10

I have pin 100, 98, 97,72, and 71 connected to a CAN transceiver (CAN address pin 0 - 4).  I also have pin 99, 42, and 43 connected to CAN transceiver (CAN_speed, CAN_TX, and CAN_RX).  There is also a DIP switch to set the CAN address.  Do you have any sample code for CAN communication on this chip?  What SDK is the best for this kind of development?  Thank you very much.

Labels (1)
29 Replies

1,854 Views
kiemvo
Contributor II

It is Kinetis CAN peripheral.  You can see the schematic portion below.  The CAN I/O ports are connected to a switch and then to the MCU pins as describe above. 

2016-12-10_223221.jpg

0 Kudos

1,855 Views
mjbcswitzerland
Specialist V

Hi

You can get K20DN512 dual-CAN support at
http://www.utasker.com/kinetis.html

CAN document at http://www.utasker.com/docs/uTasker/uTaskerCAN.PDF

Video of utilisation: https://www.youtube.com/watch?v=Ha8cv_XEvco
including simulation and monitoring of CAN bus with Total Phase Komodo CAN Duo.

Works directly with KDS, CW, S32, IAR, Keil, Atollic, Rowley, Green Hills, CooCox, GCC, VS so IDE is simply a case of preference. The simulation interface simplifies developments greatly compared to traditional methods.

Regards

Mark

0 Kudos

1,855 Views
kiemvo
Contributor II

Hello Mark,

Thank you very much for the CAN links. The main task that we need to do right now us to provide CAN addressing using DIP switch and basic CAN communication. Since we are new to CAN bus, what are the appropriate steps and recommendations?

--

Regards,

Kiem

0 Kudos

1,855 Views
mjbcswitzerland
Specialist V

Hi Kiem

You can get more details about CAN addressing at https://en.wikipedia.org/wiki/CAN_bus

Since you have a 5 bit DIP switch on your board you can only set 5 of the 11 or (extended addressing mode) 18 bits so you will need to define what address range or which masks you use with this. Based on the DIP switch value you can set the rx ID and its mask as appropriate and receive and CAN message addressed to it.

Eg. of setting a unique extended address and starting operation would be something like:

    unsigned char ucID = fnReadDIP(); // get 5 bits of ID
    ucID |= 0x26c0;                   // add fixed bits

    CANTABLE tCANParameters;                                             // table for passing information to driver
...
    tCANParameters.ulRxID = (CAN_EXTENDED_ID | ucID);                    // our ID (extended)
    tCANParameters.ulRxIDMask = CAN_EXTENDED_MASK;
...
    CAN_interface_ID0 = fnOpen(TYPE_CAN, FOR_I_O, &tCANParameters);      // open interface

Each time a message is received for the ID there is an event called CAN_RX_MSG which is handled by

Length = fnRead(CAN_interface_ID0, ucInputMessage, (GET_CAN_RX_TIME_STAMP | GET_CAN_RX_ID)); // read received CAN message
This places the ID of the transmitter, the message time stamp, plus the message content into the buffer ucInputMessage, which can then be processed accordingly.
You can see this in operation in the video.

Regards

Mark

0 Kudos

1,850 Views
kiemvo
Contributor II

Hello Mark,

We have implemented CAN bus.  However, we have an issue.  The CAN master keeps sending out messages (we probed and saw the waveform on Oscilloscope), but the slave nodes cannot receive or respond.  We also probed CAN-H and CAN-L pins of the slave and saw the exact waveform, but the slaves take no actions.  In the meantime, it seems to us that the sending function had issue with interruption (it could not get out the critical session).  My co-worker has also posted the question here https://community.nxp.com/message/866758 .  Any helps will be greatly appreciate. 

0 Kudos

1,850 Views
mjbcswitzerland
Specialist V

Hi Kiem

Unfortunately I can't really help with PE generated code - possibly it is not correctly mapping the interrupt ID to match the chip you use?

Take a look at the uTasker project that you received to see how it does it (you can also check the operation in VisualStudio without need for HW).

Regards

Mark

1,850 Views
kiemvo
Contributor II

Thanks a lot for all your advice and suggestions.  The problem was about the cable we used.  It has twisted wires inside.  Problem is now solved.  

0 Kudos

1,855 Views
kiemvo
Contributor II

Wow. Thanks for the quick response. Our firmware is based on Trinamic (see below). Would the utasker code can be ported in easily based on your experience? Have a good day.

http://www.trinamic.com/support/eval-kits/eval-kits/landungsbruecke

--

Regards,

Kiem

0 Kudos

1,855 Views
mjbcswitzerland
Specialist V

Hi Kiem

The uTasker project works immediately on almost any Kinetis (K, KL, KE, KEA, KV, KM etc.) and can be ported to any board within few minutes.

pastedImage_1.png

I just set up a "TRINAMIC Landungsbrücke" target (see above) but couldn't complete it immediately due to the fact that the evaluation board is not correctly supported on the TRINAMIC web site - it gives you an STM32 based circuit diagram instead.... I see that the boards are obtainable at Digikey but are not that cheap. I therefore wonder why you chose this board and whether it is in fact used by anyone else?


I wrote to TRINAMIC to point out that the circuits are incorrect and also that they spell "Fresscale" incorrectly but got an automated response that technical support is only possibly via a ticketing system at a certain link. The link pointed to a dead page and on the web site there only mention of an old ticketing system that seems to no longer be offered. However I did later receive a response with the correct set diagrams and so have completed it in the meantime. Note that the chip on the board is the K20DX256VLL10 and not K20DN512VLL10!

Regards

Mark

1,855 Views
kiemvo
Contributor II

Hi Mark,

This board will be used by our customer.  Currently they want to have CAN addressing and CAN communication on it.  That was why we had to use this board.  Please let me know if you get any responses from Trinamic.  We look forward to have a direction on how to implementing this on the board.  What are the necessary steps from your point of view?  Below are the steps that we have done.

1)  Got the KSDK

2)  Compiled the firmware code from Trinamic successfully.  We were able to get the .hex file and ready to load onto the board. 

Can you recommend us what to do next?  We are looking on how CAN works, but what other information can we get?  How do we get CAN driver for the chip that we use (K20DN512VLL10)?  Thanks a lot for your help.  We really appreciate it.  

0 Kudos

1,855 Views
mjbcswitzerland
Specialist V

Hi

In the uTasker project you can immediately run CAN on your board by doing the following:
- import the project into KDS (or other IDE of preference) - KDS import details are at http://www.utasker.com/kinetis/compilers.html#KDS
- enable TEENSY_3_1 as target (in config.h) - this is close to your board
- change #define KINETIS_MAX_SPEED    72000000 to 100000000 (in config.h) to match your part
- enable CAN (in config.h) with #define CAN_INTERFACE
- change the command line interface to match your board (RS232) in app_hw_kinetis.h with
#define DEMO_UART    4
- change the package size from
#define PIN_COUNT       PIN_COUNT_64_PIN to PIN_COUNT_100_PIN

When you run this code on your board it will offer a command line interface on the RS232 with a CAN menu. It will configure CAN on PTA12 and PTA13 at 1'000'000 b/s

The command line menu allows the following things to be done:

   CAN commands
===================
up             go to main menu
can            Send to default [ch] <data hex>
can_s          Send to id [ch] <id> <data hex>
can_e          Send to ext. id [ch] <id> <data hex>
can_r          Request remote default [ch]
can_rs         Request remote id [ch] <id>
can_re         Request remote ext. id [ch] <id>
can_f          Free remote rx when no response
can_d          Deposit remote message [ch] <data hex>
can_c          Clear remote message [ch]
help           Display menu specific help
quit           Leave command mode

More details at the video. You can then change IDs used, the frequency, port pin used or the CAN controller used in the CAN configuration interface if desired.

This doesn't use KSDS; if you need to use KSDS you need to experiment with any CAN support that it has. You will probably need to use the KSDS forum in this case.

Regards

Mark

0 Kudos

1,850 Views
kiemvo
Contributor II

Thanks for the info, Mark.  The problem is that we need to use the Landungsbruecke firmware and develop everything based on that one.  Please correct me if I am wrong about the information that I have for the past few day.

Let's say I have a board that use Kinetis chip.  This is a simple board the SPI, UART, PWM, USB and CAN, and I would like to develop a firmware for it.  So what I need to do is:

1)  Get the KSDS and use Processor Expert to generate the driver for those interfaces.

2)  Modify those drivers to match with the hardware (pin, clock speed, etc...)

3)  Compile and generate the firmware that has all those drivers

4)  Load onto the board

Am I missing any steps?  This is the first time we work with Kinetis chip.  We have worked with Sigma Designs chip before.  Now, let say we have a firmware and would like to add another interface like Step/Direction.  Do we have to redo all the above steps again or we can just use the Processor Expert to generate the needed interface driver and combine it to the exist firmware?

Thank you very much again. 

0 Kudos

1,850 Views
mjbcswitzerland
Specialist V

Hi

There are various methods to achieve a firmware solution (they will all work at the end) - the main difference being in the amount of time it takes to complete the exercise to the required level of functionality and quality.

The Landungsbruecke software is a simple main loop calling some parts that look to be specific to their external motor parts. Then they have packed in a number of peripherals that look to originate from the Freescale libraries - I don't know whether they work in the project or are there to help extensions.

If I were doing the project I would simply drop this main loop into a task in the uTasker project so that you have all of that plus a more flexible project (including more peripherals and more USB classes, the peripherals that you need that are also documented). PE is not of any advantage in this case since the work has already been completed.

If you prefer to use PE and mix parts from various sources and adapt their drivers where necessary it is also possible but may take many times longer before you have basic functionality and possible many times longer again until you have complete reliable operation - depending on your experience.

Adding existing code that you have to a project is described in chapter 8 of http://www.utasker.com/docs/uTasker/uTaskerV1.4_user_guide.PDF
I would estimate about 3 hours work to complete an operating framework of such a project using this technique (with some learning of project details on the way and I would also directly simulate the Tinamic part in the process to be sure of its details and the correct operation before attempting to run on the HW).

Regards

Mark

0 Kudos

1,850 Views
kiemvo
Contributor II

Thanks for your valuable information.  Let's say for the current code from Trinamic (for Landungsbruecke board) and forget about other interfaces, if I would like to have CAN communication only, where and how I can obtain the CAN library source code and driver?  Do I need to use PE to generate it or I can just get the source code and driver from NXP?  Sorry about these questions but this is the first time we work with Freescale MCU.  When I searched the project structure, there is only CAN_PDD.h file.  Thanks again. 

0 Kudos

1,850 Views
mjbcswitzerland
Specialist V

Kiem

I am sorry but I don't work with the PE or the KSDK components.


If you need an immediate and complete solution I can give you one but if you need to use the NXP components I can't help and you will need to contact NXP, wait until someone can help, or experiment until you achieve it. Probably it is better to ask in the KSDK forum rather than the general Kinetis one.

Regards

Mark

0 Kudos

1,850 Views
kiemvo
Contributor II

Hello Mark,

What is the best complete solution to achieve this in a minimal amount of time?  Thank you very much. 

0 Kudos

1,850 Views
mjbcswitzerland
Specialist V

Kiem

I suggested a solution on 13th December with an estimation of about 3 hours effort to integrate the Tinamic framework into a proven environment. My recommendation hasn't changed from that in the meantime.

Regards

Mark

0 Kudos

1,850 Views
kiemvo
Contributor II

Thanks so much for all your helps.  Your information is really helpful.  Have a good day.

0 Kudos

1,855 Views
egoodii
Senior Contributor III

The list of connections is confusing.  Are you working with the internal Kinetis CAN peripheral, or an external CAN packet processor?

0 Kudos

1,855 Views
kiemvo
Contributor II

Hello Earl,

We use Kinetis CAN peripheral.  We have implemented CAN bus.  However, we have an issue.  The CAN master keeps sending out messages (we probed and saw the waveform on Oscilloscope), but the slave nodes cannot receive or respond.  We also probed CAN-H and CAN-L pins of the slave and saw the exact waveform, but the slaves take no actions.  In the meantime, it seems to us that the sending function had issue with interruption (it could not get out the critical session).  My co-worker has also posted the question here Problem with CAN BUS communication (MK20DN512VLL10) .  Any helps will be greatly appreciate. 

0 Kudos