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.

How to Detect node on CAN bus before attempt to Transmit

In our application, we transmit 3 CAN messages every second. Each CAN message has its own mailbox. Time between transmission is 250 milliseconds.

We have a timer ISR to call our canBusTransmit() function. The problem was that each time the function was called, I had a while loop waiting for the transmit acknowledge (TAn) bit to become set. With no nodes on the bus, after awhile, the application would roll over and die.

To get around this, I check to see if the Transmission Request bit is set. If it is, I exit the function. However, this makes me think that I've got three instances of the while loop running until I hook the device up to the bus. But it seems to communicate fine when I do.

I would like to know if there is a way to determine if there is another node on the bus even before I attempt to transmit. Also, I am thinking of not using a while loop, and use an interrupt to clear the TAn. Pseudo code below.

void ecanBusTransmit()
{
    /* Get the a bitmask  for the mailbox */

    /* add this check in case there are no other nodes on the bus.
     * If not, a later check will cause this function to block and
     * eventually the program will roll over and die.
     */
    if (ECanaRegs.CANTRS.all & uliBitpos)
    {
        /* do nothing */
    }
    else
    {
        /* set the registers to load the mailbox. */
       
        /* Set MSGID */
  
        /* mailbox enable */
    
        /* Set DLC */
   
        /* set the data */
   
        /* enable transmitting the message. */
        /* Set the TRS bits for next transfer */
       
        /* Wait for TAn bit to be set. */
        while((ECanaRegs.CANTA.all & uliBitpos) == 0U )
        {
        }
        /* Clear TAn. */
        ECanaRegs.CANTA.all = uliBitpos;
    }
}