Difficulty with TRK-KEA 128 CAN Communication

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

Difficulty with TRK-KEA 128 CAN Communication

Jump to solution
1,861 Views
tylertrigg
Contributor II

I am a novice with microcontrollers so I assume this is a fairly simple issue. I want to be able to send messages back and forth between two TRK-KEA128 microcontrollers. I'm using the msCAN driver and the example project has a receive_DataFrame function and a send_DataFrame function. So I have one set to simply send a frame and the other set to receive the frame and then turn on a light signifying it was received. However, the receiver gets stuck in a loop where it looks for a flag that buffer_status[0] == NEWDATA, which never triggers.

I don't know if there is something extra I must put in the code to send data over or if I simply made a mistake in the way the microcontrollers were wired to each other. In addition, both MCUs use a different computer to receive power. Can anyone give me some guidance of where I might have gone wrong?

0 Kudos
1 Solution
1,140 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Tyler,

That code is used to output Bus clock on PTH2. I just want to ensure the frequency of Bus clock is correctly configured by Clk_Init function.
I am not sure if you have test the "Demo_ReceiveTransmit" case.
You can refer the images attached to achieve communicate with each other MCUs.

Please download "ReceiveTransmit" project to one board first.

ReceiveTransmit.png

Then download "Transmit then ReceiveTransmit" project to another board.

Transmit then ReceiveTransmit.png
I also attached these two project here, so you can test them directly.

If you have CAN bus tool, you may see the CAN data like below.

CAN bus tool.png

Best Regards,

Robin

View solution in original post

0 Kudos
8 Replies
1,140 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Tyler,

I test the MSCAN_KEA128 project on my Rev D TRK-KEA128 boards.
The "Demo_Receive_DataFrame" code can run into MSCAN_Rx_IRQHandler.

Demo_Receive_DataFrame.png


There is some difference between these two version. REV D uses PTG0 pin to control the STB of MC33901, while REV B ties it directly to GND, so you have to set PTG0 as GPIO output function and set it to low, so that it makes MC33901 in normal mode.

Rev D.png

Best Regards,

Robin

0 Kudos
1,140 Views
tylertrigg
Contributor II

Robin,

Thank you for your reply. Both of my devices are revision D as well, and I had seen on another thread, although I'm having trouble finding that thread again unfortunately, that your recommendation had to be done and that it was implemented by adding 

GPIOB_PDDR |= (1<<16);
GPIOB_PCOR = (1<<16);

to the code before trying to run the send and receive functions. However, I got more or less the same issue where it did not ever update the buffer_status. Is there something else I need to do to implement your suggestion?

Thank you,

Tyler

0 Kudos
1,140 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Tyler,

You just need to connect CANH(Pin1 of J15) and CANL(Pin2 of J15).

CANH CANL TRK-KEA128.jpg

When debugging with CodeWarrior10.7 on the Receive board, I add a breakpoint waiting for the NEWDATA.
After power on the Transmit board by another computer, the Receive board will stop at that breakpoint.

Demo_Receive_DataFrame.png

The project can be download from MSCAN driver for Kinetis EA devices.

I also attached the project here.

Best Regards,

Robin

1,140 Views
tylertrigg
Contributor II

Robin,

Thank you again for your reply. I tried the code you used, and it did successfully communicate, so I thank you greatly. I noticed a piece of code

SIM_SOPT0 |= SIM_SOPT0_CLKOE_MASK;

which was the only difference between what I had written and what you had sent. May I ask what that piece of code does? In addition, after getting a successful communication, I tried switching the send and receive node so that they did the opposite job, but the transmission would not succeed going the other direction. Do you have an idea as to what would keep that communication from succeeding? I changed nothing else about the code other than switching the "transmit" from the transmit node to "receive" and vice versa.

Thank you again,

Tyler

0 Kudos
1,141 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Tyler,

That code is used to output Bus clock on PTH2. I just want to ensure the frequency of Bus clock is correctly configured by Clk_Init function.
I am not sure if you have test the "Demo_ReceiveTransmit" case.
You can refer the images attached to achieve communicate with each other MCUs.

Please download "ReceiveTransmit" project to one board first.

ReceiveTransmit.png

Then download "Transmit then ReceiveTransmit" project to another board.

Transmit then ReceiveTransmit.png
I also attached these two project here, so you can test them directly.

If you have CAN bus tool, you may see the CAN data like below.

CAN bus tool.png

Best Regards,

Robin

0 Kudos
1,140 Views
tylertrigg
Contributor II

Thank you Robin,

That solution worked! Originally, I had tried changing my main body code to the same thing as yours rather than importing the entire project because I already had a project with the same name and didn't want to delete the entire thing. But when ReceiveTransmit wouldn't work, I decided to start from scratch and import your project and it worked perfectly fine, which makes me think I may have had a problem somewhere in my project settings. Regardless, thank you very much for your help!

Tyler

0 Kudos
1,140 Views
tylertrigg
Contributor II

Upon further inspection, I still am having some sort of trouble. Let me tell you a bit about my setup. I have a laptop that is running Transmit then ReceiveTransmit and a desktop that is running ReceiveTransmit. Just like when I was using the regular transmit and receive data frame functions beforehand, I can transmit from my laptop and receive from my desktop just fine. However, when I try to transmit from my desktop, the laptop cannot pick it up. 

The laptop can pick up the signal if the desktop uses the ReceiveTransmit function to send it, but not when it uses transmit. Do you think that may be caused by differences in power they may be receiving? Or do you have any other suggestions? It doesn't appear the code is at fault, and I've checked both the wires and the MCU's and have switched them, so it doesn't appear to be a problem with the devices. It's just that either whatever is plugged into my desktop cannot transmit or my laptop cannot receive it without using the ReceiveTransmit function.

Tyler

0 Kudos
1,140 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Tyler,

I think this was caused by frame ID.
The the msCAN channel buffer ID of receiver should be configured equal to the ID of transmitter.

Otherwise the receiver will can't pick up the signal.

frame ID.png

Best Regards,

Robin

0 Kudos