Cov txheej txheem:

Ua SAMD21-based Boards USB Port Into a Hardware Serial Port !: 3 Cov Kauj Ruam
Ua SAMD21-based Boards USB Port Into a Hardware Serial Port !: 3 Cov Kauj Ruam

Video: Ua SAMD21-based Boards USB Port Into a Hardware Serial Port !: 3 Cov Kauj Ruam

Video: Ua SAMD21-based Boards USB Port Into a Hardware Serial Port !: 3 Cov Kauj Ruam
Video: Add USB To Your Electronics Projects! - The USB Protocol Explained 2024, Kaum ib hlis
Anonim
Image
Image
Tsim Serial Device Nrog USB Txuas
Tsim Serial Device Nrog USB Txuas

Nws yog tus txheej txheem niaj hnub no los siv Arduino (lossis lwm yam sib xws) pawg thawj coj saib USB chaw nres nkoj raws li qhov chaw nyob. Qhov no muaj txiaj ntsig zoo rau kev debugging, xa thiab txais cov ntaub ntawv los ntawm peb cov laug cam ntxim nyiam.

Kuv tau ua haujlwm ntawm uChipwhen, dhau los ntawm cov ntaub ntawv ntawm nws MCU (SAMD21), Kuv pom tias USB gpio PORTA 24 thiab 25 (uas yog D-/D+ feem) kuj tseem tuaj yeem siv ua SERCOM (PAD 2 thiab 3).

Tom qab pom qhov no hauv cov ntawv teev npe, kuv xav tias nws yuav muaj txiaj ntsig zoo qee zaum los txuas cov cuab yeej khoos phis tawj txuas ncaj qha rau ntawm USB chaw nres nkoj ntau dua los ntawm kev txuas cov xov hlau ya mus rau ntawm lub khob cij los yog muab nws ncaj qha rau ntawm lub rooj tsavxwm.

Yog li, ntawm no nws yog kev qhia nrawm qhia koj yuav ua li cas teeb tsa koj lub rooj tsav xwm xws li koj tuaj yeem siv nws USB ua lub khoos phis tawj Serial chaw nres nkoj.

Hauv qhov kev qhia tshwj xeeb no, cov khoom siv txuas nrog yog Bluetooth HC-06 txuas txuas txuas. Txawm li cas los xij, koj tuaj yeem hloov kho cov cai rau lwm yam khoom siv hauv xov tooj cua, tsuav koj siv lub tshuab txuas USB txuas rau cov khoom siv.

Cov nqi khoom

ucxwb 1

micro-USB rau USB/A adapter x 1 (txuas)

HC-06 BT module x 1

Recycled USB cable x 1

Roj teeb (3V3 <VBAT <5) x 1

Kauj ruam 1: Tsim Serial Device Nrog USB Txuas

Tua tawm lub USB cable thiab txuas nws cov xov hlau mus rau Serial ntaus ntawv raws li qhia hauv kab lus thiab sau hauv qab no.

- USB cable dub -> GND

- USB cable liab -> VCC (Lub Hwj Chim)

-USB cable (D-) dawb -> RX

- USB cable (D+) ntsuab -> TX

Kauj ruam 2: Program UChip

Program UChip
Program UChip

Txuas uChipto koj lub computer thiab thauj cov duab "HWSerialUSB.ino" rau hauv lub rooj tsavxwm. Tom qab ntawd, tshem tawm uChip txuas ntxiv nrog cov kauj ruam tom ntej.

TSWV YIM: Txoj cai ua haujlwm li cas? Vim li cas kuv USB chaw nres nkoj sib txawv tam sim no?

Nov yog piav qhia ntxaws txog qhov ua kom yuam kev uas kuv tab tom ua hauv txoj cai.

Yeej, Kuv tab tom tsim qhov tshiab "SerialUSB_HW" piv txwv siv GPIO uas tam sim no tau ua haujlwm ua D- thiab D+.

Hauv Teeb () Kuv ua kom muaj kev ua haujlwm SERCOM rau USB pins, siv cov haujlwm "pinPeripherial ()" muab rau hauv "wiring_private.h" header suav nrog thaum pib ntawm txoj cai.

Tam sim no, Kuv tuaj yeem siv "SerialUSB_HW" piv txwv li tus qauv Serial lossis SerialUSB, tau txais thiab xa cov ntaub ntawv rau kuv HC-06 cov khoom siv.

Kauj Ruam 3: Sib sau ua ke - Txuas - Kev sim

Sib dhos - Txuas - Kev sim
Sib dhos - Txuas - Kev sim

Txuas lub roj teeb rau uChip

-pin_8-> VBAT--

- pin_16 -> VBAT+

Ntxig lub OTG adapter thiab tom qab ntawd Serial ntaus nrog nws hom tshiab USB chaw nres nkoj thiab … qhov ntawd yog txhua yam, kho vajtse tau npaj txhij!

Tom qab ua ke nrog HC-06 module (tus lej cim tus lej yog 1234), txuas rau BT lub cuab yeej siv koj lub xov tooj lossis BT interface. Tam sim no koj yuav tsum tau txais cov xwm txheej ntawm on-board LED.

Xa tus char 'o' los qhib lub LED, lossis lwm yam char kom tua nws.

Sim thiab sim lwm cov khoom siv. Tam sim no koj paub yuav siv USB chaw nres nkoj li Hardware Serial chaw nres nkoj!

TSWV YIM: Muaj #define hauv txoj cai, uas tso cai rau koj hloov pauv ntawm kev siv lub USB chaw nres nkoj li Emulated serial lossis raws li Hardware serial. Kev sim thiab txheeb xyuas tias Serial device txuas (HC-06) tsis sib txuas lus tshwj tsis yog tias peb yuam kom USB ua haujlwm li Hardware serial!

Pom zoo: