Since the USB2LIN converter is equiped with one CAN bus port (CAN 2.0, high speed) in addition to the two LIN bus interfaces, it can be used as a gateway between LIN and CAN bus using the LIN gateway tool included in the PP2CAN software.
In this mode, the LIN interface works as a master and reads or sends data to/from LIN peripherals. The gateway function between LIN and CAN can be used separately for both LIN ports. However, other scenarios are also possible, for example, one LIN port is used for the gateway function and the other LIN port is used to monitor LIN traffic in the scan mode.
The first step is to create a LIN table (A). That is, messages that are periodically sent to or read from the LIN. Remind that the LIN is not a multimaster, unlike the CAN bus, but can contain only one master and up to 16 slaves. In our case, the master must be the corresponding port of the USB2LIN converter. In the example shown in the figure, there is a message with Id 22h in the table which reads data of 7 bytes from the LIN and the corresponding slave device and a second message which sends a message with Id 0Ah of 8 bytes to the LIN bus. Afterwards, if a list of messages is created in the table, the Gateway (B) button can be clicked to open a window where the LIN/CAN gateway rules are edited. Here it is possible to edit the corresponding rules. Whether it is a CAN message, whose data is copied to the LIN message after its arrival and which writes the data to the LIN, or the opposite case, where the data read from the LIN is copied to the CAN message and which is sent to the CAN bus, is selected using the switches CAN->LIN or LIN->CAN. Depending on which option is selected, the LIN message identifiers from the LIN table are then available for selection. For CAN messages it is then possible to set the appropriate identifier and select whether it is 11 or 29 bit format.
If the settings are complete, the LIN table can be uploaded to the USB2LIN converter. The gateway function is started by activating the Enable gateway option. The rules in our example have the following functionality: if a message with identifier 123d arrives at the USB2LIN converter via CAN, the data is written to the LIN table and LIN messages with identifier 0Ah. This message is then generated periodically on the LIN with this new data until it is overwritten by the next incoming data from the CAN. Furthermore, if data is read from the LIN using LIN message 22h - i.e. a slave responds to the request, a message with identifier 12345d is generated on the CAN bus with this read data.
For testing, if you do not have any LIN device available, it is possible to use the second LIN port of the converter and connect both ports with a wire. Then switch this second port to slave mode and set its response in the table - generate data on LIN when a message with identifier 22h is detected on LIN.