Konke mayelana nebhasi le-Arduino I2C

Ibhasi le-Arduino I2C

cunt I-Arduino ingadala inani elikhulu lamaphrojekthi njengoba ubonile uma ufunda iHwlibre, ukuhlela i-microcontroller ngendlela elula. Kepha phakathi kokuxhumeka kwe-analog ne-digital yaleli bhodi lamahadiwe mahhala, kukhona okunye okungaziwa kangako ngabaqalayo abaningi, njengamandla weqiniso wokuxhuma kwe-PWM, i-SPI, i-RX ne-TX izikhonkwane zetheku le-serial, noma ungumnikazi webhasi le-I2C. Ngakho-ke, ngalokhu kufakwa okungenani wazi konke okudingayo kusuka ku-I2C.

cunt ibhasi le-I2C ungaxhuma futhi usebenzise amadivayisi amaningi avela eceleni analolu hlobo lwephrothokholi ukuxhumana nebhodi le-Arduino. Phakathi kwabo, ungaxhuma ama-accelerometer, izibonisi, ikhawunda, amakhampasi, namasekethe amaningi ahlanganisiwe ngenxa yalokhu kusungulwa kwePhilips.

Yini i-I2C?

I2C ibhekisa ku-Inter-Integated Circuit, okungukuthi, isifunda esihlanganisiwe. Yibhasi yokuxhumana yedatha eyakhiwe ngo-1982 yinkampani iPhilips Semiconductors, namuhla eyiNXP Semiconductors ngemuva kokuqeda lesi sigaba. Ekuqaleni yayenzelwe amathelevishini alo mkhiqizo, ukuxhumana nezipisi ezimbalwa zangaphakathi ngendlela elula. Kepha kusukela ngo-1990 i-I2C isabalale futhi isetshenziswa ngabakhiqizi abaningi.

Okwamanje isetshenziswa ngabakhiqizi abaningi be-chip ngemisebenzi eminingi. U-Atmel, umsunguli wama-microcontroller wamabhodi e-Arduino, wethule igama le-TWI (Two Wired Interface) ngenhloso yokuthola amalayisense, yize lifana ne-I2C. Kepha ngo-2006, ilungelo lobunikazi langempela liphelelwe yisikhathi futhi alisenakubuswa yilungelo lobunikazi, ngakho-ke igama elithi I2C seliphinde lasetshenziswa (ilogo kuphela eqhubeka nokuvikelwa, kepha ukusetshenziswa kwayo noma ukusetshenziswa kwaleli gama akunqunyelwe).

Imininingwane yezobuchwepheshe be-I2C

I2C ibhasi

El Ibhasi le-I2C seliphenduke indinganiso yezimboni, kanti i-Arduino iyisebenzise yokuxhumana nemingcele eyidingayo. Idinga kuphela imigqa emibili noma izintambo zokusebenza kwayo, eyodwa yesiginali yewashi (CLK) kanti enye ukuthumela idatha ye-serial (SDA). Lokhu kunenzuzo uma kuqhathaniswa nokunye ukuxhumana uma kuqhathaniswa nebhasi le-SPI, yize ukusebenza kwayo kuyinkimbinkimbi ngokwengeziwe ngenxa yesekethe eyengeziwe edingekayo.

Kuleli bhasi idivayisi ngayinye exhunywe kuyo inekheli isetshenziselwe ukufinyelela lawa madivayisi ngawodwana. Leli kheli lilungiswa ngehardware, liguqula izingcezwana ezi-3 zokugcina ngokusebenzisa ama-jumpers noma ama-switch e-DIP, noma kungenziwa nangesoftware. Idivayisi ngayinye izoba nekheli elehlukile, yize eziningana zazo zingaba nekheli elifanayo futhi kungadingeka ukusebenzisa ibhasi lesibili ukugwema izingxabano noma ukulishintsha uma kungenzeka.

Ngaphezu kwalokho, ibhasi le-I2C line- Uhlobo lobuciko be-Master-Slave, okungukuthi, inkosi-isigqila. Lokhu kusho ukuthi lapho ukuxhumana kuqalwa ngethuluzi eliyinhloko, kuzokwazi ukuthumela noma ukwamukela idatha kusuka ezigqilazweni zayo. Izigqila ngeke zikwazi ukuqala ukuxhumana, inkosi kuphela engakwenza, futhi futhi nezigqila azikwazi ukukhuluma zodwa ngqo ngaphandle kokungenelela kwenkosi.

Uma unayo othisha abaningana ebhasini, munye kuphela ozokwazi ukusebenza njengomfundisi ngasikhathi sinye. Kepha akukufanele, ngoba ukuguqulwa kothisha kufuna ubunzima obuphakeme, ngakho-ke akuvamile.

Khumbula ukuthi master inikeza isignali yewashi ukuvumelanisa wonke amadivayisi ebhasini. Lokho kuqeda isidingo sokuthi isigqila ngasinye sibe newashi laso.

Iphrothokholi yebhasi ye-I2C ibuye ibone ukusetshenziswa kwama-resistor wokudonsa ezintanjeni zamandla okuhlinzeka (i-Vcc), yize lawa ma-resistors angavamisile ukusetshenziswa ne-Arduino donsa ngoba uhlela imitapo yolwazi njengoba iWire ivula abangaphakathi ngamanani angama-20-30 k. Lokhu kungahle kuthambe kakhulu kwamanye amaphrojekthi, ngakho-ke imiphetho ekhuphukayo yesiginali izohamba kancane, ngakho-ke isivinini esiphansi namabanga amafushane wokuxhumana angasetshenziswa. Ukulungisa lokho kungadinga ukuthi usethe ama-resistor wokudonsa wangaphandle kusuka ku-1k kuye ku-4k7.

Isiginali

Isiginali ye-I2C

 

La Uhlaka lokuxhumana lapho isiginali yebhasi le-I2C iqukethe izingcezwana noma izifundazwe (lezo ezisetshenziswe e-Arduino, ngoba indinganiso ye-I2C ivumela abanye):

  • Izingcezu eziyi-8, eziyi-7 zazo isiqondiso zedivayisi yesigqila ofuna ukuyithumela noma ukwamukela idatha kuyo. Ngama-bits angama-7, kungakhiwa amakheli afinyelela ku-128 ahlukile, ngakho-ke kungatholakala imishini engu-128, kepha kungatholwa kuphela i-112, ngoba i-16 ibekelwe ukusetshenziswa okukhethekile. Futhi okungeziwe okukhombisa ukuthi uyafuna thumela noma wamukele imininingwane yedivayisi yesigqila.
  • Kukhona futhi ukuqinisekiswa kancane, uma ingasebenzi ukuxhumana ngeke kuvumeleke.
  • Ngemuva kwalokho i- ama-byte wedatha ukuthi bafuna ukuthumela noma ukwamukela ngezigqila. I-byte ngayinye, njengoba wazi, yakhiwa ama-8-bits. Qaphela ukuthi kuyo yonke i-8-bit noma i-1 byte yedatha ethunyelwe noma etholakele, kudingeka ezinye izingcezu eziyi-18 zokuqinisekisa, ikheli, njll., Okusho ukuthi ibhasi lilinganiselwe kakhulu ngejubane.
  • Isilinganiso sokugcina se- ukuqinisekiswa wokuhlangana.

Ngaphezu kwalokho, imvamisa yewashi le- ukuthunyelwa kungu-100 Mhz njengokujwayelekile, yize kunemodi esheshayo ku-400 Mhz.

Izinzuzo nezinkinga zebhasi le-I2C

I-Las izinzuzo Yilezi:

  • Ukulula ngokusebenzisa imigqa emibili kuphela.
  • Ukulahlwa kwe izindlela zokwazi ukuthi isignali ifikile yini kuqhathaniswa nezinye izivumelwano zokuxhumana.

I-Las ukungalungi Yilezi:

  • Isivinini ukudluliswa okuphansi.
  • Akuyona impinda egcwele, okusho ukuthi, awukwazi ukuthumela nokwamukela ngasikhathi sinye.
  • Ayisebenzisi ubunye nanoma yiluphi olunye uhlobo lwendlela yokuqinisekisa ukwazi ukuthi ama-data bits atholakele alungile.

 

 

I2C ku-Arduino

Ibhasi le-Arduino I2C

En I-Arduino, kuya ngemodeli, izikhonkwane ezingavunyelwa ukusebenzisa leli bhasi le-I2C ziyehluka. Ngokwesibonelo:

  • Arduino UNO, INano, iMini ProI-A4 isetshenziselwa i-SDA (idatha) ne-A5 ye-SCK (iwashi).
  • I-Arduino Mega: phina u-20 we-SDA no-21 we-SCK.

Khumbula ukuthi ukuze uyisebenzise kufanele sebenzisa umtapo wezincwadi Ucingo.h ngamakhodi wakho we-Arduino IDE, yize kukhona amanye afana nawo I2C y I2Cdevlib. Ungafunda imibhalo yale mitapo yolwazi noma izindatshana zethu kumaphrojekthi onentshisekelo kuwo ukuthola amakhodi wokuthi angahlelwa kanjani.

Wazi kanjani ikheli ledivayisi ukulisebenzisa ne-I2C?

Isixwayiso esisodwa sokugcina, futhi lokho ukuthi uma uthenga ama-IC kubakhiqizi baseYurophu, baseJapan noma baseMelika, wena khombisa umkhombandlela kufanele usebenzise idivayisi. Ngakolunye uhlangothi, amaShayina kwesinye isikhathi awayichazi imininingwane noma ayilungile, ngakho-ke ngeke isebenze. Lokho kungaxazululwa kalula ngesithwebuli sekheli ukwazi ukuthi iyiphi inkomba okufanele ubhekise kuyo kumdwebo wakho.

La umphakathi we-arduino ukwenzile lokhu ikhodi ukuskena ikheli bese ulikhomba Ngendlela elula. Yize ngikukhombisa ikhodi lapha:

#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);
}


Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Yiba ngowokuqala ukuphawula

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.