AnsweredAssumed Answered

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

Question asked by Chao Dong on Nov 21, 2015

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

Outcomes