[低價USB DAQ卡計畫] Microchip c18: USBGenWrite()與USBGenRead()
在USB 資料Packet的傳輸中,
有兩個函數會被使用到, 分別是USBGenWrite()與USBGenRead(),
我們從help檔中分別來看這兩個函數,
- 首先是USBGenWrite(),
裡面要注意兩個變數 : data與len,
data 是只要傳送的資料內容, 由Byte陣列構成 , 而len是指要傳送的陣列長度,
C
1 | #define USBGenWrite(ep,data,len) USBTxOnePacket(ep,data,len) |
Description
This function sends the specified data out the specified endpoint and returns a handle to the transfer information.
Typical Usage:
1 | //make sure that the last transfer isn't busy by checking the handle |
Preconditions
None
Parameters
| Parameters | Description |
| ep | the endpoint you want to send the data out of |
| data | pointer to the data that you wish to send |
| len | the length of the data that you wish to send |
Return Values
| Return Values | Description |
| USB_HANDLE | a handle for the transfer. This information should be kept to track the status of the transfer |
- 再來是 USBGenRead() , 變數與USBGenWrite()大同小異,
注意的是:
USBGenWrite()的data使用INPacket, 而USBGenRead()使用是OUTPacket, 資料長度為64 byte.
C
1 | #define USBGenRead(ep,data,len) USBRxOnePacket(ep,data,len) |
Description
Receives the specified data out the specified endpoint.
Typical Usage:
1 | //Read 64-bytes from endpoint USBGEN_EP_NUM, into the OUTPacket array. |
Preconditions
None
Parameters
| Parameters | Description |
| ep | the endpoint you want to receive the data into |
| data | pointer to where the data will go when it arrives |
| len | the length of the data that you wish to receive |
Return Values
| Return Values | Description |
| USB_HANDLE | a handle for the transfer. This information should be kept to track the status of the transfer |
USBGenWrite()與USBGenRead()的使用方式套用上述說明中範例程式中的code即可.
本部落格所有文章除特別聲明外,均採用CC BY-NC-SA 4.0 授權協議。轉載請註明來源 X Workshop|量測自動化 × 嵌入式 × AI 開發實戰!