This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CAN bus not receive the data

Other Parts Discussed in Thread: HALCOGEN

I use another TMS570LC43x launchpad with transceivers connected.

DCAN 3 as transmitter to transmit data and DCAN 4 as receiver to receive data, but receiver doesn't get the data.

DCAN 3 transmits data to the registers DCAN IF1DATA and DCAN IF1DATB. How to make sure that data are go to pin Tx?

For Receiver only check register NWDATx? The code hang on 

 while(!canIsRxMessageArrived(canREG4, canMESSAGE_BOX1)); 

Have neve get change in register NWDATx.

Two of below are connected via P1 connectors. the up one is CAN4 as receiver, down one is CAN3 as transimitter.

The codes: 

uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data)

{

      node->IF1DATx[i] = *data;

}

DCAN 4 receives data from 

uint32 canIsRxMessageArrived(canBASE_t *node, uint32 messageBox)

{

     flag = node->NWDATx[regIndex] & bitIndex;

}

flag has never be set, so codes are loop here infinitely in while loop in main().

uint32 canGetData(canBASE_t *node, uint32 messageBox, uint8 * const data)

{

     *pData = node->IF2DATx[s_canByteOrder[i]];

}

int main(void)
{
      /* USER CODE BEGIN (3) */
      canInit(canREG3); // Initialize the CAN Module Channel3
      canInit(canREG4); // Initialize the CAN Module Channel4

      canTransmit(canREG3, canMESSAGE_BOX1, tx_data); // Transmit data through Msg Box1 of CAN3

      while(!canIsRxMessageArrived(canREG4, canMESSAGE_BOX1)); // Wait till a message is received on CAN4, Msg Box1
      canGetData(canREG4, canMESSAGE_BOX1, rx_data); // Store the received data in rx_data

       error = checkPackets(&tx_data[0], &rx_data[0], D_SIZE); // Check if the message received is same as expected


        while(1); // Infinite Loop
/* USER CODE END */
}

Thanks,

  • Hi, our expert is out of office until 4/7. Please expect a delayed response.
    Also, please see this FAQ: software-dl.ti.com/.../index.html

  • Hi,

    You can use HALCOGen to generate a project for CAN3 and CAN4 communication:

    1. Enable CAN3 and CAN4:

    2. Configure CAN Baudrate:

    3. Configure CAN MessageBox:

    • Configure CAN3 , MessageBox 1 – Activate and Enable TX
    • Configure CAN4 , MessageBox 1 – Activate and Enable RX

    4. Copy the source code below into your HL_sys_main.c:

    /* Include Files */

    #include "HL_sys_common.h"
    #include "HL_system.h"

    /* USER CODE BEGIN (1) */
    #include "HL_can.h"

    /* Include ESM header file - types, definitions and function declarations for system driver */
    #include "HL_esm.h"

    #define D_SIZE 9

    uint8 tx_data[D_SIZE] = {'H','E','R','C','U','L','E','S','\0'};
    uint8 rx_data[D_SIZE] = {0};
    uint32 error = 0;

    uint32 checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize);
    /* USER CODE END */


    /** @fn void main(void)
    * @brief Application main function
    *
    */

    /* USER CODE BEGIN (2) */
    /* USER CODE END */


    void main(void)
    {
    /* USER CODE BEGIN (3) */

    /* initialize can 1 and 2 */
    canInit(); /* can3 -> can4 */

    /* transmit on can1 */
    canTransmit(canREG3, canMESSAGE_BOX1, tx_data);

    /*... wait until message receive on can4 */
    while(!canIsRxMessageArrived(canREG4, canMESSAGE_BOX1));
    canGetData(canREG4, canMESSAGE_BOX1, rx_data); /* receive on can4 */

    /* check received data patterns */
    error = checkPackets(&tx_data[0],&rx_data[0],D_SIZE);

    /* ... run forever */
    while(1);

    /* USER CODE END */
    }

    /* USER CODE BEGIN (4) */
    /** @fn checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize)
    * @brief check two buffers and report error
    *
    */
    uint32 checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize)
    {
    uint32 err=0;
    uint32 cnt=psize;

    while(cnt--)
    {
    if((*src_packet++) != (*dst_packet++))
    {
    err++; /* data error */
    }
    }
    return (err);
    }
    /* USER CODE END */

  • Thanks, this  has resolved the issues.