Duk game da motar Arduino I2C

Motar Arduino I2C

con Arduino na iya ƙirƙirar adadi mai yawa na ayyukan kamar yadda kuka gani idan kun karanta Hwlibre, shirye-shiryen microcontroller a hanya mai sauƙi. Amma daga cikin alamun analog da na dijital na wannan kwamfyutar kayan aikin kyauta, akwai wasu waɗanda har yanzu ba a san su da yawa ga masu farawa ba, kamar gaskiyar tasirin haɗin PWM, SPI, RX da TX fil na tashar, ko mallaki motar I2C. Sabili da haka, tare da wannan shigarwar aƙalla zaku iya sanin duk abin da kuke buƙata daga I2C.

con bas din I2C Kuna iya haɗawa da amfani da na'urori na ɓangare na uku waɗanda suke da irin wannan yarjejeniya don sadarwa tare da kwamitin Arduino. Tsakanin su, zaku iya haɗa hanzarin aiki, nuni, kantoci, kamfas, da kuma wasu da'irorin haɗe-haɗe masu tarin yawa albarkacin wannan ƙirar Philips.

Menene I2C?

I2C yana nufin Inter-Hadakar Circuit, ma'ana, kewayen hade-hade. Motar sadarwar sadarwar sadarwar ce ta ci gaba a cikin 1982 ta kamfanin Philips Semiconductors, wanda a yau shine NXP Semiconductors bayan kawar da wannan ɓangaren. Da farko an ƙirƙira shi don telebijin na wannan alamar, don sadarwa da kwakwalwan kwamfuta da yawa cikin sauƙi. Amma tun 1990 I2C ya bazu kuma yawancin masana'antun suna amfani dashi.

A halin yanzu da yawa daga chipmakers suke amfani dashi don ayyuka da yawa. Atmel, mai kirkirar microcontrollers na allon Arduino, ya gabatar da takaddar TWI (Hanyar Waya Biyu) don dalilai na lasisi, kodayake daidai yake da I2C. Amma a cikin 2006, asalin ikon mallakar ya ƙare kuma ba ya da ikon mallakar haƙƙin mallaka, saboda haka an sake amfani da kalmar I2C (tambarin ne kawai ke ci gaba da kiyayewa, amma aiwatar da shi ko amfani da kalmar ba a takura shi ba).

Bayanai na fasaha na bas na I2C

Motar I2C

El Motar I2C ta zama ƙa'idar masana'antu, kuma Arduino ya aiwatar da ita don sadarwa tare da kayan aikin da suke buƙata. Yana buƙatar layuka biyu ko igiyoyi ne kawai don aikinta, ɗaya don siginar agogo (CLK) ɗayan kuma don aika bayanan sirrin (SDA). Wannan yana da fa'ida idan aka kwatanta da sauran hanyoyin sadarwa idan aka kwatanta da motar SPI, kodayake aikinta yana da ɗan rikitarwa saboda ƙarin da'irar da ake buƙata.

A wannan bas din kowace na’ura da aka jona mata suna da adireshi amfani dasu don samun damar waɗannan na'urori daban-daban. Wannan adireshin an gyara shi ta hanyar kayan aiki, yana gyara ragowar 3 na ƙarshe ta hanyar tsalle ko sauya DIPs, kodayake kuma ana iya yin shi ta software. Kowace na'ura zata sami adireshi na musamman, kodayake da yawa daga cikinsu na iya samun adireshin iri ɗaya kuma yana iya zama dole a yi amfani da motar bas ta biyu don kauce wa rikice-rikice ko canza shi idan zai yiwu.

Bugu da kari, motar I2C tana da Ginin Jagora-Bawa, wato bawan-bawa. Wannan yana nufin cewa lokacin da sadarwa ta fara amfani da babbar na'ura, zata iya aika ko karban bayanai daga bayi. Bayin ba za su iya fara sadarwa ba, maigidan ne kawai zai iya yin hakan, haka kuma barorin za su iya magana da juna kai tsaye ba tare da sa hannun maigidan ba.

Idan kana da malamai da yawa a cikin bas din, mutum daya ne zai iya yin aikin malami lokaci guda. Amma bai cancanci hakan ba, tunda canjin malamin yana buƙatar babban rikitarwa, don haka ba shi da yawa.

Ka tuna cewa master yana bada siginar agogo don aiki tare da dukkan na'urori a cikin bas ɗin. Hakan yana kawar da bukatar kowane bawa ya mallaki agogonsa.

Yarjejeniyar bas ta I2C kuma tana hango amfani da tsayayyar iska a cikin layukan samarda wutan lantarki (Vcc), kodayake ba a yawan amfani da waɗannan masu adawa da Arduino ja saboda gidajen karatun shirye-shirye kamar yadda Waya ke kunna waɗanda ke ciki tare da ƙimomin 20-30 k. Wannan na iya zama mai laushi sosai ga wasu ayyukan, saboda haka hawan gefen siginar zai zama a hankali, saboda haka ana iya amfani da ƙananan saurin da gajeren hanyar sadarwa. Don gyara hakan kana iya buƙatar sanya ƙarfin adawa daga waje daga 1k zuwa 4k7.

Alamar

Alamar I2C

 

La tsarin sadarwa wanda siginar motar I2C ke dauke da ragowa ko jihohi (waɗanda aka yi amfani da su a Arduino, tunda ƙimar I2C tana ba wasu dama):

  • 8 ragowa, 7 daga cikinsu na adireshi na na'urar bawa da kake son shiga don aika ko karban bayanai daga gare ta. Tare da ragowa 7, har zuwa adireshi daban-daban har 128 za'a iya ƙirƙirar su, don haka ana iya samun damar amfani da na'urori 128 bisa ƙa'ida, amma 112 ne kawai za a iya isa garesu, tunda an keɓance 16 don amfani na musamman. Kuma ƙarin bit ɗin da ke nuna idan kuna so aika ko karba bawan na'urar bayanai.
  • Akwai kuma bit na inganci, idan baya aiki sadarwa bata aiki.
  • Sai kuma bayanan baiti cewa suna so su aika ko karɓa daga bayi. Kowane byte, kamar yadda kuka sani, ya kunshi 8-ragowa. Lura cewa ga kowane bit-8 ko 1 byt na bayanan da aka aiko ko karɓa, ana buƙatar ƙarin rago 18 na inganci, adireshin, da sauransu, wanda ke nufin cewa bas ɗin yana da iyakancewa cikin sauri.
  • Finalarshen bit na ingantacciya na sadarwa.

Bugu da kari, agogo mitar don watsawa shine 100 Mhz azaman daidaitacce, kodayake akwai yanayin sauri a 400 Mhz.

Fa'idodi da rashin amfani na motar I2C

da abubuwan amfani Su ne:

  • Sauki ta hanyar amfani da layi biyu kawai.
  • Yana da hanyoyin don sanin idan siginar ya isa idan aka kwatanta da sauran ladabi na sadarwa.

da disadvantages Su ne:

  • Sauri fairly low watsa.
  • Ba cikakke bane, ma'ana, ba za ku iya aikawa da karɓa lokaci guda ba.
  • Ba ya amfani da bambanci ko wani nau'in hanyar tabbatarwa don sanin idan bayanan bayanan da aka karɓa daidai ne.

 

 

I2C akan Arduino

Motar Arduino I2C

En Arduino, ya dogara da samfurin, fil da za a iya kunna don amfani da wannan motar bas ta I2C ya bambanta. Misali:

  • Arduino UNO, Nano, Mini Pro: A4 ana amfani dashi don SDA (bayanai) da A5 don SCK (agogo).
  • Mega Arduino: fil 20 don SDA da 21 don SCK.

Ka tuna cewa don amfani da shi dole ne yi amfani da laburaren Waya.h don lambobin IDE na Arduino, duk da cewa akwai wasu kamar I2C y I2Cdevlib. Kuna iya karanta takaddun waɗannan ɗakunan karatu ko abubuwanmu game da ayyukan da kuke sha'awa don samun lambobin yadda za'a tsara su.

Yaya ake sanin adireshin na'urar don amfani da ita tare da I2C?

Gargadin karshe kawai, kuma wannan shine lokacin da kuka sayi ICs daga masana'antun Turai, Japan ko Amurka, ku nuna shugabanci ya kamata kayi amfani dashi don na'urar. A gefe guda kuma, Sinawa a wasu lokuta ba sa yin bayani dalla-dalla ko ba daidai ba ne, don haka ba zai yi aiki ba. Hakan zai iya zama sauƙaƙe tare da na'urar adreshin adireshi don sanin wane shugabanci ya kamata ku koma a cikin zanenku.

La jama'ar arduino Ya halitta wannan lambar don bincika adireshin da gano shi A hanya mai sauki. Kodayake na nuna muku lambar anan:

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


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

Kasance na farko don yin sharhi

Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.