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 Sending/receiving multiple messages

Hi there,

I have an issue regarding the CAN bus. I have already seen the sample example for my TIVA TM3C123G launchpad but they didn't help me much. My problem is that I want to send different messages from specific IDs and similarly want to receive different messages from specific IDs. My main confusion is that let say I want to receive/send 10 messages, do I need to set 10 Rx and TX flags?

I am confused about how I need to setup the CAN interrupt handler as i want to send/receive 10 messages. Kindly could you please provide me some code for the CAN interrupt handler which can handle multiple RX/TX messages from specific IDs asap.

I shall be very grateful to you.

Regards,

Mohsin 

  • Moshin,

     

    No code but a few notes. 

     

    No it is not necessary to set up 10 message boxes.  You can configure a CAN input box to read all (or a subset of the) messages.  For transmission you can use a single message box to send by sending a message, and then reconfiguring it to send the next message.  In fact this technique is the 'usual' way  to start using CAN and some controllers do not allow much more.

    The additional boxes come in handy when you have to deal with remote request frames (I have not dealt with anything that does make much use of that feature) or for separating for efficiency.  Recieive efficiency particularly, but also send.  With many fullcan implementations (but not easily with the TIVA implementation) you can set up a message buffer to receive a message and then simply read the result whenever you need it.  No need to have an interrupt, the latest value is present in the message buffer. Because of the memory interface used in TIVA you probably want to use an interrupt to transfer information from the mesage buffer to somewhere a little better arranges.  However, the filters still allow you to limit the messages received in each message box buffer which allows you to potentially only need to respond to a small subset of messages greatly improving efficiency.

    So I'd suggest proceeding from the examples without worrying about the extra CAN message boxes available until you either run into a problem with overhead or you have it working and have reached the stage where it makes sense to make thing more elegant for the next improvement or addition of capability.

     

    Robert

  • Dear Robert,

    Thanks for your reply. My problem is that when I send a message from particular ID, it should send a particular message from specific ID. In my case I need a CAN RX interrupt. Sorry I didn't understand

    "For transmission you can use a single message box to send by sending a message, and then re configuring it to send the next message." 

    Kindly could you please provide few lines of code such that I can configure 3 RX & TX messages each with specific ID and TX & should send a message in response of RX message. Cheers

    Thanks for your reply again.

    Mohsin

  • Sorry, I don't have time to do that properly at the moment.  You would have to wait an unreasonable amount of time.  I can give you an outline though.

     

    For transmit

    1.   Wait until transmitted
    2.   Set up transmit buffer with message ID and data
    3.   Transmit

     

    For receive

    •   Set up receive buffer to receive all messages
    •  In receive interrupt
      •     switch(received message ID)
      •           case Message 1:
      •                 Do something
      •                  Transmit message (see above)

     

      •             case Message 2:
      •                 Do something
      •                  Transmit message (see above)

    Modify according to need. 

    Obviously I've left out a lot of details but you should be able to work from there.  This uses one transmit and one receive buffer.  Obvious weakness is that the receive interrupt is blocked waiting for transmission, so that is the first obvious improvement to make once the basics work.

     

    Rpbert