CANNY 5.3 MD1A. LIN driver
- General Description
- Drivers registers
- CANNY 5.3 MD1A in MASTER mode
- CANNY 5.3 MD1A in SLAVE mode
- CANNY 5.3 MD1A in MULTISLAVE mode
- Energy saving mode (low power consumption mode)
General Description
Up to two CANNY 5.3 MD1A input-output channels can be used to organize data reception and transmission as independent LIN driver channels.
LIN driver channels can be connected both in tandem and individually. They have individual settings for baud rate, pull-up line and bus node type - MASTER or SLAVE.
LIN driver operates using the controller’s channel resources, but has a higher priority than the discrete input-output driver. This means that for all channels, for which the LIN driver is activated, all value changes in registers associated with discrete input-output driver will be ignored.
Driver registers
Below is a description of valid values for registers controlling LIN-bus driver operation.
LIN driver configuration registers allow you to set up the controller as a LIN bus node:
Register | Expected Values |
---|---|
LINx Mode Setup Register | 1…N = set a LIN driver channel configuration that determines the current operation mode and its parameters (defined by a named constant from the named constants list); 0 = disconnect the channel from the LIN driver, return channel control to the discrete IO driver and allow the channel’s status to be changed from the function diagram |
LINx IO Channel Select Register | 8…10 = assign the specified input-output channel to the LINx driver; use the specified input-output channel to work with the corresponding LINx interface. |
Channel configuration for operation in this mode is determined by a constant, which defines a combination of parameters: protocol version, baud rate, operation mode and the availability of internal channel pull-up.
Parameter | Permitted values |
---|---|
LIN protocol version | 1.3; 2.0 |
Baud rate | 2400; 9600; 10500; 19200 |
Operation mode | MASTER; SLAVE |
Pull-up | Weak Pull-up; Float |
Named constants that define a combination of LIN driver parameters are available in the “LIN Modes” CannyLab named constants list.
Register | Return Values |
---|---|
LINx Overflow Register | 1 = registered buffer overflow on the corresponding channel of the LIN driver; 0 = no buffer overflow registered on the corresponding channel of the LIN driver. |
LINx Error Register | 1 = an error ocurred during LIN data reception; 0 = the driver is operating normally. |
LINx Ready to Send Register | 1 = LIN data transmit buffer of the corresponding channel is free and ready; 0 = LIN driver data transmission buffer is busy. |
LINx SLAVE Data Delivered Register | 1 = in SLAVE mode, indicates successful data transfer from the data transmit buffer of the corresponding LIN channel, in response to a MASTER node request; 0 = in SLAVE mode, no request was received from the MASTER node on the corresponding channel. |
LINx SLAVE Extended Transmitting Buffers Data Delivered Flags Register | 1…255 = in MULTISLAVE mode, denotes successful data transmission from the SLAVE Extended Transmitting Buffer of the corresponding LIN channel in response to a MASTER-node request. Upon successful transmission the value «1» is assinged to the bit, the number of which corresponds to the number of the sent SLAVE Extended Transmitting buffer, i.e, upon successful transmission, the values will look like the following: buffer №0 - flag register = 1 = 0x01 = 0b00000001; buffer №1 - flag register = 2 = 0x02 = 0b00000010; buffer №2 - flag register = 4 = 0x04 = 0b00000100; buffer №3 - flag register = 8 = 0x08 = 0b00001000; buffer №4 - flag register = 1 = 0x10 = 0b00010000; buffer №5 - flag register = 2 = 0x20 = 0b00100000; buffer №6 - flag register = 4 = 0x40 = 0b01000000; buffer №7 - flag register = 8 = 0x80 = 0b10000000. 0 = in MULTISLAVE mode, no request for data from Extended Transmitting Buffers was received from the MASTER node. |
Register | Return Values |
---|---|
LINx Data Set Ready Register | 1 = the message is received and placed into the corresponding LIN channel’s receive buffer; 0 = no actual data is present in the corresponding LIN channel’s receive buffer. |
LINx Received Data Register LEN | 0…8 = a value equal to the number of data bytes in the packet received via the respective LIN channel |
LINx Received Data Register ID | 0…63 = message ID of the message received via the respective LIN channel (see note) |
LINx Received Data Register D1:D0 … LINx Received Data Register LINx D7:D6 |
0…0xFFFF = respective data byte values of LIN receive buffers of each channel, two bytes per register |
Note: LIN Received Data Register ID displays only the 6 lower bits of the identifier: 4-bit address of the device and the 2 bits used in the LIN 1.1 to encode message length, used to expand the address in later LIN protocol versions. 10 higher bits of the LIN received message ID register are always zero.
Register | Expected Values |
---|---|
LINx Request to Send Register | ≥ 1 = load data from the transmit registers into the respective channel’s LIN transmit buffer 0 = do not load data into the respective channel’s LIN transmit buffer |
LINx SLAVE Extended Transmitting Buffer Number | 0…7 = Working in MULTISLAVE mode, number of the Extended Transmitting Buffer of the respective LIN driver channel, that will be filled during the current diagram execution loop |
LINx Transmit Data Register LEN | 0…8 = number of data bytes that will be transmitted over the line when the controller receives a command to send on the corresponding LIN channel |
LINx Transmit Data Register ID | 0…63 = LIN ID value for message transmission via the respective LIN channel |
LINx Transmit Data Register D1:D0 … LINx Transmit Data Register D7:D6 |
0…0xFFFF = data byte values to transmit on the respective LIN channel, two bytes per register |
Note: When transmitting LIN-messages, the driver discards all but the 6 lower bits of the LIN ID register, automatically generates 2 parity bits and adds them to the ID, according to requirements of the standard.
Note: In SLAVE mode, if the Extended Transmitting Buffer Number register is not used (i.e the Extended Transmitting Buffers are empty), the driver works in standard SLAVE mode, with a single LIN transmit buffer.
Note: In SLAVE mode, if the Extended Transmitting Buffers are filled using the Extended Transmitting Buffer Number register, the driver works in MULTISLAVE mode.
Note: In MULTISLAVE mode, the SLAVE Extended Transmitting Buffer are filled sequentially, one per diagram execution loop.
Note: When working with LIN networks of versions below 1.3, be careful while forming outgoing messages. The driver allows you to use combinations of length and identifier of the transmitted message that are unavailable for use with LIN below 1.3.
CANNY 5.3 MD1A in MASTER mode
To switch the LIN driver channel into MASTER mode, copy the constant value corresponding to MASTER mode into the respective channel’s "LINx Mode Setup Register».
For a MASTER to receive data from a SLAVE-node, you need to send the following request to the LIN bus: send the message header that contains the identifier of the SLAVE node from which the data is requested. Set the length of the transmitted message LINx LEN to zero, write a non-zero value into the transmission start register. When a response is received from the SLAVE, the data will be placed into the receive register of the corresponding LIN driver channel, and the LINx Data Set Ready Register will be set to 1, indicating data availability.
Below is an example of a function diagram for MASTER data reception from a SLAVE node. MASTER sends a data request from the SLAVE with the identifier 0x02 every 100 ms. After receiving a response, the controller stores the first 2 bytes of data in the D-flip-flop.
![Function diagram for the MASTER to receive data from a SLAVE device.](/img/docs/en/c53md1a/lin/c53md1a_lin_1.png)
For data transmission in MASTER mode, fill the ID and Data registers, while setting the transmission LIN LEN Register to a value equal to the number of transmitted data bytes. This value must be greater than zero but less than nine. Send the message by writing a non-zero value into the “LINx Request To Send Register”. The contents of the registers are copied into the LIN transmit buffer, the driver will immediately proceed to send a message.
Note: To prevent data loss, before sending a new LIN message, it is recommended to ensure that the LIN channel transmit buffer is ready to transfer the next message, by checking the LINx Ready To Send Register.
Below is an example of a function diagram used to send data to the LIN bus by the MASTER. MASTER sends a message to the bus with the identifier 0x01 that contains 2 bytes of data (0h0A and 0x55) every 500 ms.
![Function diagram for sending data to the LIN bus by the MASTER.](/img/docs/en/c53md1a/lin/c53md1a_lin_2.png)
Note: If the LINx Request To Send Register is permanently set a non-zero value, an attempt to copy the data into the transmission buffer for sending LIN messages will be made during each diagram execution loop. To avoid overflow of LIN transmission buffer, trigger the start of data transmission with a single pulse, using, for example, a Rising Edge Detector function block.
CANNY 5.3 MD1A in SLAVE mode
Operating in SLAVE mode, a LIN node receives all data transmitted over the network, but can not transmit data to the LIN bus by itself, without first receiving a request from a MASTER node.
To switch the LIN driver channel to SLAVE mode, copy the constant value corresponding to the selected mode into the respective channel’s "LINx Mode Setup Register».
To successfully send data in SLAVE mode upon MASTER-node request, you must prepare data in advance before that request is received by the controller. To do so, fill in all the necessary LINx Transmit Data Registers, namely: LIN ID register, message length register LIN LEN. Write information that you are going to send into the LINx Transmit data registers. Allow the data to be sent by setting the “LINx Request To Send Register” to a value of “1”. Upon doing all of the above the contents of data registers are copied into the LIN transmit buffer, if it is free. The data will be automatically sent each time the controller receives a request from the MASTER mode.
Note: If the LINx Request To Send Register is permanently set a non-zero value, then an attempt to copy the data to the transmission buffer for sending LIN messages will be made during each diagram execution loop. To avoid overflow of the LIN transmission buffer, trigger the start of data transmission with a single pulse, using, for example, a Rising Edge Detector function block.
Monitor MASTER requests and send automatic responses to it using the LIN driver in SLAVE mode by detecting the value “1” in LINx Data Delivered Register. Updating data in the transmission buffer is possible after it’s released. Status of the send buffer can be tracked by the value of the corresponding register.
![Function diagram for data transmission by the controller acting as a LIN node in SLAVE mode.](/img/docs/en/c53md1a/lin/c53md1a_lin_3.png)
Below is an example of a function diagram where the controller is set up as a SLAVE receiving data from the MASTER. Controller receives messages with the identifier 0x01 that contain any data. The first two bytes of data are subsequently stored in the D Flip-Flop.
![Function diagram for data reception by the controller acting as a SLAVE node receiving data from a MASTER.](/img/docs/en/c53md1a/lin/c53md1a_lin_4.png)
CANNY 5.3 MD1A in MULTISLAVE mode
Operating in MULTISLAVE mode, each LIN interface of the controller can act as multiple (up to eight per interface) LIN SLAVE nodes, enabling it to receive MASTER requests for multiple different IDs.
Switching the LIN driver to MULTISLAVE mode is performed automatically when LINx SLAVE Extended Transmitting Buffers are filled with data.
When a request is received from the MASTER, and the ID of said request is assigned to one of the Extended Transmitting Buffers, the data will be sent automatically, asynchronously to execution of the function diagram.
When the data is sent successfully, the respective flags will be set in the LINx SLAVE Extended Transmitting Buffers Data Delivered Flag register.
Fill the Extended Transmitting Buffers with data using: LINx Request to Send Register, LINx Transmit Data Register LEN, LINx Transmit Data Register ID and LINx Transmit Data Register Dy:Dz. These registers will be used by all the buffers. The data and ID of the message is sent into the buffer, the number of which is set in the LINx SLAVE Extended Transmitting Buffer Number at the moment when “1” is written to the LINx Request To Send Register.
Below is an example of the controller working in MULTISLAVE mode. In this function diagram, 4 LIN1 SLAVE Extended Transmission Buffers are filled and constantly updated. The updates happen sequentially, one per each diagram loop.
![Controller as MULTISLAVE example.](/img/docs/en/c53md1a/lin/c53md1a_lin_5.png)
Note that the above means that LIN driver working in SLAVE mode is the same as working in MULTISLAVE mode, but only using the Extended Transmision Buffer #0.
Energy saving mode (low power consumption mode)
To save power, the LIN specification allows you to switch all LIN network nodes to low power consumption mode. Most often, such a transition is initiated by a MASTER node sending an appropriate message to the bus. Alternatively SLAVE nodes can switch to this mode on their own, when there is no activity on the bus for a specified time interval. Exiting power saving mode can be initiated by any node on the bus. MASTER-node can awaken the LIN bus by simply querying the slaves. Awakening the LIN bus by SLAVE nodes is done by setting the “GND” potential on the line for a short period of time.
In the LIN driver of controller CANNY 5.3 MD1A, the MASTER-node just needs to start transmitting data or to query slaves to awaken the bus. SLAVE nodes send a request to awaken the BUS by transmitting a message with any identifier, but zero length, i.e. the “LINx Transmit Data Register LEN» is set to”0".