Please Help To Get CAN Work With 2 TRK-KEA128 Boards Connected Together With CAN BUS

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

Please Help To Get CAN Work With 2 TRK-KEA128 Boards Connected Together With CAN BUS

1,464 Views
chaodong
Contributor I

We have been stuck with KEA CAN issue for some time.

 

We did a successful test with KDS2.0 on TRK-KEA128 board (Rev D) in loopback mode, but when re-configure the MSCAN to work in normal mode (not in loopback) and configure PTG0  (CAN_STB) as Output with initial value of 0 to enable the CAN tranceiver on the board, it does not work when we connect it to an existing working CAN bus (125K baud, CAN2.0B) with 7 working CAN devices, we simply don't get any Rx interrupts or even Tx interrupts when calling SendFrame(). The other CAN devices on the same CAN bus work fine.

 

Then we did another test using 2 TRK-KEA128 boards that are connected together by the CAN bus (CAN_Rx <-> CAN_Rx, CAN_Tx <-> CAN_Tx). The CAN on each board is configured the same by using PE's default settings (not working in loopback mode), and additional settings as follow:

 

1. Configured PTG0 (CAN_STB) as Output with initial value of 0 to enable the CAN tranceiver on the both boards

2. Enabled interrupt services

3. PTC6/PTC7 as CAN_RX/CAN_TX

4.Global Acceptance Mask un-ticked

5. Bit rate = 125kbit/s

6 Did routing in PinSettings for PTC6/PTC7/PTG0

7. One board calls SendFrame() in a timed loop in the main()

 

int main(void)

{

PE_low_level_init();

GPIOB_PDDR |= (1<<16);

GPIOB_PCOR = (1<<16);

PTG0_Out_Ptr = PTG0_Out_Init(0);

PTG0_Out_ClrVal(PTG0_Out_Ptr);

MyCANPtr = CAN1_Init(NULL);

SendTest();

}

 

8. The other board calls ReceiveFrame()

 

int main(void)

{

PE_low_level_init();

GPIOB_PDDR |= (1<<16);

GPIOB_PCOR = (1<<16);

PTG0_Out_Ptr = PTG0_Out_Init(0);

PTG0_Out_ClrVal(PTG0_Out_Ptr);

MyCANPtr = CAN1_Init(NULL);

RecvTest();

}

 

The implementation of above-used functions and necessary declarations before the main() function are listed below:

 

volatile bool DataFrameTxFlg;
volatile bool DataFrameRxFlg = FALSE;
LDD_TDeviceData *MyCANPtr;
LDD_TError Error;
LDD_CAN_TFrame Frame;
uint8_t OutData[8] = {0x00U, 0x01U, 0x02U, 0x03U};           //,0X04U,0X05U,0X06U,0X07U     /* Initialization of output data buffer */
uint8_t InpData[8];
LDD_TDeviceData* PTG0_Out_Ptr;

void Delay();
void RecvTest();
void SendTest();

 

void Delay()

{

int sum = 0;

while (sum < 0xFFF)

{

  sum++;

}

}

void SendTest()

{

  for(;;)

  {

    Frame.MessageID = 0x123U;                                            /* Set Tx ID value - standard */

    Frame.FrameType = LDD_CAN_DATA_FRAME;              /* Specyfying type of Tx frame - Data frame */

    Frame.Length = sizeof(OutData);                                      /* Set number of bytes in data frame - 4B */

    Frame.Data = OutData;                                                     /* Set pointer to OutData buffer */

    DataFrameTxFlg = FALSE;                                               /* Initialization of DataFrameTxFlg */

    Error = CAN1_SendFrame(MyCANPtr, 1U, &Frame);     /* Sends the data frame over buffer 0 */

    while (!DataFrameTxFlg) {                                                /* Wait until data frame is transmitted */

    }

Delay();

  }

}

void RecvTest()

{

  for(;;)

  {

  DataFrameRxFlg = FALSE;

     while (!DataFrameRxFlg) {                                       /* Wait until data frame is received */

     }

     Frame.Data = InpData;                                           /* Set pointer to InpData buffer */

     Error = CAN1_ReadFrame(MyCANPtr, 0U, &Frame);

  }

}

 

DataFrameTxFlg and DataFrameRxFlg are set to TRUE in ISRs when a frame is sent out or received successfully.

 

In this test, the 2 boards are connected to the same PC, we still can't get any receive interrupts, however we accidentally got Tx interrupts when the board with SendTest() running in KDS debugger, but this is not repeatable. In most cases, we run the board with RecvTest() running in KDS debugger while leave the other board in free running mode, but we never see any RX interrupts.

 

We are not sure where we did wrong? we also tried not to configure the PTG0 pin or configured it to output value 1, but no progress was made.

 

So, please help!

 

Attached is the complete project.

 

Thanks in advance.

 

Chao

Original Attachment has been moved to: CanTest.rar

Labels (1)
0 Kudos
8 Replies

932 Views
kuanyuenliao
Contributor II

I had the same question and solved it already.

Since the R66 is designed in the schemetic but not mounted on the board, the CAN transceiver will always keep in standby mode.

so....short R66 will solve this question.

Reference from the PC33901 datasheet "When STB is high or floating, the device is in Standby mode. When STB is low, the device is set in Normal mode."

0 Kudos

932 Views
chaodong
Contributor I

We are still struggling with this problem.

The new progress is that we used a USBCAN analyzer to connect with one TRK-KEA128 board, and we surprisedly found that the baud rates of the CAN signals from this board are 140.35kbps, 141.18kbps, 142.011kbps, 142.86kbps, 145.45kbps with 124.83kbps configured in KDS2.0 (125kbps is the target). We guess that this is caused by the internal clock, then we moved to use the external clock on the board. However, we encountered another problem: the KDS cannot complete the PE initialisation by entering into a deadlock because there are no clock signals on the EXTAL and XTAL pins (this is confirmed). The following is the code fragment generated by the PE:

        if ((TargetMode & CPU_CLOCK_EXTERNAL_CRYSTAL_MASK) != 0) {

          while((OSC_CR & OSC_CR_OSCINIT_MASK) == 0x00U) { /* Check that the oscillator is running */

          }

Please refer to the attachment for details.

CodeFragment.JPG

The attachments also contain the external clock configuration.

ClockConfig.JPGClockSourceSettings.JPGClockSourceSettings-2.JPGClockSourceSettings-3.JPGInternalOscillator.JPGSystemOscilator.JPG

0 Kudos

932 Views
chaodong
Contributor I

debugger_display.JPG

0 Kudos

932 Views
frankfu
NXP Employee
NXP Employee

Quote: "Then we did another test using 2 TRK-KEA128 boards that are connected together by the CAN bus (CAN_Rx <-> CAN_Rx, CAN_Tx <-> CAN_Tx). "

When you connect two MCUs' CAN interfaces directly (without transceiver), you should connect (CAN_Rx <-> CAN_Tx, CAN_Tx <-> CAN_Rx). Please try it at first.

0 Kudos

932 Views
chaodong
Contributor I

we did this test but no difference produced.

0 Kudos

932 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Chao Dong,

Maybe there is some configuration issue in the RX side, please kindly refer to the KEA128 demo in the attachment, it is a receive-send demo, which means this demo waiting for frames from another node and echo it back, so it is usually used with a CAN analyzer that can set a testing frame to it.

BTW, it is a CW project, but as it is a bare metal project, no problem to review the code in the "Sources" folder.

Hope that helps, !

0 Kudos

932 Views
chaodong
Contributor I

Thanks a lot. The code is for CW platform, I tried to use it in KDS but failed. Whta we really need is the to make it work in KDS and PE.

0 Kudos

932 Views
chaodong
Contributor I

Anyone has the same problem?

0 Kudos