E pili ana i ke kaʻa ʻōhua ʻo Arduino I2C

Pahi holo Arduino I2C

Con Hiki iā Arduino ke hana i nā papahana he nui e like me kāu i ʻike ai inā heluhelu ʻoe iā Hwlibre, ke hoʻolālā ʻana i ka microcontroller ma kahi ala maʻalahi. Akā ma waena o nā aniani a me nā hoʻopili uila o kēia papa lako lako manuahi, aia kekahi mau mea i ʻike ʻole ʻia e nā poʻe hoʻomaka, e like me ka hiki maoli o nā pilina PWM, nā SPI, nā RX a me nā TX pine o ka port serial, a i ʻole ka kaʻa ʻōhua I2C ponoʻī. No laila, me kēia komo ʻana hiki iā ʻoe ke ʻike i nā mea āpau āu e makemake ai mai ka I2C.

Con ke kaʻa ʻōhua I2C hiki iā ʻoe ke hoʻohui a hoʻohana i nā hāmeʻa ʻaoʻao ʻekolu i loaʻa i kēia ʻano protocol e kamaʻilio pū me ka papa Arduino. Ma waena o lākou, hiki iā ʻoe ke hoʻohui i nā accelerometers, hōʻike, counter, panana, a me nā kaho hoʻohui like he nui aʻe i kēia hana hou a Philips.

He aha ka I2C?

ʻO I2C e pili ana i ka Inter-Integated Circuit, ʻo ia hoʻi, kaapuni hoʻohui waena. He pahi kamaʻilio ʻikepili serial i hoʻomohala ʻia ma 1982 e ka ʻoihana Philips Semiconductors, a i kēia lā ʻo NXP Semiconductors ma hope o ka hemo ʻana o kēia ʻāpana. I ka manawa mua ua hana ʻia no nā kīwī o kēia māka, e kamaʻilio i nā puʻupuʻu kūloko i kahi ala maʻalahi. Akā mai ka 1990 ua hoʻolaha ka I2C a hoʻohana ʻia e nā mea hana he nui.

Hoʻohana ʻia i kēia manawa e nā kekeke chipmaker no nā hana he nui. ʻO Atmel, ka mea nāna i hana nā microcontrollers no nā papa Arduino, i hoʻolauna i ka inoa TWI (Two Wired Interface) no nā laikini, ʻoiai ua like ia me I2C. Akā i ka 2006, ua pau ka palapala Sila Nui a ʻaʻole kuleana hou ʻia i ke kope kope, no laila ua hoʻohana hou ʻia ka huaʻōlelo I2C (hoʻomau ʻia ka pale ʻana i ka logo, akā ʻaʻole kaohi ʻia ka hoʻokō a hoʻohana ʻana o ka huaʻōlelo.

I2C kaʻa ʻōnaehana kikoʻī

I2C kaʻa ʻōhua

El Ua lilo ke kaʻa ʻōhua ʻo I2C i hae ʻoihana, a ua hoʻokō ʻo Arduino iā ia no ke kamaʻilio ʻana me nā peripherals e pono ai. Pono wale ia i ʻelua mau laina a kaula paha no kāna hana, hoʻokahi no ka uaki uaki (CLK) a ʻo kekahi no ka hoʻouna ʻana i ka ʻikepili serial (SDA). Hoʻonui kēia i ka hoʻohālikelike ʻia i nā kamaʻilio ʻē aʻe i hoʻohālikelike ʻia i ka pahi SPI, ʻoiai ʻoi aku ka paʻakikī o kāna hana ma muli o ka circuitry hou e koi ʻia.

Ma kēia kaʻa ʻōhua pili kēlā me kēia hāmeʻa i kahi helu wahi hoʻohana 'ia e nānā i kēia mau mea pakahi. Hoʻopaʻa ʻia kēia wahi i nā lako pono, hoʻololi i nā ʻāpana 3 hope loa e nā mea lele a i ʻole kuapo i nā DIP, ʻoiai hiki ke hana ʻia e ka polokalamu. E loaʻa i kēlā me kēia hāmeʻa kahi helu kūikawā, ʻoiai he mau helu like paha kekahi o lākou a pono paha e hoʻohana i kahi kaʻa ʻelua e pale i nā hakakā a hoʻololi paha inā hiki.

Hoʻohui ʻia, loaʻa i kahi kaʻa I2C Kūkala ʻano haku-kahu, ʻo ia, haku-kauā. ʻO kēia ke hoʻomaka ʻia ke kamaʻilio e kahi haku hana, hiki iā ia ke hoʻouna a loaʻa paha i ka ʻikepili mai kāna kauā. ʻAʻole hiki i nā kauā ke hoʻomaka i ke kamaʻilio, ʻo ka haku wale nō ka mea hiki ke hana, ʻaʻole hiki i nā kauā ke kamaʻilio pololei me kekahi me ka ʻole o ka haku.

Ināʻoe kekahi mau kumu ma ke kaʻa ʻōhua, hoʻokahi wale nō hiki ke lilo i kumu ma ka manawa like. Akā ʻaʻole pono ia, no ka mea ke koi nei ka loli o ke kumu i kahi paʻakikī paʻakikī, no laila ʻaʻole pinepine.

E hoʻomanaʻo i ka Hāʻawi ka haku i ka wati uaki e hoʻopili i nā hāmeʻa āpau ma ke kaʻa ʻōhua. Hoʻopau kēlā i ka pono o kēlā me kēia kauā e loaʻa i kā lākou uaki ponoʻī.

ʻIke pū ka protocol bus I2C i ka hoʻohana ʻana o nā resistors huki i nā laina voltage supply (Vcc), ʻoiai ʻaʻole hoʻohana mau ʻia kēia mau mea pale me Arduino huki huki no ka mea, nā waihona puke papahana ʻoiai ʻo Wire e hoʻoulu i nā mea kūloko me nā waiwai o 20-30 k. He palupalu paha kēia no kekahi mau papahana, no laila e lohi ka piʻi ʻana o ke kihi o ka hōʻailona, ​​no laila hiki ke hoʻohana i nā wikiwiki haʻahaʻa a me nā mamao kamaʻilio pōkole. E hoʻoponopono e pono ai ʻoe e kau i nā mea pale kū kūwaho kūwaho mai 1k a i 4k7.

Hōʻike hōʻailona

Hōʻailona I2C

 

La papa kūkā kamaʻilio ʻo kahi o kahi hōʻailona I2C bus i komo i nā ʻāpana a i ʻole nā ​​mokuʻāina (nā mea i hoʻohana ʻia ma Arduino, ʻoiai ʻo ka standard I2C e ʻae ai i nā poʻe ʻē aʻe):

  • 8 ʻāpana, 7 o lākou o kuhikuhi o ka pono kauā āu e makemake ai e kiʻi a loaʻa i nā ʻikepili mai iā ia. Me 7 mau ʻāpana, hiki i ka 128 mau helu kuhi ʻē aʻe ke hana ʻia, no laila hiki ke kiʻi ʻia i nā hāmeʻa he 128, akā ʻo 112 wale nō ke kiʻi ʻia, ʻoiai 16 i mālama ʻia no nā hoʻohana kūikawā. A ʻo ka mea hou aʻe e hōʻike ana inā makemake ʻoe hoʻouna a loaʻa paha ʻike ʻike kauā kauā.
  • Aia kekahi he ʻāpana hōʻoia, inā ʻaʻole ʻeleu ia e kū ʻole ke kamaʻilio.
  • A laila ka bytes ʻikepili makemake lākou e hoʻouna a loaʻa paha i nā kauā. ʻO kēlā me kēia byte, e like me kou ʻike, he ʻāpana 8 mau ʻāpana. E hoʻomaopopo no kēlā me kēia 8-bit a i ʻole 1 byte o ka ʻikepili i hoʻouna ʻia a loaʻa paha, koi ʻia he 18 mau paona o ka hōʻoia, ka helu wahi, a me nā mea ʻē aʻe, ʻo ia hoʻi ka palena o ka wikiwiki i ka wikiwiki.
  • ʻO kahi hope loa o waiwai o ka comunication.

Hoʻohui, ka pinepine uaki no nā transmissions ʻo 100 Mhz ma ke ʻano maʻamau, ʻoiai aia kahi ʻano wikiwiki ma 400 Mhz.

Nā mea maikaʻi a me nā maikaʻi ʻole o ke kaʻa ʻōhua I2C

ka nā pōmaikaʻi Ka mea, e:

  • Keʻano maʻalahi ma ka hoʻohana wale ʻana i ʻelua laina.
  • Loaa nā ʻano hana e ʻike inā ua hōʻea ka hōʻailona hoʻohālikelike ʻia i nā loina kamaʻilio ʻē aʻe.

ka nā meaʻino Ka mea, e:

  • ʻEpekema hoʻoili haʻahaʻa haʻahaʻa.
  • ʻAʻole ia he duplex piha, ʻo ia hoʻi, ʻaʻole hiki iā ʻoe ke hoʻouna a loaʻa i ka manawa like.
  • ʻAʻole hoʻohana i ka parity ʻaʻole hoʻi i kekahi ʻano hana o ka hōʻoia e ʻike inā pololei nā ʻikepili i loaʻa.

 

 

I2C ma Arduino

Pahi holo Arduino I2C

En Arduino, kaukaʻi ʻia i ke k modelkohu, ʻokoʻa nā mākia i hiki ke hoʻohana i kēia bus I2C. O kahi laʻana:

  • Arduino UNO, Nano, MiniPro: Hoʻohana ʻia ʻo A4 no SDA (ʻikepili) a me A5 no SCK (uaki).
  • ʻO Arduino Mega: pin 20 no SDA a me 21 no SCK.

E hoʻomanaʻo i ka hoʻohana ʻana ia pono ʻoe hoʻohana i ka waihona Uea.h no kāu code Arduino IDE, ʻoiai aia kekahi e like me I2C y I2Cdevlib. Hiki iā ʻoe ke heluhelu i nā palapala o kēia mau waihona puke a i ʻole i kā mākou ʻatikala ma nā papahana e hoihoi iā ʻoe e loaʻa nā code o ka pehea e hoʻolālā ʻia ai.

Pehea e ʻike ai i ka helu wahi o kahi hāmeʻa e hoʻohana iā ia me I2C?

Hoʻokahi wale nō ʻōlelo aʻoaʻo hope loa, a ʻo ia ke kūʻai ʻana iā IC mai nā mea hana ʻEulopa, Iapana a ʻAmelika paha kuhikuhi i ke kuhikuhi pono ʻoe e hoʻohana no ka hāmeʻa. I kekahi ʻaoʻao, ʻaʻole kikoʻī ka Kina i kekahi manawa a pololei ʻole paha ia, no laila ʻaʻole e holo. Hiki ke hoʻonā maʻalahi ʻia me kahi scanner kamaʻilio e ʻike i ke ʻaoʻao āu e kuhikuhi ai i kāu kiʻi.

La kaiāulu arduino ua hana i kēia kivila e nānā i ka helu wahi a hoʻomaopopo iā ia Ma kahi ala maʻalahi. ʻOiai wau e hōʻike aku iā ʻoe i ke code ma aneʻi:

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


Hoʻopili ka ʻike o ka ʻatikala i kā mākou kumumanaʻo o ka hoʻoponopono hoʻoponopono. E hōʻike i kahi kaomi hemahema ʻaneʻi.

E lilo i mea mua e wehewehe

E waiho i kāu manaʻo

Kāu leka uila aae? E,ʻaʻole e paʻiʻia. i hāliu aku i koi 'ia kula *

*

*

  1. He kuleana no ka ʻikepili: Miguel Ángel Gatón
  2. Ke kumu o ka ʻikepili: kaohi SPAM, hoʻokele ʻōlelo.
  3. Legitimation: Kou ʻae
  4. Ka kamaʻilio ʻana o ka ʻikepili: ʻaʻole e hōʻike ʻia ka ʻikepili i nā ʻaoʻao ʻekolu koe ka mana o ke kānāwai.
  5. Pūnaewele mālama: Pūnaewele i mālama ʻia e Occentus Networks (EU)
  6. Nā Kuleana: I kēlā me kēia manawa hiki iā ʻoe ke palena, hoʻōla a kāpae i kāu ʻike.