LIN Interface as Master

NI-CAN

LIN Interface as Master

The following steps demonstrate how to use the Frame API functions in a LIN application in which the LIN interface is emulating a master device executing the behavior specified in an LDF. The steps are shown in the following flowchart.

Frame API – LIN interface emulating a master executing the behavior specified in an LDF.

  1. Open a Network Interface Object.

    You must call the ncOpenObject function to open the Network Interface Object used in this example. The ncOpenObject function returns a handle for use in all subsequent Frame API calls for that object. When you are using the LabVIEW function library, this handle is passed through the upper left and right terminals of each Frame API function used after the open.

  2. Set attributes for the Network Interface Object.

    Prior to starting the Network Interface Object, you must configure it with its initial attribute settings. These are configured by calling the ncSetAttribute function with each desired attribute ID and value. This function takes the name of the object to configure, along with the attribute ID and value.

    For this example, the baud rate and checksum type should be configured to match those of the LIN being accessed. Self-reception is shown as enabled but it is optional. When the slave task publishes data, the resulting full frame is logged into the read queue only if self-reception is enabled. In other words, if the response queue is loaded with three entries that publish in response and two entries that subscribe in response, then only the resulting full frames for the IDs of the two subscribing entries will be logged if self-reception is disabled. If self-reception is enabled, then the resulting full frames for the IDs of all five entries will be logged. Logging of bus errors is useful for troubleshooting, in the event the slave device does not behave as expected. Since the LIN interface is emulating the master device, termination should be enabled.

  3. Start Communication.

    You must start communication on the LIN bus before you can use the Network Interface Object to transfer data.

  4. Write to the slave task using the Network Interface Object.

    Write response entry frames to the LIN interface slave task in order to configure how it will respond to the ID in each header transmitted by the master task. If it should subscribe to data in response to a header ID, then the DLC should be set to 0 and the data bytes are don’t care. If it should publish in response to a header ID, then the DLC should be in the range of one to eight with the data bytes containing the actual data to publish. If you are using an LDF, then it will define the behavior of each slave task (including the slave task in the master node), regarding its response to each header. Write completion of the response entry frame types will set a write success flag in the interface. ncWaitForState should be used to wait for write success following the write.

  5. Write to the master task and read from the slave task using the Network Interface Object.

    In this example, the NI LIN interface is acting as a master node. Thus, after the initial response entries have been loaded into the slave task response queue (step 4), you can issue the first header on the bus by writing a header frame type to the LIN interface. Per the LIN 2.0 Specification, the LIN interface master task handles processing of the header frame type and subsequent transmission of the header onto the LIN.

    As a result of the LIN interface master task transmitting a header, the LIN interface slave task will either subscribe to data or publish data in response. Each time the slave task subscribes to data in response, it will combine the header and response into a single full frame type which is placed into the read queue. If self-reception is enabled, then each time the slave task publishes data in response, it will combine the header and response into a single full frame type which is placed into the read queue. If log bus errors is enabled, then the first bus error that occurs within the header or response portion of each LIN frame will be placed into a bus error frame and loaded into the read queue. The LIN interface slave task will ignore the remainder of the frame transaction on the bus and prepare for the reception of the next header. The loading of the full or bus error frame into the read queue will set a read available flag in the interface. ncWaitForState should be used to wait for read available before executing the ncRead or ncReadMult function. You may choose to insert a time delay after processing one complete frame. The LDF will specify the delay for each ID.

    Typically, data that is published by a slave task (including the slave task in a master node, as is the case in this example), is updated as a result of a change in one or more inputs. Response entries within the LIN interface slave task response queue may be updated at any point to emulate this behavior. Steps 4 and 5 should be repeated as necessary to create the desired master behavior.

  6. Stop communication.

    Stop communication on the LIN bus before closing the Network Interface Object.

  7. Close the Network Interface Object.

    When you are finished accessing the LIN bus, close the Network Interface Object using the ncCloseObject function before you exit the application.