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.

Compiler/TM4C123AE6PM: CAN bus 2 way communication

Part Number: TM4C123AE6PM

Tool/software: TI C/C++ Compiler

Hello everyone, 

I have a question regarding CAN communication. I have two boards with TM4C123AE6PM and in both of them PA0 and PA1 are used for CAN and connected to CAN transceiver and I have set up communication in one direction. Now I want to have board 2 also send information back to board 1. Do I manage to do that by creating another message object ( tCANMsgObject ) with type MSG_OBJ_TYPE_TX and have board send it back? And in board 1 in interrupt check for message object by ID? Is that correct or I got something wrong?

  • Djedjica said:
    I have a question regarding CAN communication. I have two boards with TM4C123AE6PM and in both of them PA0 and PA1 are used for CAN and connected to CAN transceiver and I have set up communication in one direction. Now I want to have board 2 also send information back to board 1. Do I manage to do that by creating another message object ( tCANMsgObject ) with type MSG_OBJ_TYPE_TX and have board send it back?

    Yes. Make sure the arbitration values (usually called IDs) are different though.

    Although I have a feeling you may have go a hold of the wrong end of the stick. Although you can set up CAN as a reply/response you miss most of its utility when you do so.

    CAN is fundamentally a control network. It does not fit neatly into the ISO network stack model although several of the HLPs (Higher Level Protocols) shoehorn it in.

    Close analogies to CANs fundamental nature would be publish/subscribe or reflective memory. The idea is each node sends out information/commands and other nodes 'listen' to only those that they are concerned with. For example you could have a motor control setup where there are two mechanical connected motors controlled from a speed control with a separate HMI and a separate interlock controller.

    • The speed control sends out speed commands
      • In the case of receiving a fault it will set the speed output to zero.
    • The primary motor/controller controls the speed
      • It reports the motor and controller temperature
        • It will reduce speed in the case of overtemperature
        • If the temperature reaches a limit point it will declare a fault, shutdown and send a fault message
      • It reports its current operating torque
        • It will declare a fault, shutdown and send a fault message in case of an overtorque
      • It reports its voltage and current
        • An overcurrent will cause the controller to declare a fault, shutdown and send a fault message
      • In case of a fault being received it will shutdown
    • The secondary motor/controller regulates its torque to some fraction of the primary
    • It reports the motor and controller temperature
      • It will reduce torque in the case of overtemperature
      • If the temperature reaches a limit point it will declare a fault, shutdown and send a fault message
    • It reports its current operating torque
      • It will declare a fault, shutdown and send a fault message in case of an overtorque
    • It reports its voltage and current
      • An overcurrent will cause the controller to declare a fault, shutdown and send a fault message
    • In case of a fault being received it will shutdown
    • The HMI display status and fault information
      • Status and fault information will be gathered from the data on the bus
    • The interlock controller monitors interlock switches (The pattern should be obvious now)
    • If the interlocks are not satisfied then the controller will declare a fault and send a fault message

    Obviously, this is simplified presentation but think it gives you the idea. Note that none of these involve a query/response setup. You would do something like RMA (Rate Monotonic Analysis, don't let the name intimidate you it's really quite simple) to set up the schedule for these messages and ensure you don't overload the network. Once you have done the work to set it up you end up with something that is fairly easy to extend and performs well.

    Robert

  • Thank You Mr. Adsett for Yor extensive report, I will look for some means to schedule messages. In this project response is very rear, hopefully never. I want to set it up just if one chip gives fault, than this listening system can send to controller to reset some peripheral. But in one new project your advices throw CAN out of the frame and we were thinking about it, but there we need query/response communication among multiple nodes so I suppose something other should be used.
    Kind regards,
  • Djedjica said:
    I want to set it up just if one chip gives fault, than this listening system can send to controller to reset some peripheral.

    This is something where reply/response is not the best form. It is something for which CAN is well suited.

    What you are really looking for is a set of watchdog signals. Each board sends an ongoing watchdog message. If that message is not received periodically then the receiving parties know something has gone wrong and can attempt to recover or shut down. Note that this also captures network faults which the query response will not do.

    You might set up each message in a format something like

    • Byte 0: an ongoing counter. Updated each time the message is sent
    • Byte 1: Status flags indicating the status of the board, including perhaps fault flags or state information

    You might send these messages every 10mS and declare a fault if the count on a received message does not change within 30mS. You timing will vary depending on your system.

    Djedjica said:
    but there we need query/response communication among multiple nodes so I suppose something other should be used.

    You misunderstand. The issue is not that query/response cannot be used with CAN but that query/response should not be used for a control protocol. Your fault response is one example of a control message. You do need query/response for items like retrieving fault history or details and you can do this on CAN. Just don't build up a query/response protocol and then use itfor regular control, the base CAN protocol is better suited to that.

    Robert

  • Two more "above/beyond" postings - SO WORTHY of "LIKE" - yet such award is denied - for NO VALID REASON!

    Does your bookshelf contain suggestions for the (assumed) many here (to include moi) which further detail the, "Primary & Properly Purposeful Use of CAN? Both poster - and this (appreciative/(LIKING) reader - would benefit from further detailing of, "CAN's raison d'être."

    Thanks once more for sharing your time & expertise - know that both are (very) much appreciated. (even LIKED - many would say...)
  • I'll put together links to an item or two I know of. Truthfully there's not a lot. Too many have fallen into the trap of assuming the ISO model is the only (or best) model for all purposes.

    Robert
  • As promised a couple of references for the bookshelf

    First https://www.kvaser.com/can-protocol-tutorial/ A general introduction to CAN.

    can-protocol-tutorial said:
    Note 1: It is worth noting that the presence of an Acknowledgement Bit on the bus does not mean that any of the intended addressees has received the message. The only thing we know is that one or more nodes on the bus has received it correctly.

    Note 2: The Identifier in the Arbitration Field is not, despite of its name, necessarily identifying the contents of the message


    http://www.kvaser.com/wp-content/uploads/2014/02/ck301p.pdf This is an introduction to a particular CAN HLP (Higher Level protocol). It is worth reading though, especially, if you are most familiar with data networking protocols such as TCP/IP. The HLP described is quite a bit different from TCP/IP and although other HLPs have dominated it's well worth reviewing this one to really show you how a control protocol can be quite different from a data protocol. Of particular note on Pg 12, Para 2 there is the following

    CAN Kingdom Standard said:
    You will, e.g., not find any resemblance with the ISO Open Systems Interconnections (OSI) reference model. The main reason for this is that the OSI model does not support real-time networks! A basic idea in the OSI seven layer model is that the designer should only need to care about two levels; the level where he is working and the interface to the level below. When designing a real-time system however, you always have to care about how long time it takes for transmitting a piece of information  through all layers from one node to another. How this transmission is made is already mainly given by the CAN protocol in a way that does not fit very well into the OSI layers. CAN deals mainly with the lower OSI layers but the arbitration scheme results in messages priorities, something that belongs to the application layer (ref. [3])! The "Client/Server" model used in OSI also tends leading thoughts into a point to point flow of information, which is contradictory to the message oriented idea of the CAN protocol with broadcasting and multicasting possibilities. These possibilities are a great strength of CAN as they reduce the amount of communication needed in a system. Further more all nodes will get the same information simultaneously with the CAN protocol and this feature is valuable in Controller Area Networks where the nodes have to work in a synchronized way. You do not find anything about this in the OSI model. Thus it does not provide any real help to make an efficient use of the CAN protocol or to make a CAN network understandable. That is why the OSI model is not used here.

    Note that this same comment applies to other control networks such as TTP (Time Triggered Protocol), Flexray and TT/E (Time Triggered Ethernet)

    Kvaser also has a number of articles on the basics of various HLPs and other items related to real-time network communications.

    https://www.kvaser.com/about-can/higher-layer-protocols/

    Robert