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.

Extend CAN Objects

Hi there, I want to use more than 32 CAN objects for my application. Currrently TIVA driverlib only support upto 32 message objects. Is there any way I can extend the CAN message objects? Thanks

  • No, that's a hardware limitation.

    You will need to re-design how you are using them. Keep in mind that each object can represent multiple IDs and that often it's not necessary to have multiple outgoing objects.

    Robert
  • Hi, Thanks for your reply. Problem is that for my application, I want to receive CAN messages from 40 different CAN IDs. Is there any way can I achieve this? Thanks

  • Mohsin Mahmud said:

    Hi, Thanks for your reply. Problem is that for my application, I want to receive CAN messages from 40 different CAN IDs. Is there any way can I achieve this? Thanks

    Previous Reply said:
    Keep in mind that each object can represent multiple IDs
    It's easier if multiple messages share a bit pattern. However, in the worst case you set up an incoming mailbox to receive all IDs.
    See http://www.cse.dmu.ac.uk/~eg/tele/CanbusIDandMask.html for a quick intro to the concept.
    Robert
  • Hi, Thanks for your reply again. How can I receive multiple CAN messages from different IDs at the same using single message object? Can you send me some code for that? Thanks

  • Mohsin Mahmud said:
    How can I receive multiple CAN messages from different IDs at the same using single message object?

    Just as I explained in the last post. Each message object has an ID and a mask to mask off the bits to compare. I gave you link that explains further. Do you have some specific questions?

    Mohsin Mahmud said:
    Can you send me some code for that?

    No. I don't have example code. Although there might be some in the TIVAWare examples.

    Robert

  • Hi,

    Problem is that when I try to send multiple CAN messages, I couldn't able to send using 1 message object. See my code below. When I call this in my program, I couldn't send 5 messages at the same time. Sorry for keep asking but I'm bit confused understanding this. Thanks

    int i;

    for (i = 0; i<5; i++)

    {

    g_sCAN0TxMessage.ui32MsgID = 0x001 + i;
    g_sCAN0TxMessage.ui32MsgIDMask = 0x7ff;
    g_sCAN0TxMessage.ui32Flags = MSG_OBJ_NO_FLAGS;
    g_sCAN0TxMessage.ui32MsgLen = 4;
    TxMsg1Data[0] = 0;
    TxMsg1Data[1] = 1;
    TxMsg1Data[2] = 2;
    TxMsg1Data[3] = 3;
    g_sCAN0TxMessage.pui8MsgData = TxMsg1Data;
    ROM_CANMessageSet(CAN0_BASE, 1, &g_sCAN0TxMessage, MSG_OBJ_TYPE_TX);

    }

  • You can't queue up multiple messages in the same mailbox at once. You must wait for one to complete before you send the next. No big loss, the H/W cannot send multiple messages at once in any case.

    I think the only time you would need to dedicate multiple buffers to sending is in the event that you allow CAN remote requests and most protocols don't use that feature.

    If you (for some odd reason) be sure of loading the bus to capacity you could use two buffers but that does add some complications.

    Robert
  • Hi Robert, Thanks for your reply. I need to send multiples at the same time as I only want to use one object as my other can objects are used for receiving. Kidlky could you please send me code snippet of how to wait for Transmit of each can message using can driverlib. Thanks
  • Pseudo code only

    for each message
    send message
    wait for send complete (Check CANStatusGet)
    next message

    Note that send message could take quite a while. You may want to poll the status in your operating loop or make the transmit interrupt based.

    Robert
  • Hi Robert, I'm trying to poll the status. I'm using interrupt on receivering CAN messages. I can't use interrupt to get Tx status as I want to send a can message upon receiving a CAN message in interrupt handler. Hence I want to poll the TX status.

    Problem is that It never get the status back and hence It hangs my program. See my code below

    g_sCAN0TxMessage.ui32MsgID = 0x001;
    g_sCAN0TxMessage.ui32MsgIDMask = 0x7ff;
    g_sCAN0TxMessage.ui32Flags = MSG_OBJ_NO_FLAGS;
    g_sCAN0TxMessage.ui32MsgLen = 4;
    TxMsgData[0] = 0;
    TxMsgData[1] = 1;
    TxMsgData[2] = 2;
    TxMsgData[3] = 3;
    g_sCAN0TxMessage.pui8MsgData = TxMsgData;
    ROM_CANMessageSet(CAN0_BASE, 2, &g_sCAN0TxMessage, MSG_OBJ_TYPE_TX);
    while (ROM_CANStatusGet(CAN0_BASE, CAN_STS_CONTROL) != 2)
    {
    }

    Kindly guide me on this. Thanks.

  • Mohsin Mahmud said:
    Hi Robert, I'm trying to poll the status. I'm using interrupt on receivering CAN messages. I can't use interrupt to get Tx status as I want to send a can message upon receiving a CAN message in interrupt handler. Hence I want to poll the TX status

    OK, this is more likely to fail than work. You've extended your receive interrupt time (and thus latency) tremendously.

    There is no reason you couldn't either transmit using polling or a transmit interrupt to achieve this end. Given your apparent level of experience I'd suggest polling. Just set a flag in the interrupt that your main polling routine can read.

    Mohsin Mahmud said:

    Problem is that It never get the status back and hence It hangs my program. See my code below

    g_sCAN0TxMessage.ui32MsgID = 0x001;
    g_sCAN0TxMessage.ui32MsgIDMask = 0x7ff

    Use paste code (the </> symbol when you are editing in the formatted response window), the result is a lot more readable.

    Mohsin Mahmud said:
    while (ROM_CANStatusGet(CAN0_BASE, CAN_STS_CONTROL) != 2)

    I believe the return from this function is a bitmap, not an index.

    Robert

  • Hi,

    At this stage some hardware info are needed: did you checked with an oscilloscope if there is some activity on the bus?

     Also, you mention some words about the CAN status - but what is its content? what bits are set? BOFF? also LEC field is important to detect what is wrong. Same for CANERR register - how many are reported.

    Depending how the bus is realised, maybe sometime CAN bit timing should be carefully changed/trimmered. 

    Set a breakpoint and inspect those registers and figure out what really goes wrong.

    From software point of view, maybe it will be useful to read some things about CANopen protocol, some useful ideas. There are some micros with this protocol embedded into ROM, similar to driverlib (unfortunately not from TI, but is good to know).