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 problems

Other Parts Discussed in Thread: HALCOGEN

Hello,

What am I doing wrong?

I'm trying to get the CAN-bus up running on a Hercules development board.

Until now I have copied the example from HalCodGen on CAN-bus with interrupt.

I am adding this to a small program where I am already have interrupt up running from RTI and ADC.

But I cannot get the CAN-bus running. It seems like the command is never sent from CAN1. When I try to send the command a second time, it returns from the can.c in the middle of the transmit function (Pending command return). The first time, it goes all the way through the transmit function.

As far as I can see, I never get an interrupt that the command is received on CAN2. (Yes, they are connected with wires :-) )
The interrupt in VIM is set as shown in the HalCodGen example.

Question: There is a function in can.c to enable errorNotification, but I cannot find a function to enable the commandNotification. As far as I can see from the code in can.c, that bit (bit 3) is never touched in can.c. Is that function covered in some other way elsewhere or how is it handled?. I have tried to enable that bit after enabling errorNotification, but without any success.

Looking forward to a good hint :-)

Best regards
   Michael c".)

 

  • Hi Michael,

    1. Hocogen doesn't generate errorNotification and messageNotification. You have to provide those function for your application. 

    2. Do you mean bit 3 (EIE) of Ctrl register? As default, the EIE is disabled. If you want to use errorNotification, please call canEnableErrorNotification() which is included in can.c

    3. For INT, please make sure:

                  a. CAN Driver is enabled in  Driver Enable

                  b. CAN interrupt ISR is mapped correct in VIM RAM

                  c.  Enabled CAN high or low INT in VIM channel 0-31 and 31-62 

                  d.  Enable CAN INT in CAN Msg1~8 or others       (make sure your selection is set in CAN.C canREG1 (or 2) ->INTMUXx[0U] )

    Example for call halcogen functions for transmit and receive:

    	unsigned int  i;
    unsigned int Test_Status; // 0 --> Pass, 1 - Fail
    unsigned char tx_data[8] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88};
    unsigned char rx_data[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; /*1st 4 bytes will be ID*/

    canInit();

    canTransmit(canREG1, canMESSAGE_BOX1, tx_data);
    while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
    canGetData(canREG2, canMESSAGE_BOX1, rx_data);

    Test_Status = 0;

    for(i=0;i<8;i++)
    {
    if(tx_data[i] != rx_data[i+4])
    {
    //Test Failed
    Test_Status = 1;
    }
    }


    Regards,

    QJ

  • Hi QJ,

    Thank You for your detailed reply.

    I went through each point in your reply, and to my supprise found that the enabling of the interrupt for the transmit-message was missing in HalCoGen "code" :-(

    It is enabled now, and I have "Hello World" transmitted and received on my CAN-Bus :-)

    Best Regards

       Michael c".)

     

  • Hello,

    I seem to be having the same problem where the transmit function seem to be exiting at this part:

    /** - Check for pending message:
    * - pending message, return 0
    * - no pending message, start new transmission
    */
    if (node->TXRQx[regIndex] & bitIndex)
    {
    return success;
    }
    
    
    I went through the previous solution post. If I am trying to transmit on/through Message 1 (Id:1), am I correct in having changed the following in the canInit() function:
    
    
    /** - Assign interrupt level for messages */
    canREG2->INTMUXx[0U] = 0x00000001U;

    Also I didn't change anything here in the canInit() function as it seemed to correspond to a transmit configuration:

    /** - 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 (canREG2->IF1STAT & 0x80);
    canREG2->IF1MSK = 0xC0000000U | ((0x000007FFU & 0x1FFFFFFFU) << 0U);
    canREG2->IF1ARB = 0x80000000U | 0x40000000U | 0x20000000U | ((1U & 0x1FFFFFFFU) << 0U);
    canREG2->IF1MCTL = 0x00001080U | 0x00000C00U | 8U;
    canREG2->IF1CMD = 0xF8;
    canREG2->IF1NO = 1;


     The strangest part of all this, is that I am able to transmit data out of CAN1 using Message 1(Id:1) but not CAN2. I deactivated Message 1 for CAN1 in HALCoGen as a precaution with no change in symptoms.
    
    
    Any suggestions?
    
    
    Regards,
    
    
    Griswald Brooks
  • Hi QJ,

    i did the setting regarding INT but it seems that the "canREG1 (or 2) ->INTMUXx[0U]" is not set. I have the following generated code:

    canREG1->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;

    In HALCoGen i did the following setting:

    1) VIM Channel 0-31 -->  i enabled the VIM channel 16 (CAN1 High), 29 (CAN1 Low) and 44 (CAN1 IF3)

    2) DCAN1 Msg1-8 --> i enabled the message 1 in TX mode and anabled the VIM interrupt (see image below)

    3) VIM RAM --> the setting is like in the below figure

    is it right my configuration? can you provide me a HALCoGen file with rights settings so i can try to implement a simple project with some CAN messages TX and RX?

    Many thanks in advance


    Ciro

  • Hello Ciro,

    In your 1st diagram, you checked DCAN0INT line (High Priority). In INTMUXx[0U], bit 1 represents  message object number 1, and value 0 means DCAN0INT line is activated.

    Your INTMUXx[0u] setting is correct.

    Regards,

    QJ