# CAN FD Protocal

```cpp
// Commands Description:
struct ucan_command {
  uint16_t  opcode_channel;
  uint16_t  args[3];
}

Command=opcode_channel & 0x3ff
Channel=opcode_channel >> 12

Commands Define as below：
1,UCAN_CMD_RESET_MODE :0x001
//no args needed.
2,UCAN_CMD_NORMAL_MODE:0x002
//no args needed.
3,UCAN_CMD_LISTEN_ONLY_MODE: 0x003
//no args needed.
4,UCAN_CMD_TIMING_SLOW:0x004
Uint16_t args[3] define:   //bitrate setting
  uint8_t  ewl;    /* Error Warning limit */
  uint8_t  sjw_t;    /* Sync Jump Width + Triple sampling */
  uint8_t  tseg2;    /* Timing SEGment 2 */
  uint8_t  tseg1;    /* Timing SEGment 1 */
  uint16_t  brp;    /* BaudRate Prescaler */
5,UCAN_CMD_TIMING_FAST: 0x005  //FD bitrate setting
Uint16_t args[3] define:
  uint8_t  unused;
  uint8_t  sjw;    /* Sync Jump Width */
  uint8_t  tseg2;    /* Timing SEGment 2 */
  uint8_t  tseg1;    /* Timing SEGment 1 */
  uint16_t  brp;    /* BaudRate Prescaler */
6,UCAN_USB_CMD_CLK_SET:0x80
Uint16_t args[3] define:
uint8_t mode;
uint8_t unused[5];
mode value define:
0x00:80MHZ
0x01:60MHZ
0x02:40MHZ
0x03:30MHZ
0x04:24MHZ
0x05:20MHZ

7,UCAN_USB_CMD_DEVID_SET:0x81
Uint16_t args[3] define:

uint16_t unused;
    uint32_t device_id;

8,UCAN_CMD_END_OF_COLLECTION: 0x3ff
//no args needed.

Command package format:
Command1+command2+command3+………+UCAN_CMD_END_OF_COLLECTION command

Command data packets was send by bulk endpoint 0x01.


Device Receive can frames:
struct ucan_rx_msg {
  uint16_t  size;
  uint16_t  type;
  uint32_t  ts_low;
  uint32_t  ts_high;
  uint32_t  tag_low;
  uint32_t  tag_high;
  uint8_t  channel_dlc;
  uint8_t  client;
  uint16_t  flags;
  uint32_t  can_id;
  uint8_t  d[];
}
USB packet buffer : ucan_rx_msg1+ucan_rx_msg2+…ucan_rx_msgn+0x000000
Device Send to usb host through USB bulk in endpoint 0x82

Device Send can frames:

Ch1 : USB BULKOUT :0X02
CH2 : USB BULKOUT :0X03

USB Buffer contents:
struct ucan_tx_msg {
  uint16_t  size;
  uint16_t  type;
  uint32_t  tag_low;
  uint32_t  tag_high;
  uint8_t  channel_dlc;
  uint8_t  client;
  uint16_t  flags;
  uint32_t  can_id;
  uint8_t  d[];
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.123buyelectronic.com/home/user-manual/can-fd-protocal.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
