LIN Interface as Slave Device

NI-CAN

LIN Interface as Slave Device

The following steps demonstrate how to use the Frame API functions in a LIN application in which the LIN interface is acting as a slave device. The steps are shown in the following flowchart.

Frame API – LIN interface acting as slave

  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.

  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 received by the master. 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. 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. Read from the slave task using the Network Interface Object

    As the external master issues headers, the LIN interface slave task will either subscribe to data or publish data in response to each. 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.

    Typically, slave devices that publish data update it 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 slave 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.