Zonse za basi ya Arduino I2C

Basi ya Arduino I2C

Con Arduino ikhoza kupanga ntchito zambiri monga mwawonera ngati muwerenga Hwlibre, mapulogalamu a microcontroller m'njira yosavuta. Koma pakati pa kulumikizana kwa analog ndi digito kwa bolodi yaulere iyi, pali zina zomwe sizikudziwika kwa oyamba kumene, monga kuthekera kwenikweni kwa kulumikizana kwa PWM, SPI, mapini a RX ndi TX a doko lonyamula, kapena Basi la I2C. Chifukwa chake, ndi kulowa uku mutha kudziwa chilichonse chomwe mungafune kuchokera ku I2C.

Con Basi ya I2C mutha kulumikiza ndikugwiritsa ntchito zida zambiri za anthu ena omwe ali ndi pulogalamu yamtunduwu yolumikizirana ndi gulu la Arduino. Pakati pawo, mutha kulumikiza accelerometers, mawonetsero, kauntala, ma kampasi, ndi ma circuits ena ambiri ophatikizidwa chifukwa cha izi zomwe Philips adapanga.

Kodi I2C ndi chiyani?

I2C imatanthawuza Dera Losakanikiranandiye kuti, kuphatikiza kosakanikirana. Ndi basi yolankhulirana yochitira ma data yopangidwa mu 1982 ndi kampani ya Philips Semiconductors, yomwe lero ndi NXP Semiconductors itachotsa gawoli. Poyamba idapangidwira ma TV amtunduwu, kuti alumikizane ndi tchipisi zingapo zamkati m'njira yosavuta. Koma kuyambira 1990 I2C yafalikira ndipo imagwiritsidwa ntchito ndi opanga ambiri.

Pakali pano imagwiritsidwa ntchito ndi opanga makina ambiri pazinthu zingapo. Atmel, wopanga ma microcontroller a Arduino board, adayambitsa dzina la TWI (Two Wired Interface) pazolinga zamalayisensi, ngakhale zili zofanana ndi I2C. Koma mu 2006, chivomerezo choyambirira chidatha ndipo sichikhala ndiumwini, motero mawu akuti I2C agwiritsidwanso ntchito (logo yokha ndi yomwe ikupitilizabe kutetezedwa, koma kukhazikitsa kapena kugwiritsa ntchito mawuwo sikungoletsedwe).

Zambiri zamabasi a I2C

Basi ya I2C

El Basi ya I2C yakhazikika pamalonda, ndipo Arduino wayigwiritsa ntchito yolumikizirana ndi zotumphukira zomwe zimafunikira. Imangofunika mizere iwiri kapena zingwe zogwirira ntchito, imodzi ndi mbendera ya wotchi (CLK) ndipo inayo yotumiza ma serial (SDA). Izi ndizopindulitsa poyerekeza ndi kulumikizana kwina poyerekeza ndi basi ya SPI, ngakhale magwiridwe ake ndi ovuta chifukwa chazowonjezera zina zofunika.

Pa basi iyi chipangizo chilichonse cholumikizidwa nacho chimakhala ndi adilesi amagwiritsa ntchito makinawa payokha. Adilesiyi imakonzedwa ndi ma hardware, ndikusintha ma bits atatu omaliza kudzera pa ma jumpers kapena kusintha ma DIP, ngakhale atha kuchitidwanso ndi mapulogalamu. Chipangizo chilichonse chimakhala ndi adilesi yapadera, ngakhale angapo akhoza kukhala ndi adilesi yomweyo ndipo kungakhale koyenera kugwiritsa ntchito basi yachiwiri kuti mupewe mikangano kapena kusintha ngati zingatheke.

Kuphatikiza apo, basi ya I2C ili ndi Zomangamanga za Master-Slave, ndiye kuti, kapolo wamkulu. Izi zikutanthauza kuti kulumikizana kukayambitsidwa ndi chida champhamvu, chizitha kutumiza kapena kulandira chidziwitso kuchokera kwa akapolo ake. Akapolowo sangathe kuyambitsa kulumikizana, ndi mbuye yekhayo amene angatero, ndipo akapolowo sangathe kulankhulana okhaokha popanda mbuye wawo.

Ngati mungathe aphunzitsi angapo pa basi, m'modzi yekha ndi amene angakhale mphunzitsi nthawi imodzi. Koma sizoyenera, popeza kusintha kwa aphunzitsi kumafuna zovuta zambiri, kotero sizowonjezereka.

Kumbukirani kuti master amapereka chizindikiritso cha wotchi kuti agwirizanitse zida zonse pa basi. Izi zimathetsa kufunika kwa kapolo aliyense kukhala ndi wotchi yakeyake.

Protocol ya basi ya I2C ikuwonetseranso kugwiritsidwa ntchito kwa zotsutsana ndi magetsi (Vcc), ngakhale ma resistor sagwiritsidwa ntchito ndi Arduino kukoka chifukwa mapulogalamu malaibulale monga Waya imatsegulira zamkati mwazikhalidwe za 20-30 k. Izi zitha kukhala zofewa kwambiri kuma projekiti ena, chifukwa chake kuwonjezeka kwa chizindikirocho kumachedwetsa, kuthamanga kwakanthawi kochepa komanso mtunda waufupi wolumikizirana ungagwiritsidwe ntchito. Kuti mukonze izi mungafunike kuyika zotsutsana zakunja kuchokera 1k mpaka 4k7.

Chizindikiro

Chizindikiro cha I2C

 

La chimango cholumikizirana Pomwe chizindikiro cha basi cha I2C chimakhala ndi ma bits kapena ma state (omwe amagwiritsidwa ntchito ku Arduino, popeza muyezo wa I2C umalola ena):

  • Ma bits 8, 7 mwa iwo a njira ya chida cha akapolo chomwe mukufuna kuti mutumize kapena kulandira deta kuchokera pamenepo. Ndi ma bits 7, mpaka ma adilesi osiyanasiyana a 128 atha kupangidwa, kotero zida za 128 zimatha kupezeka, koma ndi 112 zokha zomwe zingapezeke, popeza 16 zimasungidwa kuti zizigwiritsidwa ntchito mwapadera. Ndi zina zowonjezera zomwe zikuwonetsa ngati mukufuna kutumiza kapena kulandira chidziwitso cha akapolo.
  • Palinso kutsimikizira pang'ono, ngati sikugwira ntchito kuyankhulana sikukhala kovomerezeka.
  • Kenako ma data kuti akufuna kutumiza kapena kulandira ndi akapolo. Byte iliyonse, monga mukudziwa, ili ndi ma bits 8. Dziwani kuti pa 8-bit iliyonse kapena 1 ya data yomwe imatumizidwa kapena kulandiridwa, maina ena 18 ovomerezeka, adilesi, ndi zina zambiri amafunika, zomwe zikutanthauza kuti basiyo imathamanga kwambiri.
  • Gawo lomaliza la kuvomerezedwa za chisangalalo.

Kuphatikiza apo, kuchuluka kwa wotchi ya Kutumiza ndi 100 Mhz monga muyezo, ngakhale pali njira yofulumira pa 400 Mhz.

Ubwino ndi zovuta za basi ya I2C

ndi ubwino Iwo ndi:

  • Kuphweka pogwiritsa ntchito mizere iwiri yokha.
  • Zakhala Njira zodziwira ngati chizindikirocho chafika poyerekeza ndi njira zina zolumikizirana.

ndi zovuta Iwo ndi:

  • Kuthamanga Kutumiza pang'ono.
  • Si duplex yathunthuNdiye kuti, simungatumize ndi kulandira nthawi yomweyo.
  • Sagwiritsa ntchito parity kapena njira ina iliyonse yotsimikizira kuti mudziwe ngati ma data omwe alandila ndi olondola.

 

 

I2C pa Arduino

Basi ya Arduino I2C

En Arduino, kutengera mtunduwozikhomo zomwe zingathe kugwiritsidwa ntchito kugwiritsa ntchito basi iyi ya I2C zimasiyana. Mwachitsanzo:

  • Arduino UNO, Nano, Mini ovomereza: A4 imagwiritsidwa ntchito pa SDA (data) ndi A5 ya SCK (wotchi).
  • Mega Arduino: pini 20 ya SDA ndi 21 ya SCK.

Kumbukirani kuti kuti mugwiritse ntchito muyenera gwiritsani ntchito laibulale Zamgululi ma code anu a Arduino IDE, ngakhale pali ena onga I2C y I2Cdevlib. Mutha kuwerenga zolemba za malaibulale awa kapena zolemba zathu pazantchito zomwe zimakusangalatsani kuti mupeze ma code amomwe angakonzedwere.

Kodi mungadziwe bwanji adilesi yazida kuti mugwiritse ntchito ndi I2C?

Chenjezo limodzi lomaliza, ndiye kuti mukamagula ma IC kuchokera kwa opanga aku Europe, Japan kapena America, inu onetsani mbali zomwe muyenera kugwiritsa ntchito chipangizocho. Mbali inayi, achi China nthawi zina samazifotokoza mwatsatanetsatane kapena sizolondola, chifukwa sizigwira ntchito. Izi zitha kuthetsedwa mosavuta ndi chojambulira ma adilesi kuti mudziwe njira yomwe muyenera kulozera pazojambula zanu.

La gulu la arduino adapanga izi code kuti muyese adilesi ndikuizindikira Mwanjira yosavuta. Ngakhale ndikuwonetsani nambala yanu apa:

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


Zomwe zili m'nkhaniyi zikutsatira mfundo zathu za malamulo okonzekera. Kuti mufotokoze cholakwika dinani Apa.

Khalani oyamba kuyankha

Siyani ndemanga yanu

Anu email sati lofalitsidwa. Amafuna minda amalembedwa ndi *

*

*

  1. Wotsogolera pazosankhazi: Miguel Ángel Gatón
  2. Cholinga cha deta: Control SPAM, kasamalidwe ka ndemanga.
  3. Kukhazikitsa: Kuvomereza kwanu
  4. Kulumikizana kwa zomwe zafotokozedwazo: Zomwezo siziziwululidwa kwa anthu ena kupatula pakukakamizidwa mwalamulo.
  5. Zosunga: Zosungidwa ndi Occentus Networks (EU)
  6. Ufulu: Nthawi iliyonse mutha kuchepetsa, kuchira ndikuchotsa zidziwitso zanu.