Konke malunga nebhasi yeArduino I2C

I-Arduino I2C ibhasi

Con I-Arduino inokudala inani elikhulu leeprojekthi njengoko ubonile ukuba ufunda iHwlibre, udweliso lwenkqubo kwi-microcontroller ngendlela elula. Kodwa phakathi kokunxibelelana kwe-analog kunye nedijithali yale bhodi yehardware yasimahla, kukho ezinye ezingasaziwa kwabasaqalayo abaninzi, ezinje ngokuqina konxibelelwano lwe-PWM, i-SPI, i-RX kunye ne-TX izikhonkwane zezibuko lezibuko, okanye eyakho ibhasi ye-I2C. Ke ngoko, ngolu ngenelo ungazi yonke into oyifunayo kwi-I2C.

Con Ibhasi ye-I2C Unokudibanisa kwaye usebenzise izixhobo ezininzi zomntu wesithathu ezinolu hlobo lweprotocol ukunxibelelana nebhodi yeArduino. Phakathi kwabo unokudibanisa ii-accelerometer, izibonisi, iikhawuntari, kunye neesekethe ezininzi ezihlanganisiweyo enkosi kule nto yenziwe yiPhilips.

Yintoni i-I2C?

I2C ibhekisa kwiSekethe engaphakathiOko kukuthi, isekethe edityanisiweyo. Yibhasi yokunxibelelana ngedatha eyi-serial ephuhliswe ngo-1982 yinkampani ye-Philips Semiconductors, namhlanje eyi-NXP Semiconductors emva kokulahla eli candelo. Kuqala yenzelwe iithelevishini zolu hlobo, ukunxibelelana ngeetshiphusi ezininzi zangaphakathi ngendlela elula. Kodwa ukusukela ngo-1990 i-I2C isasazekile kwaye isetyenziswa ngabavelisi abaninzi.

Okwangoku isetyenziswa ngabaninzi bee-chipmaker yemisebenzi emininzi. I-Atmel, umyili wee-microcontrollers zeebhodi ze-Arduino, wazisa igama le-TWI (ezimbini ezinentambo esibonakalayo) ngeenjongo zokufumana iilayisensi, nangona iyafana ne-I2C. Kodwa ngo-2006, i-patent yoqobo yaphelelwa lixesha kwaye ayisekho phantsi kwelungelo lobunikazi, ke igama elithi I2C lisetyenziswe kwakhona (kuphela ilogo eqhubeka ikhuselwa, kodwa ukusetyenziswa kwayo okanye ukusetyenziswa kwegama akukhawulelwanga).

Iinkcukacha ngebhasi ye-I2C

I2C ibhasi

El I2C ibhasi ibe ngumgangatho kumzi mveliso, kwaye iArduino iyiphumezile Ukunxibelelana nemida eyifunayo. Ifuna kuphela imigca emibini okanye iintambo ekusebenzeni kwayo, enye yeyesiginali yewotshi (CLK) kunye nenye yokuthumela idatha ye-serial (SDA). Oku kuluncedo xa kuthelekiswa nolunye unxibelelwano ngokuthelekiswa nebhasi ye-SPI, nangona ukusebenza kwayo kunzima ngakumbi ngenxa yesekethe eyongezelelweyo efunekayo.

Kule bhasi isixhobo ngasinye esidityaniswe kuyo sinedilesi esetyenziselwa ukufikelela kwezi zixhobo ngokukodwa. Le dilesi ilungiswe ngesixhobo sehardware, esiguqula ii-bits ezi-3 zokugqibela ngokutsiba okanye ngokutshintsha ii-DIPs, nangona zinokwenziwa nakwisoftware. Isixhobo ngasinye siya kuba nedilesi eyahlukileyo, nangona uninzi lwazo lunokuba nedilesi enye kwaye kunokuba yimfuneko ukusebenzisa ibhasi yesibini ukunqanda ungquzulwano okanye ukuyitshintsha ukuba kunokwenzeka.

Ukongeza, ibhasi ye-I2C ine Uhlobo lobugcisa bekhoboka, Oko kukuthi, ikhoboka eliyintloko. Oku kuthetha ukuba xa unxibelelwano luqaliswa sisixhobo esiyintloko, siya kuba nakho ukuthumela okanye ukufumana idatha kumakhoboka ayo. Amakhoboka awayi kuba nakho ukuqala unxibelelwano, kuphela yinkosi enokuyenza, kwaye namakhoboka akanakuthetha omnye nomnye ngokuthe ngqo ngaphandle kongenelelo lwenkosi.

Ukuba unayo Ootitshala abaliqela ebhasini, Mnye kuphela onokusebenza njengomfundisi ngaxeshanye. Kodwa ayifanelekanga, kuba utshintsho lootitshala lufuna ubunzima obuphezulu, ngoko ke alukho rhoqo.

Gcina ukhumbula ukuba inkosi ibonelela ngesiginali yewotshi ukungqamanisa zonke izixhobo ebhasini. Oko kuphelisa isidingo sokuba ikhoboka ngalinye libe newotshi yalo.

Umgaqo-nkqubo webhasi we-I2C ukwabona ukusetyenziswa kwe-resistors zokutsala kwimigca ye-voltage yonikezelo (Vcc), nangona ezi zixhathisa zihlala zingasetyenziswa neArduino tsala ngenxa yokuba iinkqubo zethala leencwadi Njengocingo lusebenza lwangaphakathi ngamaxabiso angama-20-30 k. Oku kunokuba kubutofotofo kwezinye iiprojekthi, ngenxa yoko imiphetho ekhulayo yomqondiso iya kuhamba kancinci, isantya esisezantsi kunye nemigama emifutshane yokunxibelelana inokusetyenziswa. Ukulungisa ukuba ungadinga ukuseta izixhobo zokutsala zangaphandle ezivela kwi-1k ukuya kwi-4k7.

Isiginali

Umqondiso we-I2C

La isakhelo sonxibelelwano Umqondiso webhasi we-I2C uqukethe iibits okanye iimeko (ezo zisetyenziswe eArduino, kuba umgangatho we-I2C uvumela abanye):

  • Iibhithi ezi-8, ezisi-7 zazo idilesi yesixhobo sekhoboka ofuna ukungena kuso ukuthumela okanye ukufumana i data evela kuso. Ngama-7 bits, ukuya kuthi ga kwiidilesi ezahlukeneyo ezili-128 ezinokwenziwa, kungoko izixhobo ezingama-128 zinokufikelelwa ngokwengcinga, kodwa zinokufikeleleka kuphela ezili-112, kuba zili-16 zigcinelwe usetyenziso olukhethekileyo. Kwaye isuntswana elongezelelweyo elibonisa ukuba uyafuna thumela okanye wamkele Ulwazi lwezixhobo zekhoboka.
  • Kukho kwakhona isuntswana lokuqinisekisa, ukuba ayisebenzi unxibelelwano aluyi kuba semthethweni.
  • Emva koko idatha yedatha ukuba bafuna ukuthumela okanye ukufumana ngamakhoboka. I-byte nganye, njengoko uyazi, yenziwe ziibhithi ezi-8. Qaphela ukuba kuyo yonke i-8-bit okanye i-1 byte yedatha ethunyelweyo okanye efunyenweyo, kuyafuneka ukongezwa kweebits ezili-18 zokuqinisekisa, idilesi, njl.njl, oko kuthetha ukuba ibhasi inomda kakhulu ngokwesantya.
  • Isiphelo sokugqibela uqinisekiso Yonxibelelwano.

Ukongeza, ubude bexesha lewotshi Ukuhanjiswa yi-100 Mhz njengomgangatho, nangona kukho imowudi ekhawulezayo kwi-400 Mhz.

Izinto eziluncedo nezingalunganga ebhasi ye-I2C

Las ezintle Zizo:

  • Ukulula ngokusebenzisa imigca emibini kuphela.
  • Inayo iindlela zokwazi ukuba umqondiso ufikile xa kuthelekiswa nezinye iinkqubo zonxibelelwano.

Las ngxaki Zizo:

  • Isantya Ukuhanjiswa okuphantsi.
  • Ayisiyiyo iduplex epheleleyoOko kukuthi, awunakho ukuthumela nokwamkela ngaxeshanye.
  • Ayisebenzisi ubulungisa okanye naluphi na olunye uhlobo lwendlela yokuqinisekisa ukwazi ukuba iidata ezifunyenweyo zichanekile.

I2C kwiArduino

I-Arduino I2C ibhasi

En Arduino, kuxhomekeke kwimodeliIzikhonkwane ezinokuthi zisebenzise le bhasi ye-I2C ziyahluka. Umzekelo:

  • Arduino UNO, Nano, MiniPro: A4 isetyenziselwa i-SDA (idatha) kunye ne-A5 ye-SCK (iwotshi).
  • UArduino Mega: i-pin 20 ye-SDA kunye ne-21 ye-SCK.

Khumbula ukuba ukuze uyisebenzise kufuneka Sebenzisa ithala leencwadi Ucingo.h Iikhowudi zakho ze-IDE zeArduino, nangona zikhona ezinye ezinje I2C y i2cdevlib. Ungawafunda amaxwebhu ala mathala eencwadi okanye amanqaku ethu kwiiprojekthi onomdla wokufumana iikhowudi zendlela enokucwangciswa ngayo.

Uyazi njani idilesi yesixhobo ukusisebenzisa kunye ne-I2C?

Isilumkiso esinye sokugqibela, kwaye yile xa uthenga ii-ICs kubenzi baseYurophu, baseJapan okanye baseMelika, wena bonisa icala onokuyisebenzisela isixhobo. Kwelinye icala, amaTshayina ngamanye amaxesha akayicacisi okanye ayichanekanga, ke ayizukusebenza. Oko kunokuba lula ukusonjululwa ngeskena sedilesi ukuze wazi ukuba loluphi ulwalathiso ekufuneka ujonge kulo kumzobo wakho.

La uluntu lwase-arduino uyenzile le ikhowudi yokuskena idilesi kwaye ichonge Ngendlela elula. Nangona ndikubonisa ikhowudi apha:

#include "Wire.h"
 
extern "C" { 
    #include "utility/twi.h"
}
 
void scanI2CBus(byte from_addr, byte to_addr, void(*callback)(byte address, byte result) ) 
{
  byte rc;
  byte data = 0;
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1, 0);
    callback( addr, rc );
  }
}
 
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,DEC);
  Serial.print( (result==0) ? " Encontrado!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}
 
 
const byte start_address = 8;
const byte end_address = 119;
 
void setup()
{
    Wire.begin();
 
    Serial.begin(9600);
    Serial.print("Escaneando bus I2C...");
    scanI2CBus( start_address, end_address, scanFunc );
    Serial.println("\nTerminado");
}
 
void loop() 
{
    delay(1000);
}


Yiba ngowokuqala ukuphawula

Shiya uluvo lwakho

Idilesi yakho ye email aziyi kupapashwa. ezidingekayo ziphawulwe *

*

*

  1. Uxanduva lwedatha: UMiguel Ángel Gatón
  2. Injongo yedatha: Ulawulo lwe-SPAM, ulawulo lwezimvo.
  3. Umthetho: Imvume yakho
  4. Unxibelelwano lwedatha: Idatha ayizukuhanjiswa kubantu besithathu ngaphandle koxanduva lomthetho.
  5. Ukugcinwa kweenkcukacha
  6. Amalungelo: Ngalo naliphi na ixesha unganciphisa, uphinde uphinde ucime ulwazi lwakho.