Cov txheej txheem:

STM32 CAN Interface: 7 Kauj Ruam
STM32 CAN Interface: 7 Kauj Ruam

Video: STM32 CAN Interface: 7 Kauj Ruam

Video: STM32 CAN Interface: 7 Kauj Ruam
Video: FDCAN in STM32 || Normal Mode || Message RAM Configuration 2024, Kaum ib hlis
Anonim
STM32 CAN Interface
STM32 CAN Interface

Cov Chaw Thauj Khoom Hauv Cheeb Tsam Network npav, lossis CAN npav, yog cov txheej txheem kev sib txuas lus tau zoo heev ua tsaug rau nws lub peev xwm ceev, muaj kev ntseeg tau ntev, thiab tiv thaiv lub suab nrov. Vim li no, CAN kev sib txuas lus tau dhau los ua tus qauv hauv kev siv tsheb thiab cov suab nrov ib puag ncig. Cov cuab yeej ntawm CAN npav hu ua nodes. Txhua qhov ntawm CAN lub tsheb npav tau txuas nrog ua ke, txhais tau tias txhua lub node txuas nrog rau txhua lwm qhov ntawm lub network. Ib lub npav CAN ib leeg tuaj yeem muaj txog 115 nodes ntawm ib zaug, nyob ntawm tus nqi ntawm kev xa xov, tab sis rau feem ntau daim ntawv thov, nws raug pom zoo kom muaj txog li 32 lub cuab yeej. Nws kuj tseem pom zoo kom khaws qhov ntev nruab nrab ntawm thawj thiab qhov kawg tsawg dua 40 meters sib nrug.

Cov lus qhia ib kauj ruam-ib-kauj ruam no yuav qhia koj yuav teeb tsa CAN node siv STM32 microcontroller li cas, suav nrog cov Circuit thiab yooj yim C code nyeem thiab sau rau CAN npav

Khoom siv

Rau txhua CAN ntawm:

  • 1x STM32 breakout board (Nucleo, Blue Pill, lwm tus)
  • 1x MCP2551 CAN transceiver IC
  • 1x 0.1µF capacitor
  • 1 x 120Ω resistor
  • 1 x 1 kΩ resistor
  • 1+ nyeem tau cov tswv yim (khawm, hloov, lub zog, thiab lwm yam) lossis cov zis (LED, MOSFET, thiab lwm yam)
  • 1x Dsub9 txuas

Kauj Ruam 1: Lub Transceiver Circuit

Transceiver Circuit
Transceiver Circuit

Txhawm rau tham nrog CAN npav, peb yuav siv MCP2551 CAN transceiver IC. IC ua raws li tus neeg xa xov nruab nrab/tus xa xov txuas txuas STM32 mus rau CAN npav. Lub Circuit Court los teeb tsa IC no yooj yim heev, tab sis muaj qee yam yuav tsum nco ntsoov:

  • CAN_RX (tus pin 4) thiab CAN_TX (tus pin 1) ntawm MCP2551 nti tuaj yeem tsuas yog mus rau qee tus pin ntawm STM32.

    • Ntawm STM32F1 Nucleo, txuas kab RX rau tus pin PB8 thiab TX kab rau tus pin PB9.
    • Ntawm STM32F1 cov ntsiav tshuaj xiav, txuas RX rau tus pin PA11 thiab TX rau tus pin PA12.
    • Nco ntsoov tias cov haujlwm pin no muaj lwm txoj hauv kev. Xa mus rau microcontroller phau ntawv qhia txhawm rau txiav txim siab tias tus pin twg muaj peev xwm CAN_RD thiab CAN_TD
    • Yog tias siv Arduino lossis pawg thawj coj tsis muaj CAN tus neeg sib txuas lus tau tsim, MCP2515 IC nti yuav xav tau los hloov lwm cov kev cai xov xwm rau CAN.
  • CANL tus pin yuav tsum txuas nrog rau lwm tus CANL tus pin ntawm lwm lub tsheb npav. Tib yam mus rau CANH pins.
  • 120Ω resistor hla CANH thiab CANL pins tsuas yog xav tau yog tias lub node yog lub davhlau ya nyob twg. Qhov no txhais tau tias nws yog qhov kawg ntawm kev txuas txuas txuas txuas. Hauv lwm lo lus, CAN lub tsheb npav yuav tsum muaj ob lub 120Ω resistors nyob rau hauv nws, thiab lawv yuav tsum nyob deb ntawm ib leeg ib leeg li qhov ua tau.
  • Thaum kawg, 1kΩ resistor ntawm RS (tus pin 8) tuaj yeem sib pauv rau 10kΩ resistor los tswj lub sijhawm nce/poob ntawm CAN cov lus xov. Xa mus rau MCP2551 nti daim ntawv qhia kom ntxaws.

Kauj Ruam 2: Nyeem Ntawv thiab Sau Ntawv mus rau CAN Bus

Nyeem thiab Sau Ntawv mus rau CAN Bus
Nyeem thiab Sau Ntawv mus rau CAN Bus

Tam sim no qhov kev xa xov hluav taws xob txuas nrog STM32, peb tuaj yeem pib sau ntawv mus rau CAN npav. Phau ntawv qhia no yuav tsis nkag mus tob rau hauv STM32 cov cai. Txawm li cas los xij, nco ntsoov txheeb xyuas peb cov cai rau piv txwv ntawm no. Siv STM32 ua CAN node yuav xav tau CAN header file. Peb tau sau peb tus kheej, uas tuaj yeem pom ntawm peb github ntawm no. Ntawm no, peb yuav muab cov lus luv luv ntawm cov txheej txheem nyeem/sau.

Txhawm rau nyeem los ntawm CAN npav, peb yuav tsum xub paub tus lej ntawm CAN cov lus. Txhua cov lus yuav tsum muaj tus lej tshwj xeeb, nrog tus lej qis dua muaj qhov muaj feem thib siab dua. Cov lej code qhia ntawm no yog tos CAN cov lus nrog ID 0x622. Hauv peb cov kab ke, yog thawj zaug ntawm 6 byte siab, ces peb xav teeb tus pin A10 siab.

Thaum sau CAN cov lus, peb yuav tsum nco ntsoov tias CAN cov lus yog ntau-byte. Txhua daim ntawv sau yuav tsum muaj tus lej ID thiab qhov ntev. Hauv daim ntawv qhia thib ob ntawm cov cai pom, peb sau cov ntaub ntawv rau txhua byte, tom qab ntawd xa cov lus (Tus lej thiab tus lej tsis ntev tau hais tseg ua ntej hauv tus lej).

Kauj Ruam 3: Txuas Cov Nodes

Kev Sib Txuas
Kev Sib Txuas

Thaum txuas ntau CAN nodes, ua tib zoo saib xyuas yuav tsum tau them rau qhov ntev ntawm cov xov hlau. Ob txoj kab nyob deb tshaj plaws tuaj yeem mus txog 40m sib nrug ntawm ib leeg. Cov nodes nruab nrab txuas rau lub tsheb npav yuav tsum tsis pub dhau 50cm ntawm txoj kab npav loj.

CAN kev sib txuas ua raws txheej txheem kev lag luam ntawm kev siv Dsub9 txuas nrog CANL kab ntawm tus pin 2 thiab CANH kab ntawm tus pin7. Qhov kev xaiv CANGND kab tuaj yeem mus rau tus pin 3.

Kauj Ruam 4: Ua PCB

Ua PCB
Ua PCB

Thaum khiav CAN cov cim ntawm PCB, nco ntsoov tias CAN yog qhov sib txawv ntawm lub teeb liab, thiab yog li, kev qhia cov txheej txheem rau CANH thiab CANL yuav tsum tau ua tib zoo.

Kauj Ruam 5: Nthuav Tawm Pawg Thawj Coj

Nthuav tawm Pawg Thawj Coj
Nthuav tawm Pawg Thawj Coj

Pov qee qhov ntxiv ua ke, ntxiv qee qhov nkag/tawm, thiab txuas tag nrho lawv cov CANH thiab CANL pins. Nco tseg tias txhua tus STM32 lossis lwm lub microcontroller xav tau nws tus kheej MCP2551 nti; lawv tsis tuaj yeem sib qhia.

Nrog qhov hais tias, sim ua kom koj cov PCBs me dua li qhov tau qhia ntawm no

Kauj Ruam 6: Txiav Koj Cov PCBs Los Ntawm JLCPCB

Xaj koj cov PCBs los ntawm JLCPCB
Xaj koj cov PCBs los ntawm JLCPCB

JLCPCB muab kev pabcuam sai, ua haujlwm tau zoo ntawm tus nqi tsim nyog. Tau txais 5 cov laug cam, xim twg nrog ntau qhov kev hloov pauv, tsuas yog $ 2! Thiab yog tias nws yog koj thawj qhov kev xaj, tau txais 10 daim txiag rau tus nqi zoo ib yam!

Tsuas yog rub koj cov gerbers thiab tau txais nqe lus tam sim! Xa koj daim ntawv xaj thiab koj cov laug cam yuav tshuaj xyuas rau kev tsim khoom hauv ib teev. Thaum koj them nyiaj, koj tuaj yeem cia siab tias koj cov laug cam zoo hauv sai li peb hnub!

Txheeb nws tawm ntawm no

Kauj Ruam 7: Tau Koj Cov Phiaj Xwm

Tau Koj Cov Ntsiab Lus!
Tau Koj Cov Ntsiab Lus!

Hu nrov nrov rau JLCPCB rau kev txhawb nqa txoj haujlwm no. JLCPCB (ShenzhenJLC Electronics Co., Ltd.), yog lub tuam txhab PCB loj tshaj plaws hauv Suav teb thiab cov chaw tsim khoom lag luam tshwj xeeb tshwj xeeb hauv PCB sai prototyping thiab cov khoom me me PCB tsim. Lawv tau ua siab zoo muab UBC Hnub Ci nrog peb cov PCBs tshiab rau peb lub tsheb sib tw uas siv hnub ci. Peb tau tso peb daim ntawv xaj rau hnub Friday thiab tau txais cov laug cam rau hnub Wednesday!

Pom zoo: