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.

tms470 dcan receiver problem

Other Parts Discussed in Thread: HALCOGEN

sir,

i am using the TMS470MF066HDK . i try to do the simple transmission and reception.

i configure the message object 1 for tx (DCAN1) , and message object 2 for rx. (DCAN1).

i can transmit the data from the controller . but i can't  receive any data. 

is any can explain me sir, what changes i want to do.

thanks 

arun

  • CAN requires at least two nodes on the network so that at least one receiver acknowledges the message. I suggest you try the CAN example that is in HALCoGen (Help->Help Topics->Examples). This example sends a message out CAN1 and receives that message on CAN2. Remember to connect the two CANs together (J1-H to J2-H and J1-L to J2-L) with two wires.
  • sir,
    i tried that one. the data is transmitted from DCAN1 to DCAN2.
    but i want to communicate with in one DCAN.
    from DCAN1 , message object 1 for tx, and message object 2 for rx.
    how can i transmit and receice the data.

    thanks
    arun
  • I am not sure you can do that. Not sure why you would want to do that. The CAN state-machine is checking every bit that is transmitted to detect any transmission problem. The DCAN module cannot acknowledge its own message so as a minimum you would need another node on the network to do the acknowledge bit.
  • hi sir,

    sorry for the delay to relpy to you..

    sir , actually perviously i was used that TM4C123 microcontroller , in TM4C123GXL launchpad.

    in that also i have the two CAN . but i was using the only one CAN from that ( CAN0) ( message object 1 ( TX) , and message object 2 (RX )).

    like that here also i want to use the only one CAN ( DCAN ) . for transmit and receive . that is my requirement also.

    in one end i am connect this TMS470MF066HDK for tranmit and receice (DCAN) (message object 1 ( TX ), and message object 2 ( RX ) ) , in another end i am connect to the SAINT TOOL for check the proper transmit and receive .

    is it possible to do like this sir.. ?????

    thanks
    arun
  • Arun,

    Do you want to do something different than what is pictured above where within the same CAN module one mailbox is configured to transmit and the other to receive?

  • I setup a test on the TMS470MF066HDK. I have the two DCANs connected to form a network. I configured DCAN1 message 1 as TX and DCAN1 message 2 as receive and DCAN2 message 1 as receive, all using the same ID. Transmitting on DCAN1 I see the receive message on DCAN2. I do not see it on DCAN1. Then if enable the external loopback test mode on DCAN1, I receive the message on DCAN1 and on DCAN2. In the DCAN module you cannot receive the message you are transmitting unless you have a loopback mode enabled. I have attached the .zip of the project I used.

    5241.HydraCAN.zip

  • hi ,

    what ever the picture you send to me , i did the same thing.

    in one end i have our TMS470MF066HDK kit , in an another end i have the SAINT BUS ENGINE 2 ( for check the can transmit and receive ).

    here , what ever the code i did in my side i put it in down side .

    here the data transmited successfully , but if i send any data from theSAINT BUS ENGINE 2 ( for check the can transmit and receive ) , the data is not received in the received buffer .

    is any other changes i want to do in the coding sir ...?????


    prog :

    #include "system.h"
    #include "esm.h"
    #include "can.h"
    uint8 tx_buffer[8]={'a','r','u','n','k','i','n','g'};
    uint8 rx_buffer[8]={0};

    uint32 checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize);

    void main(void)
    {
    canInit();
    canTransmit(canREG1, canMESSAGE_BOX1, tx_buffer);
    while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2));
    canGetData(canREG1, canMESSAGE_BOX2, rx_buffer);
    }

    thanks
    arun
  • You did not enable external loopback.

    void main(void)
    {
    /* USER CODE BEGIN (2) */
    
        /* initialize can 1 and 2   */
        canInit(); /* can1 -> can2 */
    
        /* special loop back enable */
        canREG1->CTL |= 0x80; // Enable test mode
        canREG1->TEST |= 0x100; // Enable external loop back
    
        /* transmit on can1 */
        canTransmit(canREG1, canMESSAGE_BOX1, tx_data);
    
        /*... wait until message receive on can1 */
        while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2));
        canGetData(canREG1, canMESSAGE_BOX2, rx_data1);  /* receive on can1  */
    
        /* check received data patterns */
        error1 = checkPackets(&tx_data[0],&rx_data1[0],D_SIZE);
    
        /*... wait until message receive on can2 */
        while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
        canGetData(canREG2, canMESSAGE_BOX1, rx_data2);  /* receive on can2  */
    
        /* check received data patterns */
        error2 = checkPackets(&tx_data[0],&rx_data2[0],D_SIZE);
    
        /* ... run forever */
        while(1);
    
    /* USER CODE END */
    
    }
    

    You cannot receive what you transmit unless you are in a loopback test mode.

  • hi sir,

    i am using the same code what ever u give it to me. but i can not receive the data in the rx_data1.

    the data is received to the rx_data2. but i cannot receive in the rx_data1.

    i want to do any other changes in the code.

    i make DCAN1 message object 1 for Tx, DCAN1 message object 2 for Rx ,DCNA2 message object 1 for Rx.

    i dont know what misstake i did it sir..?????

    thanks
    arun
  • sir,

    with Only using DCAN1 , I want to transmit and receive the data sir.

    i make the network to DCAN1, to the saint bus engine tool. ( for monitering the data, transmit and receive ) .

    for normal canTransmit() ,function i can transmit the data to that saint tool . if i am sending any data from the saint tool , i can not receive the data in that rx_buffer.

    thanks
    arun
  • Do you have a mailbox configured as transmit using the same message ID as the message that you are trying to receive from the saint bus engine? When the DCAN module receives a message, it checks the mailboxes for a match to the ID. It looks like if it sees a transmit mail box matching the ID, it does not store the message even if there is a receive mailbox with the same ID.
  • hi sir ,

    no sir, actually my receive mailbox number is 2. from the saint tool i am transmit the data with the ID: 2 .
    but the data is not received in my receive mailbox .
    i dont know what is the problem..???
    if i send any data from the saint tool means , i want to use the interrupt handler in my code , for receiving that data ???

    thanks
    arun
  • Are you using standard (11-bit) or extended (29-bit) IDs? Make sure the saint tool is using the same type of ID.

  • hi sir,

    i am not change any id value given in the HALCOGEN.
    from DCAN1 ( ID = 1 (transmit) & ID = 2 (receive)). i am not using any DCAN2 message objects.

    from saint tool i am give the data to transmit ID :00 02.

    sir , defaultly the HALCOGEN generate the code for message object configuration. ( in CanInit function ).

    is there i want to do any other changes in the Caninit( ), function ????

    i attached that generated code in down side.

    i thought when the data is come from the saint tool means we must use the INTERRUPT HANDLER. is it corrcet sir ????

    code :


    void canInit(void)
    {
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    /** @b Initialize @b DCAN1: */

    /** - Setup control register
    * - Disable automatic wakeup on bus activity
    * - Local power down mode disabled
    * - Disable DMA request lines
    * - Enable global Interrupt Line 0 and 1
    * - Disable debug mode
    * - Release from software reset
    * - Disable parity and ECC
    * - Enable/Disable auto bus on timer
    * - Setup message completion before entering debug state
    * - Setup normal operation mode
    * - Request write access to the configuration registers
    * - Setup automatic retransmission of messages
    * - Disable error interrupts
    * - Disable status interrupts
    * - Enter initialization mode
    */
    canREG1->CTL = 0x00000000U
    | 0x00000000U
    | 0x00021443U;

    /** - Clear all pending error flags and reset current status */
    canREG1->ES = canREG1->ES;
    //canREG1->ES = ox0000031FU;

    /** - Assign interrupt level for messages */
    canREG1->INTMUXx[0U] = 0x00000001U
    | 0x00000002U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U;

    canREG1->INTMUXx[1U] = 0x00000000U;

    /** - Setup auto bus on timer period */
    canREG1->ABOTR = 0U;

    /** - Initialize message 1
    * - Wait until IF1 is ready for use
    * - Set message mask
    * - Set message control word
    * - Set message arbitration
    * - Set IF1 control byte
    * - Set IF1 message number
    */
    while ((canREG1->IF1STAT & 0x80U) ==0x80U)
    {
    } /* Wait */


    canREG1->IF1MSK = 0xC0000000U | ((0x000007FFU & 0x1FFFFFFFU) << 0U);
    canREG1->IF1ARB = 0x80000000U | 0x40000000U | 0x20000000U | ((1U & 0x1FFFFFFFU) << 0U);
    canREG1->IF1MCTL = 0x00001080U | 0x00000800U | 8U;
    canREG1->IF1CMD = 0xF8;
    canREG1->IF1NO = 1;

    /** - Initialize message 2
    * - Wait until IF2 is ready for use
    * - Set message mask
    * - Set message control word
    * - Set message arbitration
    * - Set IF2 control byte
    * - Set IF2 message number
    */
    while ((canREG1->IF2STAT & 0x80U) ==0x80U)
    {
    } /* Wait */

    canREG1->IF2MSK = 0xC0000000U | ((0x000007FFU & 0x1FFFFFFFU) << 0U);
    canREG1->IF2ARB = 0x80000000U | 0x40000000U | 0x00000000U | ((2U & 0x1FFFFFFFU) << 0U);
    canREG1->IF2MCTL = 0x00001080U | 0x00000400U | 8U;
    canREG1->IF2CMD = 0xF8;
    canREG1->IF2NO = 2;


    /** - Setup IF1 for data transmission
    * - Wait until IF1 is ready for use
    * - Set IF1 control byte
    */
    while ((canREG1->IF1STAT & 0x80U) ==0x80U)
    {
    } /* Wait */
    canREG1->IF1CMD = 0x87;

    /** - Setup IF2 for reading data
    * - Wait until IF1 is ready for use
    * - Set IF1 control byte
    */
    while ((canREG1->IF2STAT & 0x80U) ==0x80U)
    {
    } /* Wait */
    canREG1->IF2CMD = 0x17;

    /** - Setup bit timing
    * - Setup baud rate prescaler extension
    * - Setup TSeg2
    * - Setup TSeg1
    * - Setup sample jump width
    * - Setup baud rate prescaler
    */
    canREG1->BTR = (0U << 16U) |
    ((2U - 1U) << 12U) |
    (((3U + 2U) - 1U) << 8U) |
    ((2U - 1U) << 6U) |
    19U;

    /** - Setup TX pin to functional output */
    canREG1->TIOC = 0x0000004CU;

    /** - Setup RX pin to functional input */
    canREG1->RIOC = 0x00000048U;

    /** - Leave configuration and initialization mode */
    canREG1->CTL &= ~0x00000041U;

    /** @b Initialize @b DCAN2: */

    /** - Setup control register
    * - Disable automatic wakeup on bus activity
    * - Local power down mode disabled
    * - Disable DMA request lines
    * - Enable global Interrupt Line 0 and 1
    * - Disable debug mode
    * - Release from software reset
    * - Disable parity and ECC
    * - Enable/Disable auto bus on timer
    * - Setup message completion before entering debug state
    * - Setup normal operation mode
    * - Request write access to the configuration registers
    * - Setup automatic retransmission of messages
    * - Disable error interrupts
    * - Disable status interrupts
    * - Enter initialization mode
    */
    canREG2->CTL = 0x00000000U
    | 0x00000000U
    | 0x00021443U;

    /** - Clear all pending error flags and reset current status */
    canREG2->ES = canREG2->ES;

    /** - Assign interrupt level for messages */
    canREG2->INTMUXx[0U] = 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U
    | 0x00000000U;

    canREG2->INTMUXx[1U] = 0x00000000U;


    /** - Setup auto bus on timer period */
    canREG2->ABOTR = 0U;


    /** - Setup IF1 for data transmission
    * - Wait until IF1 is ready for use
    * - Set IF1 control byte
    */
    while ((canREG2->IF1STAT & 0x80U) ==0x80U)
    {
    } /* Wait */
    canREG2->IF1CMD = 0x87;

    /** - Setup IF2 for reading data
    * - Wait until IF1 is ready for use
    * - Set IF1 control byte
    */
    while ((canREG2->IF2STAT & 0x80U) ==0x80U)
    {
    } /* Wait */
    canREG2->IF2CMD = 0x17;

    /** - Setup bit timing
    * - Setup baud rate prescaler extension
    * - Setup TSeg2
    * - Setup TSeg1
    * - Setup sample jump width
    * - Setup baud rate prescaler
    */
    canREG2->BTR = (0U << 16U) |
    ((2U - 1U) << 12U) |
    (((3U + 2U) - 1U) << 8U) |
    ((2U - 1U) << 6U) |
    19U;

    /** - Setup TX pin to functional output */
    canREG2->TIOC = 0x0000004CU;

    /** - Setup RX pin to functional input */
    canREG2->RIOC = 0x00000048U;

    /** - Leave configuration and initialization mode */
    canREG2->CTL &= ~0x00000041U;

    /** @note This function has to be called before the driver can be used.\n
    * This function has to be executed in privileged mode.\n
    */

    /* USER CODE BEGIN (5) */
    /* USER CODE END */
    }

    thanks
    arun
  • From the code above you are using extended identifies (29-bit). That is OK, but it is not the default. You can verify this by looking at the HALCoGen check box highlighted below:

    Please verify that the saint tool is also using extended identifiers. If not, that the ID field will be left shifted into bits ID[28:18] of the receive buffer and will not match the ID bits in your receive mailbox. Also note that you are using a 29-bit ID but your mask is only 11-bits (0x7FF).

    You don't need to use the interrupt handler, you can poll for the receive message.

  • hi sir,

    i checked that masking and the id from the saint tool.
    now i can transmit and receive the data from the saint tool to my board.

    but, i have one problem now. in my code i am enabling the interrupt handler.
    now i am put my code in a while(1) loop.

    qus 1 : my code is getting blocked because of the canIsRxMessageArrived() , function. when ever i receive any data from saint tool , then only my code go to the next step. until it will block in the canIsRxMessageArrived() function . but i want to send and receive the data with out any blocking .

    qus 2 : now i am enable the ( EIE & SIE ) bit in the CONTROL REGISTER . first time data transmission is ok. but from the second time the ERROR STATUS REGISTER , and INTERRUPT REGISTERS are raised . i dont know how to clear those errors. (i dont know how to clear this errors in Can Error notification function)

    can u please tell me the sollution for this prob sir..

    i am attaching my main prog here.

    prog :

    void main(void)
    {
    canInit();
    while(1)
    {


    canTransmit(canREG1, canMESSAGE_BOX1, tx_data);

    receive = canIsRxMessageArrived(canREG1, canMESSAGE_BOX2); // for check
    if(receive != 0) // for check
    {
    while(!canIsRxMessageArrived(canREG1, canMESSAGE_BOX2));
    }

    if(recv_flag == 1) // this flag is raised in the Canmessagenotification ().
    {
    canGetData(canREG1, canMESSAGE_BOX2, rx_data);
    recv_flag=0;

    }
    }

    thanks
    arun