CANopen LSS服务协议(CiA DSP-305 V1.0)

概述

CANopen Layer Setting Services(LSS,层次设置服务)规范,用于在CAN网络中远程配置从站设备的层参数(节点ID、波特率、LSS地址)。

核心概念

LSS Master 与 LSS Slave

  • LSS Master:网络中唯一,负责配置其他设备
  • LSS Slave:数量不限,被Master配置
  • 所有设备必须处于STOP状态才能使用LSS

LSS地址结构

<LSS-ADDRESS> ::= <vendor-id><product-code><revision-number><serial-number>
  • vendor-id:由CiA分配给供应商
  • product-code、revision-number、serial-number:由供应商分配
  • LSS地址等同于CANopen Identity Object(Index 1018H)

LSS模式

  • Configuration Mode:所有LSS服务可用
  • Operation Mode:只有Switch Mode服务可用

LSS服务分类

1. Switch Mode Services(切换模式服务)

Switch Mode Global(全局切换)

  • 命令码:cs = 0x04
  • COB-ID:2021(请求)/ 2020(响应)
  • 参数:mode(0=operation, 1=configuration)
  • 作用:将所有LSS Slave切换到指定模式

Switch Mode Selective(选择切换)

  • 命令码:cs = 0x64~0x68
  • 逐字节发送LSS地址(vendor-id, product-code, revision-number, serial-number)
  • 仅切换匹配的单个从站

2. Configuration Services(配置服务)

Configure Node-ID(配置节点ID)

  • 命令码:cs = 0x17
  • 参数:Node-ID
  • 错误码:0=成功, 1=超出范围

Configure Bit Timing Parameters(配置位时序参数)

  • 命令码:cs = 0x19
  • table_selector:0=标准CiA表
  • table_index:选择波特率条目

标准CiA波特率表:

波特率Table_Index
1000 kBit0
800 kBit1
500 kBit2
250 kBit3
125 kBit4
100 kBit5
50 kBit6
20 kBit7
10 kBit8

Activate Bit Timing Parameters(激活位时序)

  • 命令码:cs = 0x21
  • switch_delay:切换延迟时间(毫秒),必须大于网络中最长处理时间

Store Configured Parameters(存储配置)

  • 命令码:cs = 0x23
  • 将配置写入非易失性存储

3. Inquiry Services(查询服务)

Inquire LSS Address(查询LSS地址)

  • 命令码:cs = 0x5A~0x5D
  • 分四次查询:vendor-id, product-code, revision-number, serial-number
  • COB-ID:2020响应

4. Identification Services(识别服务)

LSS Identify Remote Slaves

  • 命令码:cs = 0x70~0x75
  • 指定vendor-id、product-code和serial-number范围
  • 匹配的从站通过cs=0x79响应

协议细节

COB-ID分配

  • 请求消息(Master→Slave):COB-ID = 2021h
  • 响应消息(Slave→Master):COB-ID = 2020h

命令码分配

  • 0x00~0x3F:LMT服务保留
  • 0x40~0x7F:标准LSS服务保留
  • 0x80~0xFF:厂商自定义

数据格式

  • 字节编号0~7,0先发
  • 位编号0~7,0为LSB
  • lsb/msb表示多字节整数顺序

实现规则

  1. 同步机制:同一时间只能有一个Slave与Master通信
  2. 无效COB处理:忽略非法COB,本地处理
  3. 超时处理:超时不是LSS服务的确认,需应用层处理
  4. 波特率切换:必须使用switch_delay确保所有节点完成切换

应用场景

  • 生产线终端设备自动配置
  • 现场总线系统维护时远程修改节点参数
  • 批量生产时统一设置设备地址和波特率

关联文档