Try   HackMD

kSerial Protocol

封包開頭由 2-byte 起始字元“KS”開始,1-byte‘\r’結尾,封包內容包含封包型態(TP)、封包參數(PX)、封包校驗碼(CK)、資料(DN)以及資料長度(LN),封包的總長度不定,隨資料長度變化。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 封包型態(TP)
    由 4-bit 組成,分別為無號數、有號數、浮點數和保留指令四種,用來敘述封包的資料型態或是封包的功能、作用。
  • 資料長度(LN)
    由 12-bit 組成,敘述封包夾帶的資料長度,資料長度(LN)為零表示封包沒有夾帶資料,資料長度(LN)最大為 4095,這意味著封包的最大最小長度分別為 8-byte 以及 4103-byte。
  • 封包參數(P1, P2)
    由 2-byte 組成,保留給使用的的資料功能,用以增加封包應用的靈活性。
  • 封包校驗碼(CK)
    1-byte的校驗碼是用來確認封包資訊的正確性,CK=(TP*16+LN+P1+P2)%256
  • 資料(DN)
    封包的夾帶資料,長度與型態分別由 LN 和 TP 決定,其資料(DN)可以不隨封包傳送。

kSerial Packet Example

最小長度的封包格式

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

傳送 1 個 2 bytes 有號數 -22808(A6E8h) 的資料

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

傳送 3 個 2 bytes 有號數 -208, 73, -22808 (FF30h, 0049h, A6E8h)的資料

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

kSerial Packet R0 Command

R0 Command 是針對裝置(Target) 所提供的指令,主要用來設定裝置的系統參數

KSCMD_R0_DEVICE_BAUDRATE

設定裝置的傳輸鮑率指令,type=R0(8h), P1=KSCMD_R0_DEVICE_BAUDRATE(D1h), P2=04h, DN=BaudRate(32-bit),指令可以用來設定裝置的 UART 通訊鮑率,單位為 bps,裝置收到指令後會關掉 UART,並重新設定鮑率再啟動,設定完成後不會回傳訊息做應答

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

KSCMD_R0_DEVICE_RATE

設定裝置的更新頻率指令,type=R0(8h), P1=KSCMD_R0_DEVICE_RATE(D2h), P2=04h, DN=UpdateRate(32-bit),指令可以用來設定裝置的更新頻率,單位為 Hz,設定完成後不會回傳訊息做應答

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

KSCMD_R0_DEVICE_MDOE

設定裝置的運行模式指令,type=R0(8h), P1=KSCMD_R0_DEVICE_MDOE(D3h), P2=mode,指令可以用來設定裝置運行模式,MODE 0 預設為不執行任何程序,模式可依需求自行定義新增,設定完成後不會回傳訊息做應答

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

KSCMD_R0_DEVICE_ID

獲取裝置的 16-Bit ID 指令,type=R0(8h), P1=KSCMD_R0_DEVICE_ID(D0h), P2=00h,指令可以用來確認裝置是否有在線上,若裝置有收到指令則會回傳 16-bit ID

Host 發送指令 … Device Check

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Target 回傳 … Device ID

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

KSCMD_R0_DEVICE_GET

獲取裝置的資訊指令,type=R0(8h), P1=KSCMD_R0_DEVICE_GET(E3h), P2=KSCMD_R0_XXX 所定義的項目,指令可以用來獲取裝置上的設定,像是目前實現的鮑率、更新頻率、模式以及 ID,獲取的資訊都以 32-bit 來儲存,獲取 ID 則會回傳 32-bit ID

Host 發送指令 … Get Device Info

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Target 回傳 … Device Info

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

kSerial Packet R1 Command

R1 Command 是透過裝置(Target) 為媒介,對外部的 I2C 裝置(Device) 做讀寫的操作

I2C WRITE

I2C 寫指令,type=R1(Ch), P1=8-Bit SlaveAddress, P2=RegAddress, DN=WriteData

Host 發送指令 … I2C Single Write

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Host 發送指令 … I2C Multiple Write

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

I2C READ

I2C 讀指令,type=R1(Ch), P1=(slaveAddress<<1) | 0x01, P2=regAddress, DN=ReadLength

Host 發送指令 … I2C Single Read

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Target 回傳 … I2C Single Read Data

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Host 發送指令 … I2C Multiple Read

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Target 回傳 … I2C Multiple Read Data

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

kSerial Packet R2 Command

R2 Command 為 R1 Command 的擴充指令集,針對外部的 I2C 裝置(Device) 做進一步的應用

KSCMD_R2_TWI_SCAN_DEVICE

掃描 I2C 裝置地址,type=R2(Dh), P1=KSCMD_R2_TWI_SCAN_DEVICE(A1h), P2=00h,掃描裝置上的 I2C 裝置地址,回傳的封包長度依實際存在的 I2C 裝置數目而改變

Host 發送指令 … I2C Scan Device

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Target 回傳 … I2C Scan Address

KSCMD_R2_TWI_SCAN_REGISTER

掃描 I2C 裝置暫存器數值,type=R2(Dh), P1=KSCMD_R2_TWI_SCAN_REGISTER(A2h), P2=8-bit address,回傳指定地址的 I2C 裝置上的暫存器全部 256 bytes 數值

Host 發送指令 … I2C Scan Device Register

Target 回傳 … I2C Scan Device Register Data

kSerial Packet R3, R4 Command

此指令並無特別定義,可以自行使用