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.

TMS320F2812 CANES

Hello

I want to build a stable CAN communication software between 2 CAN Modules, that is why i have build this Err Reset Function:

 

bool ResetErr()
{   
    if (ECanaRegs.CANES.all <= 2) return(true);
    else
        {   
            if (ECanaRegs.CANES.bit.FE == 1) ECanaRegs.CANES.bit.FE = 0x0001;
            if (ECanaRegs.CANES.bit.BE == 1) ECanaRegs.CANES.bit.BE = 0x0001;
            if (ECanaRegs.CANES.bit.SA1 == 0) ECanaRegs.CANES.bit.SA1 = 0x0001;
            if (ECanaRegs.CANES.bit.CRCE == 1) ECanaRegs.CANES.bit.CRCE = 0x0001;
            if (ECanaRegs.CANES.bit.SE == 1) ECanaRegs.CANES.bit.SE = 0x0001;
            if (ECanaRegs.CANES.bit.ACKE == 1) ECanaRegs.CANES.bit.ACKE = 0x0001;
            if (ECanaRegs.CANES.bit.PDA == 1) ECanaRegs.CANES.bit.PDA = 0x0001;
            if (ECanaRegs.CANES.bit.BO == 1)
                                        {   
                                            //ECanaRegs.CANMC.bit.CCR = 1;
                                            //while(ECanaRegs.CANES.bit.CCE == 0) {};
                                            ECanaRegs.CANES.bit.BO = 0x0001;
                                        }
            if (ECanaRegs.CANES.bit.EP == 1) ECanaRegs.CANES.bit.EP = 0x0001;
            if (ECanaRegs.CANES.bit.EW == 1) ECanaRegs.CANES.bit.EW = 0x0001;
            if (ECanaRegs.CANES.bit.SMA == 1)
                                        {
                                            ECanaRegs.CANMC.bit.SUSP = 1;
                                            //ECanaRegs.CANES.bit.SMA = 0x0001;
                                        }

            //if (ECanaRegs.CANES.bit.CCE == 1) ECanaRegs.CANES.bit.CCE = 0x0001;
            if (ECanaRegs.CANES.bit.PDA == 1) ECanaRegs.CANES.bit.PDA = 0x0001;
           
            LedSwitch();       

            return(false);
        }       
}

 

The problem that i have is that even when  i reset the error flags with ResetErr(), and un-plug one of the CAN-Modules from the T node and plug in again, the communication gets bloked.

 

Thank You.

Regards.

 

  • 1.) I don't think that your function will work properly. If you read the first paragrapth of spru074, chapter 2.13 page 51, it says that if one bit is set, the others get frozen. If you clear the bit that has been set first, only then the next bit will be set in CANES. So if you start to clear the bits in the sequence of your function, only 1 bit will be cleared. After leaving that function CANES will immediately be reloaded with the next error flag. To clear all flags, you must call that function multiple times, until all flags are cleared. Best way to to this is to write an interrupt service for CAN - Errors. This ISR will be triggered multiple times, each time an error-flag is set.

    2.) some the bits cannot be cleared (SMA, PDA, - see figure 2-13. of spru074).

    3.) SMA is a status bit. Your code to set SUSP = 1 in case of an active SMA is wrong, because this will change the Emulation Suspend mode from SOFT to FREE. When you initialize the CAN, your make a desicion between SOFT ( on Emulation suspend an ongoing CAN transmission is fiinshed and then the CAN module stops) and FREE ( on Emulation Suspend the CAN module keeps running). SMA is just an indication, if the CAN module has entered the suspend mode or not.

    4.) If you have just 2 nodes in a CAN and you unplug one of them, the other node (if it transmits messages) will soon go into bus off state due to missing ACKs. If you replug the node, it is too late for the other node.  Try to use a 3rd node oin your net.

    Regards

     

     

     

     

  • Hello

    Firts thank you for your answer.

    I have chenged my function into:

    bool IsResponseSent()
    {   
        if (ECanaRegs.CANES.all <= 2) return(true);
        else
            {               
                if (ECanaRegs.CANES.bit.FE == 1) ECanaRegs.CANES.bit.FE = 0x0001;
                if (ECanaRegs.CANES.bit.BE == 1) ECanaRegs.CANES.bit.BE = 0x0001;
                if (ECanaRegs.CANES.bit.SA1 == 0) ECanaRegs.CANES.bit.SA1 = 0x0001;
                if (ECanaRegs.CANES.bit.CRCE == 1) ECanaRegs.CANES.bit.CRCE = 0x0001;
                if (ECanaRegs.CANES.bit.SE == 1) ECanaRegs.CANES.bit.SE = 0x0001;
                if (ECanaRegs.CANES.bit.ACKE == 1) ECanaRegs.CANES.bit.ACKE = 0x0001;           
                if (ECanaRegs.CANES.bit.BO == 1)
                                            {   
                                                ECanaRegs.CANMC.bit.CCR = 1;
                                                while(ECanaRegs.CANES.bit.CCE == 0);
                                                //ECanaRegs.CANES.bit.BO = 0x0001;
                                            }
                if (ECanaRegs.CANES.bit.EP == 1) ECanaRegs.CANES.bit.EP = 0x0001;
                if (ECanaRegs.CANES.bit.EW == 1) ECanaRegs.CANES.bit.EW = 0x0001;
               
                //if (ECanaRegs.CANES.bit.SMA == 1) ECanaRegs.CANES.bit.SMA = 0x0001;
                if (ECanaRegs.CANES.bit.CCE == 1) ECanaRegs.CANES.bit.CCE = 0x0001;
                //if (ECanaRegs.CANES.bit.PDA == 1) ECanaRegs.CANES.bit.PDA = 0x0001;                                               
               
                LedSwitch();       

                return(false);
            }       
    }

    but the CCE stays in 1 and i can not send.

     

    thanks

  • If the CAN node is in Bus off state, the next step depends on the initialization of the ABO bit. If auto bus on is 1, then the node will re-enter active mode, if there was an CAN idle time of 128'11 bit periods at the physical CAN-Line. If your physical net traffic includes such a period, then your command CCR=1 will be answered by the CAN with CCE=1.  If ABO=0, you need a full new CAN - initialization or RESET to reactivate your CAN.

    However, you haven't answered to point (4) of my first post. Try to use more than 2 nodes when you experiment with pug-off an plug-on.

     

     

  • Hello

    Thank you again for your help.

    I do not have 3 CAN Modules now, i will get a new one sooon for testing. How 3 modules can help me?

    Thank You

    Regards


  • In your first post you stated that you tried to unplug 1 node from your CAN. I explained that when you unplug 1 node from a 2 node only net, the 2nd node will enter Bus-OFF because of a missing partner. Result: plug ON of node 1 will not work, because node 2 has gone.. If you use a 3rd node and unplug 1 node, the 2 remaining nodes will stay alive.

  • Hello

    In this phase it doesn't matter, because when i un-plug one of the CAN module the intterupt system gets bloked.

    I have 2 intterupts:

    // Overload CPU Timer 0 and CAN1 ISR - entry
          EALLOW;
          PieVectTable.TINT0 = &cpu_timer0_isr;
          PieVectTable.ECAN1INTA = &ecan1intA_isr;
          EDIS;

    One for can transmission and receiving and one for a timer, when i unplug-and-plug one of the can modules from the nodes the can interrupt system doesn't trigger any more.

    Thank You.

    Regards.