Cov txheej txheem:

CAN raws tu qauv - Yog, Peb Ua Tau!: 24 Kauj Ruam
CAN raws tu qauv - Yog, Peb Ua Tau!: 24 Kauj Ruam

Video: CAN raws tu qauv - Yog, Peb Ua Tau!: 24 Kauj Ruam

Video: CAN raws tu qauv - Yog, Peb Ua Tau!: 24 Kauj Ruam
Video: Plab Plab Ntswg..(Pluav Pluav Ntswg) Maiv Twm New Song 2023-2024 2024, Kaum ib hlis
Anonim
Image
Image
Cov peev txheej siv
Cov peev txheej siv

Lwm qhov kev qhia tsis ntev los no tau qhia los ntawm kuv tus YouTube channel cov thwjtim yog CAN (Tus Saib Xyuas Cheeb Tsam Network) raws tu qauv, uas yog yam peb yuav tsom mus rau niaj hnub no. Nws yog ib qho tseem ceeb los piav qhia tias CAN yog cov txheej txheem kev sib txuas lus ib txhij. Qhov no txhais tau tias kev sib koom ua ke ntawm cov qauv txuas nrog lub network tau ua tiav hauv kev sib piv rau qhov pib ntawm txhua cov lus xa mus rau lub npav. Peb yuav pib los ntawm kev qhia cov ntsiab lus yooj yim ntawm CAN raws tu qauv thiab ua qhov kev sib dhos yooj yim nrog ob ESP32s.

Hauv peb qhov kev sib tham, ESPs tuaj yeem ua tus tswv thiab tus qhev. Koj tuaj yeem muaj ntau lub microcontrollers xa ib txhij, vim tias CAN cuam tshuam nrog kev sib tsoo ntawm txhua yam cia li. Qhov chaws ntawm txoj haujlwm no yooj yim heev. Txheeb nws tawm!

Kauj Ruam 1: Cov Khoom Siv

  • Ob qhov qauv ntawm ESP WROOM 32 NodeMcu
  • Ob CAN transceivers los ntawm WaveShare
  • Jumpers rau kev sib txuas
  • Logical analyzer rau kev ntes
  • Peb USB cables rau ESPs thiab tshuaj ntsuam xyuas
  • 10 meters ntawm txoj hlua sib tw los ua tsheb npav

Kauj Ruam 2: YUAV (Network Cheeb Tsam Network)

CAN (Network Cheeb Tsam Network)
CAN (Network Cheeb Tsam Network)
  • Nws tau tsim los ntawm Robert Bosch GmbH hauv xyoo 1980 los pab rau kev lag luam tsheb.
  • Nws tau dhau los ntau xyoo nyob rau xyoo vim nws muaj zog thiab yooj ntawm kev siv. Nws tau siv nrog cov cuab yeej siv tub rog, tshuab ua liaj ua teb, kev tsim khoom thiab kev tsim kho tshuab, neeg hlau, thiab khoom siv kho mob.

Kauj Ruam 3: CAN - Cov yam ntxwv

CAN - Cov yam ntxwv
CAN - Cov yam ntxwv
CAN - Cov yam ntxwv
CAN - Cov yam ntxwv
  • Ob-xaim xov tooj sib txuas lus
  • Qhov siab tshaj ntawm 8 bytes ntawm cov ntaub ntawv muaj txiaj ntsig ntawm ib tus ncej, nrog kev faib ua tau
  • Chaw nyob qhia rau cov lus thiab tsis yog rau ntawm
  • Muab lub luag haujlwm tseem ceeb rau cov lus thiab xa tawm ntawm "tuav" cov lus
  • Muaj peev xwm siv tau los txheeb xyuas thiab teeb liab tsis raug
  • Muaj peev xwm ua tau ntau tus tswv (txhua lub hauv paus tuaj yeem thov nkag npav)
  • Muaj peev xwm ua tau ntau yam (ib nqe lus rau ntau tus neeg tau txais tib lub sijhawm)
  • Hloov tus nqi nce txog 1Mbit / s ntawm lub npav 40-meter (txo tus nqi nrog nce ntawm qhov ntev busbar)
  • Kev hloov pauv yooj yim ntawm kev teeb tsa thiab qhia txog cov nodes tshiab (txog 120 nodes ntawm ib lub npav)
  • Cov cuab yeej txheem, tus nqi qis, thiab muaj khoom zoo
  • Cov txheej txheem tswj hwm: ISO 11898

Kauj Ruam 4: Siv Circuit

Siv Circuit Court
Siv Circuit Court

Ntawm no, Kuv muaj Transceivers. Muaj ib qho ntawm txhua sab, thiab lawv tau txuas nrog ob kab xov hlau. Ib tus yog lub luag haujlwm xa thiab lwm tus tau txais cov ntaub ntawv.

Kauj Ruam 5: Cov Kab Xa Kab Voltages (Kev Tshawb Fawb Sib Txawv)

Kev Xa Kab Kab Voltages (Kev Tshawb Fawb Sib Txawv)
Kev Xa Kab Kab Voltages (Kev Tshawb Fawb Sib Txawv)

Hauv CAN, qhov tseem ceeb yog Zero.

Kev Tshawb Nrhiav Kab Sib Txawv Ua Ntej Ua Ntej Tsis hnov suab (EFI)

Kauj Ruam 6: CAN Cov Qauv thiab Cov Qauv Txheej Txheem

CAN Cov Qauv thiab Cov Qauv Txheej Txheem
CAN Cov Qauv thiab Cov Qauv Txheej Txheem

Cov qauv txheem nrog 11-ntsis tus cim

Kauj Ruam 7: CAN Cov Qauv thiab Cov Qauv Txheej Txheem

CAN Cov Qauv thiab Cov Qauv Txheej Txheem
CAN Cov Qauv thiab Cov Qauv Txheej Txheem

Cov ntawv txuas ntxiv nrog tus lej 29-ntsis

Kauj Ruam 8: CAN Cov Qauv thiab Cov Qauv Txheej Txheem

Nws yog ib qho tseem ceeb kom nco ntsoov tias cov txheej txheem twb tau laij tawm CRC thiab xa ACK thiab EOF cov cim, uas yog yam uas twb tau ua tiav los ntawm CAN raws tu qauv. Qhov no lav paub tias cov lus xa mus yuav tsis tuaj txog qhov tsis raug. Qhov no vim tias yog nws muab teeb meem hauv CRC (Redundant Cyclic Check lossis Redundancy Check), uas yog tib yam li cov ntaub ntawv tshawb xyuas tus lej, nws yuav raug txheeb xyuas los ntawm CRC.

Kauj Ruam 9: Plaub Hom Ntoo (thav duab)

Plaub Hom Ntas (thav duab)
Plaub Hom Ntas (thav duab)

Nws yog ib qho tseem ceeb kom nco ntsoov tias cov txheej txheem twb tau laij tawm CRC thiab xa ACK thiab EOF cov cim, uas yog yam uas twb tau ua tiav los ntawm CAN raws tu qauv. Qhov no lav paub tias cov lus xa mus yuav tsis tuaj txog qhov tsis raug. Qhov no vim tias yog nws muab teeb meem hauv CRC (Redundant Cyclic Check lossis Redundancy Check), uas yog tib yam li cov ntaub ntawv tshawb xyuas tus lej, nws yuav raug txheeb xyuas los ntawm CRC.

Plaub hom thav duab (thav duab)

Kev xa thiab txais cov ntaub ntawv hauv CAN yog ua raws plaub hom kev thav duab. Cov hom kab yuav raug txheeb xyuas los ntawm kev hloov pauv hauv cov khoom tswj lossis txawm tias hloov pauv los ntawm cov txheej txheem sau kab lus rau txhua kis.

  • Cov Ntaub Ntawv: Muaj cov ntaub ntawv xa mus rau tus txais (s)
  • Cov Chaw Taws Teeb: Qhov no yog thov rau cov ntaub ntawv los ntawm ib qho ntawm cov nodes
  • Kev Ua Yuam Kev Tsis Zoo: Nws yog kab ntawv xa los ntawm ib qho ntawm cov nodes thaum txheeb xyuas qhov ua yuam kev hauv lub tsheb npav thiab tuaj yeem kuaj pom los ntawm txhua lub hauv paus
  • Overload Frame: Ua haujlwm kom qeeb tsheb ntawm lub npav vim cov ntaub ntawv hla dhau lossis ncua ntawm ib lossis ntau qhov ntawm.

Kauj Ruam 10: Circuit - Cov ntsiab lus ntawm Kev Sib Txuas

Circuit - Cov ntsiab lus ntawm Kev Sib Txuas
Circuit - Cov ntsiab lus ntawm Kev Sib Txuas

Kauj Ruam 11: Circuit -Capture Data

Circuit - Kev ntes cov ntaub ntawv
Circuit - Kev ntes cov ntaub ntawv

Wavelengths tau txais rau tus qauv CAN nrog 11-ntsis ID

Kauj Ruam 12: Circuit -Capture Data

Circuit - Kev ntes cov ntaub ntawv
Circuit - Kev ntes cov ntaub ntawv

Wavelengths tau txais rau ncua CAN nrog 29-ntsis ID

Kauj Ruam 13: Circuit -Capture Data

Circuit - Kev ntes cov ntaub ntawv
Circuit - Kev ntes cov ntaub ntawv

Cov ntaub ntawv tau los ntawm tus kws tshuaj xyuas cov laj thawj

Kauj Ruam 14: Arduino Library - CAN

Arduino Library - YOG
Arduino Library - YOG

Kuv qhia ntawm no ob qhov kev xaiv uas koj tuaj yeem nruab CAN Driver Library

Arduino IDE Tus Thawj Saib Xyuas Tsev Qiv Ntawv

Kauj ruam 15: Github

Github
Github

github.com/sandeepmistry/arduino-CAN

Kauj Ruam 16: Tus Kws Tshaj Lij Tshaj Tawm

Source Code: suav nrog thiab teeb tsa ()

Peb yuav suav nrog CAN lub tsev qiv ntawv, pib ua ntu zus rau kev debugging, thiab pib CAN npav ntawm 500 kbps.

#include // Inclui a biblioteca CAN void setup () {Serial.begin (9600); // inicia serial para debug thaum (! Serial); Serial.println ("Transmissor CAN"); // Inicia o barramento CAN a 500 kbps if (! CAN.begin (500E3)) {Serial.println ("Falha ao iniciar o controlador CAN"); // caso não seja possível iniciar o controlador thaum (1); }}

Kauj Ruam 17: Cov Cai Code: Loop (), Xa Tus Qauv CAN 2.0 Pob

Siv tus qauv CAN 2.0, peb xa pob khoom. Tus lej 11-ntsis qhia tus lej. Cov ntaub ntawv thaiv yuav tsum muaj txog 8 bytes. Nws pib pob nrog ID 18 hauv hexadecimal. Nws ntim 5 bytes thiab kaw qhov haujlwm.

void loop () {// Usando o CAN 2.0 padrão // Envia um pacote: o id tem 11 bits e identifica a mensagem (prioridade, evento) // o bloco de dados deve possuir até 8 bytes Serial.println ("Enviando pacote … "); CAN.beginPacket (0x12); // id 18 em hexadecimal CAN.write ('h'); // 1º byte CAN.write ('e'); // 2º byte CAN.write ('l'); // 3º byte CAN.write ('l'); // 4º byte CAN.write ('o'); // 5º byte CAN.endPacket (); // encerra o pacote para envio Serial.println ("Enviado."); ncua (1000);

Kauj Ruam 18: Cov Cai Code: Loop (), Xa Cov Ncua Ntev CAN 2.0 Pob

Hauv qib no, tus lej ID muaj 29 qhov. Nws pib xa 24 ntsis ntawm tus lej ID thiab, ib zaug ntxiv, ntim 5 bytes thiab txiav tawm.

// Usando CAN 2.0 Estendido // Envia um pacote: o id tem 29 bits e identifica a mensagem (prioridade, evento) // o bloco de dados deve possuir até 8 bytes Serial.println ("Enviando pacote estendido …"); CAN.beginExtendedPacket (0xabcdef); // id 11259375 decimal (abcdef em hexa) = 24 khoom preenchidos até aqui CAN.write ('w'); // 1º byte CAN.write ('o'); // 2º byte CAN.write ('r'); // 3º byte CAN.write ('l'); // 4º byte CAN.write ('d'); // 5º byte CAN.endPacket (); // encerra o pacote para envio Serial.println ("Enviado."); ncua (1000); }

Kauj Ruam 19: Tus Neeg Tau Txais Cov Cai

Source Code: suav nrog thiab teeb tsa ()

Ib zaug ntxiv, peb yuav suav nrog CAN lub tsev qiv ntawv, pib ua ntu zus kom debug, thiab pib CAN npav ntawm 500 kbps. Yog tias muaj qhov ua yuam kev, qhov yuam kev no yuav luam tawm.

#include // Inclui a biblioteca CAN void setup () {Serial.begin (9600); // inicia a serial para debug thaum (! Serial); Serial.println ("Txais CAN"); // Inicia o barramento CAN a 500 kbps if (! CAN.begin (500E3)) {Serial.println ("Falha ao iniciar o controlador CAN"); // caso não seja possível iniciar o controlador thaum (1); }}

Kauj Ruam 20: Cov Cai Code: Loop (), Tau Txais Pob thiab Txheeb Xyuas Hom Ntawv

Peb tau sim tshuaj xyuas qhov loj ntawm pob ntawv tau txais. CAN.parsePacket () txoj hauv kev qhia kuv qhov loj me ntawm pob ntawv no. Yog li yog tias peb muaj pob, peb yuav tshuaj xyuas seb nws puas txuas ntxiv lossis tsis yog.

void loop () {// Tenta verificar o tamanho do acote recebido int packetSize = CAN.parsePacket (); yog (packetSize) {// Se temos um pacote Serial.println ("Recebido pacote."); yog (CAN.packetExtended ()) {// verifica se o pacote é estendido Serial.println ("Estendido"); }

Kauj Ruam 21: Qhov Chaw: Loop (), Tshawb xyuas seb nws puas yog pob khoom nyob deb

Ntawm no, peb tshawb xyuas yog tias pob ntawv tau txais yog cov ntaub ntawv thov. Hauv qhov no, tsis muaj cov ntaub ntawv.

yog (CAN.packetRtr ()) {// Verifica se o pacote é um pacote remoto (Requisição de dados), neste caso não há dados Serial.print ("RTR"); }

Kauj Ruam 22: Cov Cai Tau Txais: Loop (), Cov Ntaub Ntawv Ntev Thov lossis Tau Txais

Yog tias pob ntawv tau txais yog qhov kev thov, peb qhia qhov thov ntev. Tom qab ntawd peb tau txais Cov Ntaub Ntawv Ntev Code (DLC), uas qhia txog qhov ntev ntawm cov ntaub ntawv. Thaum kawg, peb qhia qhov ntev tau txais.

Serial.print ("Pacote com tus lej 0x"); Serial.print (CAN.packetId (), HEX); yog (CAN.packetRtr ()) {// se o pacote recebido é de requisição, indicamos o constimento solicitado Serial.print ("e requsitou o comprimento"); Serial.println (CAN.packetDlc ()); // obtem o DLC (Cov Ntaub Ntawv Ntev Code, que indica o constimento dos dados)} lwm {Serial.print ("e constimento"); // aqui somente indica o comprimento recebido Serial.println (packetSize);

Kauj Ruam 23: Cov Cai Tau Txais: Loop (), Yog Cov Ntaub Ntawv Tau Txais, Nws Tom Qab Luam Ntawv

Peb luam tawm (ntawm tus saib hauv xov tooj) cov ntaub ntawv, tab sis tsuas yog tias lub pob ntawv tau txais tsis yog qhov kev thov.

// Imprime os dados somente se o pacote recebido não foi de requisição thaum (CAN.available ()) {Serial.print ((char) CAN.read ()); } Serial.println (); } Serial.println (); }}

Kauj Ruam 24: Rub Cov Ntaub Ntawv

PDF

INO

Pom zoo: