Zvese nezve Arduino I2C bhazi

Arduino I2C bhazi

Con Arduino inogona kugadzira yakakura nhamba yemapurojekiti sezvawaona kana iwe ukaverenga Hwlibre, kuronga iyo microcontroller nenzira yakapusa. Asi pakati peanalogog uye yedhijitari kubatana kweiyi yemahara Hardware bhodhi, pane zvimwe zvisati zvazivikanwa kune vakawanda vanotanga, senge kugona kwechokwadi kwekubatana kwePWM, iyo SPI, iyo RX uye TX pini dze serial port, kana iyo yako I2C bhazi. Naizvozvo, neiyi yekupinda iwe unogona zvishoma kuziva zvese zvaunoda kubva kuI2C.

Con iyo I2C bhazi unogona kubatanidza uye kushandisa akawanda-echitatu-bato zvishandiso zvine iyi mhando yeprotocol yekutaurirana neArduino bhodhi. Pakati pavo, unogona kubatanidza accelerometers, maonesheni, kaunda, macompass, uye akawanda akawanda akabatanidzwa macircuit nekuda kweichi Philips chigadzirwa.

Chii chinonzi I2C?

I2C inoreva Inter-Integated Circuitndokuti, inopindirana-dunhu. Iyo serial data yekutaurirana bhazi yakagadzirwa muna 1982 nekambani yePhilips Semiconductors, iyo nhasi inonzi NXP Semiconductors mushure mekubvisa chikamu ichi. Pakutanga iyo yakagadzirirwa materevhizheni echiratidzo ichi, kuti ataure akati wandei machipisi nenzira yakapusa. Asi kubvira 1990 I2C yakapararira uye inoshandiswa nevakawanda vanogadzira.

Parizvino inoshandiswa nevakawanda vevanogadzira machipisi yemabasa akawanda. Atmel, iye mugadziri wema microcontroller emabhodhi eArduino, akaunza iyo TWI (Mbiri Wired Interface) kudomwa kwezvinangwa zvekupa marezinesi, kunyange hazvo yakafanana neI2C. Asi muna 2006, iyo yekutanga patent yakapera uye haichisiri pasi pekopiraiti, saka izwi rekuti I2C rakashandiswazve (logo chete ndiyo inoramba ichichengetedzwa, asi kuitiswa kwayo kana kushandiswa kwetemu hakurambidzwe).

I2C bhazi technical ruzivo

I2C bhazi

El I2C bhazi rave indasitiri yakajairwa, uye Arduino yaishandisa yekutaurirana nemipendero inoida iyo. Inongoda mitsara miviri kana tambo dzekushanda kwayo, imwe yechiratidzo chewachi (CLK) uye imwe yekutumira serial data (SDA). Izvi zvinobatsira kana zvichienzaniswa nezvimwe zvekutaurirana zvichienzaniswa nebhazi reSPI, kunyangwe mashandiro ayo akatonyanya kuomarara nekuda kwenzvimbo dzekuwedzera dzinodiwa.

Mubhazi rino mudziyo wega wega wakabatanidzwa pairi une kero yakashandiswa kuwana izvi zvishandiso zvakasiyana. Iri kero rakagadziriswa nehurdware, kugadzirisa matatu ekupedzisira nenzira dzekusvetuka kana kushandura maDIP, kunyangwe ichigonawo kuitwa nesoftware. Chishandiso chimwe nechimwe chichava nekero yakasarudzika, kunyangwe akati wandei angave aine kero imwechete uye zvingave zvakakodzera kushandisa bhazi rechipiri kudzivirira kunetsana kana kuchichinja kana zvichibvira.

Uye zvakare, iyo I2C bhazi ine Master-Muranda mhando mapurani, Ndokunge, tenzi-muranda. Izvi zvinoreva kuti kana kutaurirana kukatangwa neatenzi chishandiso, ichakwanisa kutumira kana kugamuchira dhata kubva kuvaranda vayo. Varanda havazokwanise kutanga kutaurirana, tenzi chete ndiye anogona kuzviita, uye zvakare varanda vacho havagone kutaura kune mumwe nemumwe zvakananga pasina kupindira kwashe.

Kana iwe uine vadzidzisi vakati wandei mubhazi, mumwe chete ndiye anogona kuita semudzidzisi panguva imwe chete. Asi hazvina kukodzera, nekuti shanduko yemudzidzisi inoda kunetsa kukuru, saka haiwanzo kuitika.

Ramba uchifunga kuti iyo tenzi anopa chiratidzo chewachi kuti aenzanise zvese zvishandiso zviri mubhazi. Izvo zvinobvisa kudiwa kwemuranda wega wega kuti ave newachi yake.

Iyo I2C bus protocol inofungidzira zvakare kushandiswa kweanodhonza-kumusoro maresitoreni mumagetsi emagetsi (Vcc), kunyangwe aya maresitor haawanzoshandiswa neArduino dhonza nekuti mapurogiramu emaraibhurari seWiiresi inomutsa iwo emukati nemahunhu e20-30 k. Izvi zvinogona kuve zvakapfava kune mamwe mapurojekiti, nekudaro iwo ari kukwira mativi echiratidzo anononoka, saka kumhanya kwakaderera uye madiki mafupi ekutaurirana anogona kushandiswa. Kugadzirisa izvo ungangoda kuisa ekunze ekudhonza-anopikisa kubva 1k kusvika 4k7.

Signal

I2C chiratidzo

 

La kutaurirana furemu yeiyo chiratidzo cheI2C bhazi chine mabiti kana matunhu (ayo anoshandiswa muArduino, sezvo muyero weIC2 unobvumidza vamwe):

  • 8 bits, 7 acho e nhungamiro yemuranda mudziyo waunoda kuwana kutumira kana kugamuchira data kubva mairi. Iine mabiti manomwe, anosvika mazana neshanu kero dzakasiyana dzinogona kugadzirwa, saka zana nemakumi masere nematanhatu dzinogona kuwanikwa, asi 7 chete dzinogona kuwanikwa, sezvo gumi nematanhatu zvakachengeterwa kushandiswa kwakakosha. Uye iyo yekuwedzera iyo inoratidza iyo kana iwe uchida tumira kana kugamuchira ruzivo rwechigadzirwa chemuranda.
  • Panewo zvakare kusimbiswa zvishoma, kana isiri kushanda kutaurirana kwacho hakuzoiti.
  • Ipapo iyo data mabheti kuti ivo vanoda kutumira kana kugashira nevaranda. Bheti yega yega, sekuziva kwako, inoumbwa ne8-bits Ziva kuti kune yega yega 8-bit kana 1 byte yedata rakatumirwa kana kugashirwa, mamwe mabhii gumi nematanhatu ekusimbiswa, kero, nezvimwewo anodikanwa, zvinoreva kuti bhazi rakaganhurirwa nekumhanya.
  • Chikamu chekupedzisira che kusimbiswa zvekubatana.

Uye zvakare, iyo frequency frequency ye kufambisa kuri 100 Mhz seyakajairwa, kunyangwe paine inokurumidza nzira pa400 Mhz.

Zvakanakira nekuipira bhazi reI2C

ari zvinobatsira Ndizvo:

  • Nyore nekungoshandisa mitsara miviri.
  • Inayo nzira dzekuziva kana chiratidzo chasvika uchienzaniswa nedzimwe nzira dzekutaurirana.

ari kukanganisa Ndizvo:

  • Speed kutapudza kwakaderera.
  • Haisi yakazara duplex, ndiko kuti, haugone kutumira uye kugamuchira panguva imwe chete.
  • Hazvishandisi parity kana chero imwe mhando yekusimbisa mashandiro ekuziva kana madhata mabhii akagamuchirwa ari echokwadi.

 

 

I2C paArduino

Arduino I2C bhazi

En Arduino, zvinoenderana nemuenzaniso, pini dzinogona kugoneswa kushandisa iyi I2C bhazi dzinosiyana. Semuyenzaniso:

  • Arduino UNO, Nano, MiniPro: A4 inoshandiswa kune SDA (data) uye A5 yeSCK (wachi).
  • Arduino Mega: pini 20 yeSDA uye 21 yeSKK.

Rangarira kuti kuishandisa iwe unofanirwa shandisa raibhurari Wire.h yeako Arduino IDE makodhi, kunyangwe paine mamwe akafanana I2C y I2Cdevlib. Unogona kuverenga zvinyorwa zvemaraibhurari aya kana zvinyorwa zvedu pazvirongwa zvinokufadza iwe kuti uwane makodhi ekuti angagadziriswe sei.

Nzira yekuziva sei kero yechigadzirwa kuti uishandise neI2C?

Kungoyeverwa kwekupedzisira, uye ndiko kuti kana iwe ukatenga maIC kubva kuEuropean, maJapan kana maAmerican vagadziri, iwe ratidza mafambiro iwe unofanirwa kushandisa kune chishandiso. Kune rimwe divi, maChinese dzimwe nguva haazvitaure kana zvisina kunaka, saka hazvishande. Izvo zvinogona kugadziriswa zviri nyore nekero scanner kuti uzive kwaunofanirwa kutarisa mune yako sketch.

La arduino nharaunda yakagadzira izvi kodhi yekutarisa kero uye kuiziva Nenzira yakapusa. Kunyangwe ini ndichikuratidza iyo kodhi ipo pano:

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


Izvo zviri muchinyorwa zvinoomerera pamisimboti yedu ye tsika dzekunyora. Kuti utaure chikanganiso tinya pano.

Iva wekutanga kutaura

Siya yako yekutaura

Your kero e havazobvumirwi ichibudiswa. Raida minda anozivikanwa ne *

*

*

  1. Inotarisira iyo data: Miguel Ángel Gatón
  2. Chinangwa cheiyo data: Kudzora SPAM, manejimendi manejimendi.
  3. Legitimation: Kubvuma kwako
  4. Kutaurirana kwedata
  5. Dhata yekuchengetedza: Dhatabhesi inobatwa neOccentus Networks (EU)
  6. Kodzero: Panguva ipi neipi iwe unogona kudzora, kupora uye kudzima ruzivo rwako