Cov txheej txheem:

I2C Bus rau ATtiny thiab ATmega: 8 Kauj Ruam
I2C Bus rau ATtiny thiab ATmega: 8 Kauj Ruam

Video: I2C Bus rau ATtiny thiab ATmega: 8 Kauj Ruam

Video: I2C Bus rau ATtiny thiab ATmega: 8 Kauj Ruam
Video: AVR 47# Программный I2C 2024, Kaum ib hlis
Anonim
I2C Bus rau ATtiny thiab ATmega
I2C Bus rau ATtiny thiab ATmega

Kuv nyiam Atmel AVR microcontrollers! Txij li thaum tsim Ghetto Kev Txhim Kho Txheej Txheem tau piav qhia hauv Phau Ntawv Qhia no, Kuv tsis muaj qhov kawg ntawm kev lom zem sim nrog AVR ATtiny2313 thiab ATmega168 tshwj xeeb. Kuv txawm mus kom deb li deb los sau Cov Lus Qhia ntawm kev siv cov hloov pauv raws li cov tswv yim, thiab txuas ntxiv Ghetto Kev Txhim Kho Txheej Txheem lub tswv yim rau CPLDs Thaum lub sijhawm ua haujlwm tsis ntev los no, kuv xav tau ob peb lub keyboards rau kev teeb tsa tswj qhov muaj nuj nqis. AVRs tsis muaj I/O koob txaus, yog li kuv yuav tsum xav txog qee yam. Kuv tuaj yeem tau sim cov txheej txheem nkag mus yooj yim nrog cov keyboard thiab zaub, tab sis ATtiny2313 yuav tsis muaj peev txheej. Hmoov zoo, Atmel tau muab txoj hauv kev nyob ib puag ncig cov teeb meem no los ntawm suav nrog kev sib cuam tshuam uas tuaj yeem txuas rau cov chips ntxiv (xws li nco lossis I/O chaw nres nkoj) nrog ob kab lus yooj yim. Yog lawm, los ntawm kev siv tsuas yog ob tus I/O tus pin ntawm AVR peb tuaj yeem nkag tau ntau yam ntxiv I/O pins, thiab lwm yam peev txheej ib yam. Ob txoj kab hlau txuas no tau raug hu ua Inter-Integrated Circuit bus, lossis tsuas yog I2C npav thiab tau tsim los ntawm NXP thaum nws tseem yog Philips Semiconductors. Yog tias koj tab tom nyeem Cov Lus Qhia no tej zaum koj yuav tau hnov txog I2C lub tsheb npav thiab tej zaum tseem tau siv nws ntawm PIC lossis lwm lub microcontroller. Thaum lub tswv yim yooj yim heev, thiab txhawb los ntawm cov khoom siv kho vajtse ntawm AVRs, cov tsav tsheb software tseem tsim nyog siv I2C npav. Atmel muab Daim Ntawv Thov Kev Pab (saib Cov Khoom Siv tom qab hauv Cov Lus Qhia no), tab sis cov no tsis tiav thiab tsis qhia ib qho piv txwv dhau kev sib txuas lus nrog lwm lub cuab yeej AVR. Nws tsis yog lub hom phiaj ntawm qhov qhia no qhia rau leej twg yuav tsim I2C tsav tsheb rau AVRs. Qhov tseeb, kuv yuav muab nthuav dav ntawm Atmel tsav tsheb rau ATtiny2313 thiab ATmega168 cov cuab yeej, Kuv yuav piav qhia qhov yuav tsum tau thiab kev txwv uas siv thaum siv cov no, thiab kuv yuav qhia koj ua piv txwv ntawm I2C cov cuab yeej. Tom qab koj ua haujlwm dhau ntawm Cov Lus Qhia no koj yuav tuaj yeem siv I2C npav tau zoo hauv koj li haujlwm AVR. Pom tseeb, koj tuaj yeem tsis quav ntsej cov tsav tsheb rau me me lossis MEGA yog tias koj tsuas yog xav tau ib qho ntawm lawv. Rau cov uas xav paub ntau ntxiv txog I2C npav, Kuv yuav muab cov ntawv txuas rau cov khoom tsim nyog.

Kauj Ruam 1: Txhua Yam Khoom I2C Yog Dab Tsi?

Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?
Txhua Yam Khoom I2C Qhov Twg Lawm?

Lub npav I2C yog qhov yooj yim, ob txoj hlua txuas uas tuaj yeem txuas ntau yam khoom siv ua ke thiab tso cai rau lawv sib pauv cov ntaub ntawv. Hauv nws daim ntawv yooj yim tshaj plaws muaj ib lub cuab yeej siv tswv yim uas sib txuas lus rau ntau yam cuab yeej qhev. Txhua lub cuab yeej txuas nrog ua ob kab ntawm I2C npav. Ob lub xov hlau hu ua SCL thiab SDA. SCL yog kab kab thiab yog tswj los ntawm tus tswv cuab. SDA yog kab lus qhia ob txoj kev. Txhawm rau hloov cov ntaub ntawv, tus tswv xa tawm tus qhev chaw nyob nrog rau ib qho me ntsis nyeem/sau tus chij. Yog tias xav tau kev sau ntawv, tus tswv yuav txuas ntxiv xa cov ntaub ntawv mus rau tus hais lus qhev. Yog tias tau thov nyeem, tus qhev yuav teb nrog cov ntaub ntawv. Txhawm rau sib koom ua lag luam, SCL thiab SDA cov kab tau siv los ntawm tus tswv thiab tus qhev los qhia ntau yam xwm txheej. Cov no suav nrog START, STOP, ACK (lees paub) thiab NAK (tsis lees paub). Cov ncauj lus kom ntxaws ntawm cov xwm txheej no yog cov neeg tsav tsheb ua haujlwm. Qhov tseeb geeks ntawm koj tuaj yeem kawm tag nrho cov ntsiab lus hauv qhov txuas hauv qhov kawg ntawm Cov Lus Qhia no. Qhov kev xav tau hluav taws xob yog yooj yim zoo nkauj. Tus tswv thiab cov qhev yuav tsum siv tib qib rau Vcc, thaj chaw yuav tsum txuas nrog, thiab SCL thiab SDA kab yuav tsum rub mus rau Vcc. Tus nqi ntawm cov neeg tawm tsam rub tawm yog txiav txim siab qhov tseeb los ntawm kev suav raws qhov peev txheej tag nrho ntawm lub npav, tab sis qhov ua tau tuaj yeem zoo nkauj npaum li cas ntawm 1.8K thiab 10K. Kuv pib nrog 5.1K thiab siv qis dua kom txog thaum nws ua haujlwm. Qhov no feem ntau tsis yog teeb meem tshwj tsis yog tias koj muaj cov cuab yeej siv ntau lossis ntev ntawm cov xov hlau ntawm cov khoom. Qhov npe cov ntaub ntawv ntawm I2C npav yog 100Kbits/thib ob. Cov nqi ntawm 400Kbits/thib ob, 1Mbits/thib ob, thiab dhau los ua tau ib yam nkaus, tab sis tsis tau txais kev txhawb nqa los ntawm cov tsav tsheb hauv Cov Lus Qhia no. Txhua I2C cov cuab yeej yuav ua haujlwm ntawm 100Kbits/thib ob. Qhov ATtiny2313 thiab ATmega168 txhua qhov siv I2C npav sib txawv. ATtiny2313 siv Universal Serial Interface (USI) kho vajtse - uas tseem tuaj yeem siv rau SPI npav. ATmega168 tau mob siab kho vajtse rau I2C npav hu ua Two Wire Interface (TWI). Thaum sau cov tsav tsheb, cov kev sib txawv no feem ntau yog pob tshab rau tus neeg siv. Ib qhov sib txawv tseem ceeb yog hauv software: ATmega168 I2C tus tsav tsheb cuam tshuam kev tsav tsheb thaum uas rau ATtiny2313 tsis yog. Qhov no txhais tau tias ATmega168 program tsis tas yuav tos I2C cov ntaub ntawv hloov chaw, tab sis tsuas yog yuav tsum tau tos ua ntej pib lwm qhov kev hloov pauv, lossis kom txog thaum cov ntaub ntawv tuaj txog ntawm kev ua haujlwm nyeem. Cov piv txwv thiab kev sib tham kom ua raws yuav tsum ua kom pom meej. I2C qhov chaw nyob yog 7 qhov ntev, yog li mus txog 127 cov cuab yeej tuaj yeem nyob hauv npav yog tias txhua tus muaj qhov chaw nyob tshwj xeeb. Raws li tau qhia hauv daim duab, 7 qhov chaw nyob me me no tau txav mus rau ib qho me ntsis thiab qhov tsawg kawg yog qhov tseem ceeb tau siv los chij nyeem lossis sau ntawm lub cuab yeej ntawm qhov chaw nyob. Yog li qhov ua tiav qhev qhov chaw nyob yog 8 ntsis byte. Qhov chaw nyob tiag yog ib feem txiav txim sab hauv rau lub cuab yeej thiab tsis tuaj yeem hloov pauv (4 qhov tseem ceeb tshaj plaws), thiab txiav txim ib nrab los ntawm cov khoom uas tuaj yeem txuas nrog cov cuab yeej pin (3 yam tsawg kawg tseem ceeb) uas tuaj yeem txuas siab lossis qis rau teeb tsa qhov chaw nyob tshwj xeeb Suab tsis meej pem, tab sis ib qho piv txwv yuav qhia qhov no meej. PCA8574A cov ntaub ntawv qhia pom tias plaub qhov tseem ceeb tshaj plaws ntawm I2C chaw nyob yuav ib txwm yog 0111. Peb ntu tom ntej yog txiav txim siab los ntawm kev teeb tsa ntawm tus pin AD0, AD1 thiab AD2. Cov pins no tuaj yeem txuas rau hauv av lossis rau qhov muaj txiaj ntsig zoo (5 volts) los sawv cev 0 lossis 1 feem. Yog li thaj tsam ntawm qhov chaw nyob tuaj yeem yog 38 txog 3F hexadecimal, raws li qhia hauv lwm daim duab los ntawm PCA8574 cov ntaub ntawv. Yog li los ntawm kev hloov chaw teeb tsa me ntsis, txog 8 PCA8574 Raws li tuaj yeem nyob ntawm I2C npav tib lub sijhawm. Txhua tus yuav teb rau nws qhov chaw nyob qhev nkaus xwb. Yog tias xav tau ntau qhov chaw nres nkoj I/O xav tau, PCA8574 tuaj yeem siv tau. Tsuas yog qhov sib txawv ntawm PCA8574 thiab PCA8574A yog tias I2C qhev qhov chaw nyob ntawm PCA8574 yog 20 txog 27 hexadecimal. chaw nyob Nyeem cov ntawv cov ntaub ntawv kom zoo thiab nco ntsoov tias qhov chaw nyob qhev yuav ntev 7 ntsis. Nyeem/sau me ntsis yuav tsum raug kho cais. Ib zaug ntxiv, ib qho piv txwv yuav pab tau. Cov ntaub ntawv cov ntaub ntawv rau 24C16 EEPROM peb yuav sim nrog hais tias thawj (qhov tseem ceeb tshaj plaws) plaub qhov chaw ntawm tus qhev yog 1010. Peb qhov tom ntej tuaj yeem txiav txim siab los ntawm A0, A1 thiab A2; tab sis nco ntsoov cov ntaub ntawv tseem suav nrog 24C01 txog 24C08 uas yog EEPROMs me dua. Daim duab los ntawm cov ntaub ntawv qhia pom tias kev teeb tsa ntawm cov chaw nyob no tsis quav ntsej li qhov loj me nce thiab tsis quav ntsej kiag rau 24C16. Ntawd yog, peb qhov kawg tsis muaj teeb meem thiab 24C16 yeej siv tag nrho I2C qhev chaw nyob 50 txog 57 hexadecimal. Qhov chaw nyob ntawm tus qhev yuav tsum hais txog ntu sib txawv hauv 24C16. Thawj 256 bytes nyob ntawm 50h, tom ntej 256 ntawm 51h, thiab ntxiv mus txog 256 kawg ntawm 57h - rau tag nrho 2K bytes. Txij li qhov chaw nyob ntawm PCF8570 RAM peb kuj tau sim nrog hauv qhov no, 24C16 thiab PCF8570 tsis tuaj yeem siv ua ke.

Kauj Ruam 2: xaj qee I2C Devices

Tam sim no koj paub me ntsis txog I2C Bus thiab xav siv nws, vim li cas ho tsis xaj qee cov khoom siv I2C los sim nrog tam sim no kom lawv tuaj yeem ua rau koj thaum koj tab tom tau txais software npaj? Cov cuab yeej tsim nyog suav nrog I/ O Interface Expander (kuv nyiam), Static Ram, thiab EEPROM. Muaj ntau ntau ntxiv, tab sis cov no yog qhov pib zoo. AVR cov txheej txheem peb yuav siv yog ATtiny2313 thiab Atmega168 (siv hauv Arduino). Yog tias koj tshiab rau cov no, tom qab ntawd saib qhov Kev Qhia Zoo no kom kawm paub txog lawv thiab tsim koj li Ghetto Development System. Cov txheej txheem ntawm ATmega168 nyob rau tam sim no Qhia qhia yuav ua li cas siv Ghetto Kev Txhim Kho Txheej Txheem rau cov txheej txheem no. Cov kab hluav taws xob sib txuas sib txuas yog tib yam li ib qho rau ATtiny2313. (Kuv tsis tau sim USB version ntawm Ghetto Development System, yog li kuv tsis paub meej tias I2C npav nkag mus rau nws li cas. Ib yam rau Arduino.) Ntawm no yog Digikey cov lej ib feem. Port Expander: IC I2C I/O EXPANDER 568-4236-5-NDRam: IC SRAM 256X8 W/I2C 568-1071-5-NDEEPROM: IC EEPROM SERIAL 16K CAT24C16LI-G-ND

Kauj Ruam 3: I2C Tsav Tsheb

Nov yog cov lus piav qhia txog kev tsav tsheb rau I2C npav. Cov no tau tsim los siv Atmel Apps Notes rau pib. Kuv tsis tuaj yeem ua qhov no yam tsis muaj lawv ua lub hauv paus los tsim. Kev txhim kho tau ua tiav siv WinAVR thiab gcc C compiler. Kev txwv tus lej teev tau piav qhia hauv qab no rau txhua tus txheej txheem. Txij li thaum kuv tsis tuaj yeem sim txhua qhov kev ua haujlwm tsw / moos tus lej ua ke tau, kuv yuav cia li ua raws li qhov kuv tuaj yeem sim thiab sim qhia qhov txwv thiab txwv. Nov yog tus tsav tsheb ua haujlwm thiab siv lawv li cas. Thov saib cov piv txwv kom paub meej ntxiv thiab pom cov haujlwm hauv kev siv hauv cov haujlwm tiav. Yog tias koj xav khiav ntawm lwm tus nqi, tom qab ntawd koj yuav tsum tau kho qhov tsis sib xws hauv cov tsav tsheb. Email rau kuv yog tias koj xav tau kev pab ua qhov no. Koj kuj tseem tuaj yeem tau txais qee cov lus qhia los ntawm Atmel apps sau tseg hauv kab ntawv txuas hauv Cov Chaw Pabcuam. Hu nws ib zaug thaum pib ntawm koj qhov haujlwm. Nws rov qab tsis muaj dab tsi thiab tsis muaj kev sib cav. Txij li txoj haujlwm no tsuas yog rov ua tus lej yuam kev, kuv siv lub luag haujlwm TWI_Act_On_Failure_In_Last_Transmission (TWIerrorMsg) txhawm rau teeb qhov yuam kev LED. Cov lej yuam kev tau teev tseg hauv USI_TWI_Master.h. Nov yog yuav hu nws li cas: TWI_Act_On_Failure_In_Last_Transmission (USI_TWI_Get_State_Info ()) USI_TWI_Start_Read_Write () Cov haujlwm no yog siv los nyeem thiab sau ib qho bytes rau I2C li. Nws kuj tseem siv los sau ntau bytes. Muaj 6 kauj ruam los siv txoj haujlwm no. 1) Tshaj tawm cov lus tsis nyob hauv koj qhov haujlwm los tuav tus qhev chaw nyob thiab cov ntaub ntawv byte kom xa lossis tau txais. unsigned char messageBuf (MESSAGEBUF_SIZE); 2) Muab qhov chaw nyob qhev ua thawj byte hauv qhov tsis. Hloov nws ib sab laug thiab LOS YOG hauv Nyeem/Sau me ntsis. Nco ntsoov Nyeem/Sau me ntsis yuav yog 1 rau Nyeem thiab 0 rau Kev Sau. Qhov piv txwv no yog rau Nyeem. messageBuf (0) = (TWI_targetSlaveAddress << TWI_ADR_BITS) | (TRUE << TWI_READ_BIT); 3) Thaum ua Kev Sau Ntawv, muab lub byte los sau rau hauv qhov chaw tom ntej hauv qhov tsis. 4) Hu rau USI_TWI_Start_Read_Write ua haujlwm nrog cov lus tsis thiab cov lus loj raws li arguments.temp = USI_TWI_Start_Read_Write (messageBuf, 2); 5) rov qab tus nqi (qhov ntsuas hauv qhov no) tuaj yeem kuaj xyuas seb puas muaj qhov yuam kev tshwm sim. Yog tias yog, nws tau daws raws li tau hais los saum no. Saib cov piv txwv hauv cov khoos phis tawj. 6) Yog xav tau Nyeem ntawv, cov byte nyeem yuav nyob hauv qhov chaw thib ob hauv qhov tsis yog. Yog tias ntau tus bytes yuav tsum tau sau (xws li rau lub cim xeeb ntaus ntawv), tib txoj haujlwm no tuaj yeem siv tau. Teeb tsa qhov tsis thiab hu rau niaj hnub sib txawv me ntsis. Qhov thib ob byte hauv qhov tsis yuav yog qhov pib nco chaw nyob uas yuav sau. Cov ntaub ntawv yuav tsum tau sau yuav nyob hauv bytes tom ntej. Cov lus loj yuav yog qhov loj nrog rau txhua cov ntaub ntawv siv tau. Yog li yog 6 bytes yuav tsum tau sau, tom qab ntawv cov lus yuav yog 8 (chaw nyob qhev + chaw nyob nco + 6 bytes ntawm cov ntaub ntawv). USI_TWI_Start_Random_Read () Cov haujlwm no yog siv los nyeem ntau bytes los ntawm I2C ntaus ntawv, feem ntau nws tsuas yog muaj txiaj ntsig rau nco txog qee yam. Siv cov txheej txheem no zoo ib yam li yav dhau los niaj hnub no, nrog ob qhov tshwj xeeb. Qhov teeb tsa Nyeem/Sau me ntsis tsis muaj teeb meem. Kev hu xov tooj niaj hnub no ib txwm ua rau Nyeem Ntawv Nyeem Ntawv. Qhov lus loj yuav tsum yog 2 ntxiv rau tus lej bytes uas yuav tsum tau nyeem. cov tsav tsheb tau tsim los rau lub moos ntawm 4MHz rau ATmega168. Cov piv txwv qhia pom yuav ua li cas teev tus nqi moos no. Yog tias koj xav khiav ntawm lwm tus nqi, tom qab ntawd koj yuav tsum tau kho qhov tsis sib xws hauv cov tsav tsheb. Email rau kuv yog tias koj xav ua qhov no. TWI_Master_Initialise () Qhov haujlwm no pib TWI kho vajtse rau I2C hom kev ua haujlwm. Hu nws ib zaug thaum pib ntawm koj qhov haujlwm. Nws rov qab tsis muaj dab tsi thiab tsis muaj kev sib cav. Nco ntsoov qhib kev cuam tshuam los ntawm kev hu swi () tom qab pib ua haujlwm. TWI_Get_State_Info () Cov haujlwm no rov qab I2C cov ntaub ntawv yuam kev thiab siv yog tias muaj qhov yuam kev tshwm sim thaum lub sijhawm I2C pauv. Txij li txoj haujlwm no tsuas yog rov ua tus lej yuam kev, kuv siv lub luag haujlwm TWI_Act_On_Failure_In_Last_Transmission (TWIerrorMsg) txhawm rau teeb qhov yuam kev LED. Cov lej yuam kev tau teev tseg hauv TWI_Master.h, tab sis raug hloov kho rau teeb liab ntawm qhov yuam kev LED. Saib cov qauv piv txwv kom paub meej. Nov yog yuav hu nws li cas: TWI_Act_On_Failure_In_Last_Transmission (TWI_Get_State_Info ()) Nco ntsoov tias kev txheeb xyuas yuam kev tau ua tiav los ntawm kev ua kom ntseeg tau tias I2C kev ua lag luam tiav (ua haujlwm hauv qab no) thiab tom qab ntawd ntsuas me ntsis hauv lo lus xwm txheej thoob ntiaj teb. TWI_Start_Read_Write () TWI_Start_Random_ead ob lub luag haujlwm ua haujlwm zoo ib yam li cov haujlwm uas tau piav qhia saum toj no tab sis nrog qee qhov kev zam. Lawv tsis xa rov qab ib qho yuam kev qhov tseem ceeb. Data nyeem tsis raug pauv mus rau qhov tsis. Ua qhov no yuav ua tiav nrog cov haujlwm piav qhia tom ntej. Thaum hu rau TWI_Start_Random_Read, cov lusSize yuav tsum yog tus lej ntawm cov ntaub ntawv bytes thov ntxiv rau ib qho, tsis yog ob qho. I2C tus tsav tsheb rau ATmega168 yog cuam tshuam tsav. Ntawd yog, I2C kev sib pauv tau pib thiab tom qab ntawd ua nws tus kheej thaum lub sijhawm tseem ceeb tseem ua haujlwm. Thaum txoj haujlwm tseem ceeb xav tau cov ntaub ntawv los ntawm kev sib pauv I2C uas nws tau pib, nws yuav tsum txheeb xyuas seb puas muaj cov ntaub ntawv muaj. Qhov xwm txheej yog tib yam rau kev txheeb xyuas yuam kev. Cov txheej txheem tseem ceeb yuav tsum paub tseeb tias I2C kev ua lag luam tiav ua ntej kuaj xyuas qhov ua yuam kev. Ob txoj haujlwm tom ntej no tau siv rau cov hom phiaj no. TWI_Transceiver_Busy () Hu rau lub luag haujlwm no kom pom tias I2C kev ua lag luam tiav ua ntej kuaj xyuas qhov ua yuam kev. Cov piv txwv cov phiaj xwm qhia yuav siv li cas. TWI_Read_Data_From_Buffer () Txoj haujlwm no yuav ua kom ntseeg tau tias I2C kev ua lag luam tiav ua ntej xa cov ntaub ntawv. Thaum tus nqi raug xa rov qab los ntawm txoj haujlwm no, Kuv pom tshawb xyuas qhov yuam kev me ntsis kom ntseeg tau ntau dua. Nov yog hu li cas. Cov lus Loj yuav tsum yog ib qho ntau dua li cov lej ntawm cov ntaub ntawv xav tau. Cov ntaub ntawv yuav nyob hauv messageBuf pib ntawm qhov chaw thib ob.temp = TWI_Read_Data_From_Buffer (messageBuf, messageSize);

Kauj ruam 4: Cia Peb Tsim

Cia Tsim!
Cia Tsim!
Cia Tsim!
Cia Tsim!
Cia Tsim!
Cia Tsim!
Cia Tsim!
Cia Tsim!

Pib los ntawm rub tawm cov ntawv I2C Schematics.zip. Tej zaum koj yuav xav tsim I2C nplaub tshev hauv koj thaj chaw ua haujlwm kom tuav cov lej thiab piv txwv cov ntawv program. Unzip cov schematics rau hauv phau ntawv no. Koj yuav pom daim nplaub tshev hu ua I2C Schematics. Qhib cov ntaub ntawv npe me me I2C.pdf. Cov phiaj xwm no qhia txog ATtiny2313 Ghetto Development System, thiab PCA8574A I/O Port Expander (muaj lub thawv loj dashed ncig nws). Qhov Chaw Txuas Hluav Taws Xob Chaw Nres Nkoj tau tsim rau ntawm lub khob cij. Ua tibzoo saib cov duab kom pom cov voj voog no zoo li cas. Lawv nyob ntawm qhov yooj yim zoo nkauj. Qhov ATtiny2313 ib feem ntawm cov phiaj xwm tsuas yog Ghetto Kev Tsim Kho nrog peb lub teeb ci (LED1, 2, thiab 3, ntxiv rau R4, 5, thiab 6) thiab lub laub khawm (S1) txuas rau nws, ntxiv rau nthuav dav ntxiv. Cov ncauj lus kom ntxaws yog qhov ntxiv ntawm cov dhia (JP4, 5, thiab 6) uas tuaj yeem raug tshem tawm kom tso cai txuas I2C npav SCL thiab SDA kab. Cov dhia yuav tsum nyob hauv qhov chaw rau kev ua haujlwm, tom qab ntawd tshem tawm kom SCL thiab SDA tuaj yeem txuas nrog. Cov duab qhia cov dhia dhia hauv qhov chaw thiab tshem tawm. Qhov chaw ntawm cov dhia no yog nyob ntawm koj, koj tsuas yog yuav tsum muab lawv tso rau hauv koj li Ghetto Development System yog tias koj xav siv I2C npav. Lub tsheb npav I2C yuav tsum raug txuas nrog thiab cov neeg dhia dhia tau muab tso rau qhov chaw rau kev ua haujlwm. Nco ntsoov tias koj tsuas yog yuav tsum tau txhawj xeeb nrog JP4 thiab JP6 rau I2C npav. Muab tso rau hauv JP5 yog tias koj xav tias koj yuav xav siv lub npav SPI. Ua daim ntawv qhia zaub mov PCA8574A I/O Port Expander yog yooj yim heev. Muab Vcc (+5 volts) thiab Gnd (hauv av) txuas thiab txuas AD0, 1, thiab 2 rau hauv av (ua rau I2C qhev chaw nyob 38 hex). Tom qab ntawd txuas 4 blinkenlights, thiab 4 DIP keyboards. (Yog tias koj tsis muaj DIP hloov pauv koj tuaj yeem siv cov xov hlau xwb. Tie rau hauv av lossis tawm ntab mus rau teeb liab rau lossis tawm ib feem.) Thaum kawg, txuas lub rub tawm tus tiv thaiv (R11 thiab 12) los ntawm SDA thiab SCL rau Vcc. Cov no tau qhia ua 3.3K, tab sis ib qho txiaj ntsig los ntawm 1.8K txog 5.1K yuav tsum ua haujlwm (tej zaum mus txog 10K tab sis kuv tsis tau sim qhov ntawd). Thaum koj tau npaj cov ATtiny2313 koj tuaj yeem tshem cov dhia thiab txuas SDA thiab SCL rau kev sim tam sim no rau ATmega168. Tsuas yog qhov me me ntawm no yog qhov uas koj yuav tsis tau tsim Ghetto Kev Tsim Kho Txheej Txheem rau cov txheej txheem no. Yog tias yog qhov xwm txheej, tom qab ntawd cov txheej txheem kuv muab (MEGA I2C.pdf) yuav qhia koj li cas. Qhov no tsuas yog kev tso cai ntawm ATtiny2313 version. Yog tias koj npaj ua ntej koj tuaj yeem ua kom ntseeg tau tias koj cov phiaj xwm cable yuav haum rau ob lub system. Qhov sib txawv tseem ceeb yog qhov sib ntxiv ntawm C2 thiab C3. Saib cov duab rau kev tso rau ntawm cov no, lawv yuav tsum nyob ze rau ntawm lub nti; ib ntawm lawv yog qhov tseeb hauv qab nti. Cov no pab ua kom nrov nrov tawm ntawm qhov sib piv rau cov hloov pauv tshwj xeeb. Koj tsis tas yuav tso cov neeg dhia dhia tshwj tsis yog koj npaj yuav siv SPI tsheb npav vim tias lawv tsis xav tau rau I2C tsheb npav ntawm cov nti no. Nco ntsoov tias PCA8754A breadboard yuav tsis hloov pauv. Koj tsuas yog nqes SDA thiab SCL thiab koj mus! Yooj yim, huh?

Kauj Ruam 5: Cia Txoj Cai thiab Xeem

Cia Code thiab Xeem!
Cia Code thiab Xeem!
Cia Code thiab Xeem!
Cia Code thiab Xeem!
Cia Code thiab Xeem!
Cia Code thiab Xeem!

Nws yog lub sijhawm los tsim cov tsav tsheb thiab cov piv txwv cov haujlwm. Peb yuav pib nrog ATtiny2313 thiab PCA8574A breadboard uas peb nyuam qhuav ua. Rub tawm cov ntawv I2C.zip rau hauv koj phau ntawv teev npe I2C thiab unzip nws. Koj yuav muaj daim nplaub tshev tshiab hu ua I2C. Hauv nws koj yuav pom USI I2C (rau ATtiny2313) thiab TWI I2C (rau ATmega168). Hauv USI I2C, koj yuav pom I_O Port folder. Lub nplaub tshev ntawd muaj cov cai rau peb thawj qhov kev pabcuam, thiab USI I2C cov tsav tsheb. Ua haujlwm WinAVR, suav sau thiab thauj cov cai rau hauv ATtiny2313. Ua pa tob tob thiab tig lub zog. Nov yog qhov yuav tsum tau: Ntawm lub zog ntawm, LED 1 ntawm chaw nres nkoj PD6 ntawm ATtiny2313 ntsais muag ob zaug. Koj tsis muaj dab tsi ntxiv yuav tshwm sim txog thaum koj nias lub pob (S1). Txhua lub sijhawm nyem lub pob, cov hloov pauv tau nyeem thiab lawv teeb tsa yuav tshwm ntawm LEDs txuas nrog PCA8574A. Hloov tus nqi ntawm cov hloov pauv, nias lub pob, thiab LEDs yuav tsum hloov pauv. Ua qhov no kom txog thaum koj dhau qhov zoo siab pom nws ua haujlwm. Yog (Vajtswv txwv!) Tej yam tsis ua haujlwm raws li xav tau, ua tib zoo tshuaj xyuas koj cov xov hlau. I2C qhov tsis raug yuav raug teeb tsa los ntawm qhov ntsais ntawm LED3 (PD4) thiab tej zaum txhais tau tias koj yuav tsum tau txheeb xyuas tias SDA thiab SCL txuas nrog tus pin raug thiab raug rub kom raug. Yog hais tias tej yam tseem tsis ua haujlwm, nyeem seem ntawm ntu no kom kawm paub txog kev debug. Ntawm no rov qab mus thiab saib qhov chaws. Qhib cov ntaub ntawv USI_I2C_Port.c. Nov yog txoj cai rau qhov piv txwv program. (USI_TWI_Master.c thiab USI_TWI_Master.h muaj cov tsav tsheb - koj tuaj yeem tsis quav ntsej lawv tshwj tsis yog koj xav paub.) Siv tus piv txwv los coj koj tus kheej I2C daim ntawv thov. Feem ntau, txoj haujlwm qhia koj yuav pib li cas thiab siv I2C cov tsav tsheb, suav nrog nce tus qhev chaw nyob thiab seem ntawm cov lus tsis, thiab tau txais cov ntaub ntawv tawm ntawm nws. Koj tseem yuav pom yuav ua li cas kuv debounce lub pob thiab teeb tsa lub voj. Muaj qee qhov ntsiab lus ntawm txoj haujlwm tsim nyog hais txog. Nco ntsoov tias cov ntaub ntawv los ntawm cov hloov pauv tau hloov ua ntej nws tau sau rau LEDs ntawm Chaw Nkoj Nkoj. Tsis tas li nco ntsoov tias cov tswv yim nkag ntawm Chaw Nkoj Nkoj yuav tsum tau sau ua siab kom ua haujlwm kom raug. Cov ntsiab lus no tau piav qhia hauv PCA8574A cov ntaub ntawv. Ib txwm nyeem cov ntawv txheeb xyuas kom zoo! Ntawm kev txaus siab ntau dua yog kev siv debugging raws li txoj cai. Nyob ze qhov pib ntawm qhov program cov ntaub ntawv yog nqe lus // #txhais DEBUG thiab nphoo tag nrho cov cai yog #ifdef DEBUG nqe lus. Tsuav DEBUG tsis tau hais tseg (ob qhov slashes ua kab lus tawm tswv yim thiab khaws nws los ntawm kev txhais), cov cai hauv #ifdef rau #endif nqe lus yuav tsis raug suav ua. Tab sis yog tias txhua yam tsis ua haujlwm raws li koj xav tau, rov sau dua thiab rov ua qhov chaws nrog #define DEBUG tsis ua raws. Koj yuav tau txais ntau qhov ntsais ntsais ntawm LEDs uas koj tuaj yeem txiav txim siab ua raws qhov kev ua tiav ntawm koj qhov haujlwm thiab pab koj nrhiav qhov tseeb qhov twg mus tsis raug. Qhov tseeb, kuv qhia koj sim qhov no tsuas yog pom tias muaj dab tsi tshwm sim. Dab tsi koj yuav pom yog tias LED 2 (ntawm PD5) yuav ntsais thaum ua tiav kev nce qib los ntawm txoj haujlwm. Tus nqi nyeem los ntawm cov hloov pauv yuav ntsais muag ntawm LED 1 (PD6) ua ntej nws tau tshwm rau ntawm LED Chaw Nres Nkoj. Koj yuav tsum muaj peev xwm taug qab txoj haujlwm raws li nws siv los ntawm kev siv cov LEDs. Peb yuav ua haujlwm nrog ATmega168 tom ntej; hla ntu no yog tias koj tsuas yog txaus siab rau ATtiny2313. Tseem nrog kuv? Zoo. Tsiv mus rau TWI_I2C nplaub tshev, hloov koj cov npe ua haujlwm rau IO_Port, thiab suav sau thiab thauj khoom TWI_I2C_Port.c rau hauv ATmega168. Txiav tawm SDA thiab SCL kab los ntawm ATtiny2313 thiab txuas lawv rau ATmega168. Tsaug zog thiab av, thiab txhawb zog. Kev ua haujlwm yuav tsum zoo ib yam! Ua si kom txog thaum qhov kev txaus siab tso tseg, tom qab ntawd cia saib lub chaws. Kuv qhib TWI_I2C_Port.c. Txoj cai yuav luag zoo ib yam tshwj tsis yog ua yuam kev thiab ua kom cuam tshuam cuam tshuam cov tsav tsheb. Nov yog qhov sib txawv: Nco ntsoov tias lub moos yuav tsum tau teeb tsa 4MHz rau I2C npav kom ua haujlwm tau zoo. Se (); nqe lus tig rau cuam tshuam tom qab pib ua I2C cov tsav tsheb. Txhawm rau txheeb xyuas qhov ua tsis raug, qhov xwm txheej tshwj xeeb tau kuaj. Thaum nyeem, TWI_Read_Data_From_Buffer muaj nuj nqi yuav tsum raug hu kom hloov cov ntaub ntawv nyeem rau hauv cov lus tsis. Thaum sau ntawv, thaum (TWI_Transceiver_Busy ()) yuav tsum tau siv kom ntseeg tau tias kev hloov pauv tiav ua ntej kuaj xyuas qhov ua tsis raug. Ob qhov haujlwm kawg no tau piav qhia saum toj no hauv kev piav qhia ntawm cov tsav tsheb. Lwm yam tshaj li ntawd, cov cai zoo ib yam li rau ATtiny2313. DEBUG ua haujlwm ib yam nkaus thiab yog tias koj xav sim nrog qhov ntawd.

Kauj Ruam 6: Siv I2C Nco

Siv I2C Nco
Siv I2C Nco
Siv I2C Nco
Siv I2C Nco
Siv I2C Nco
Siv I2C Nco
Siv I2C Nco
Siv I2C Nco

Tam sim no peb tau kawm siv lub npav I2C los nyeem thiab sau I/O Port Expander, cia peb txav mus siv I2C nco, ob qho tib si RAM thiab EEPROM. Qhov sib txawv tseem ceeb yog tias ntau bytes tuaj yeem nyeem lossis sau los ntawm kev nco nrog ib zaug I2C hais kom ua. Txhawm rau npaj rau cov kev sim no, peb yuav tsum hloov kho kho vajtse me ntsis thiab tsim ob peb qhov kev hloov pauv tshiab ntawm lub khob cij. Khaws Chaw Nres Nkoj Chaw Nkoj txij li peb yuav siv nws los tso saib qee qhov cim xeeb. Tshem lub DIP hloov pauv los ntawm PCA8574A thiab tso lub teeb ntsais ntawm cov koob ntawd. Yog tias koj tsis muaj lub teeb ci txaus, txav qhov ntawm P4 txog P7 hla mus rau P0 txog P3. (Qhov muaj txiaj ntsig los tso tawm yog qhov me me txaus.) Tam sim no saib cov txheej txheem I2C Ram.pdf thiab txuas tus PCF8570 ntawm lub khob cij. Saib daim duab no thiab. Nco ntsoov khi tus pin 7 rau Vcc. Siv cov xov hlau rau SDA thiab SCL los ntawm PCA8574A. Tsis tas yuav tsum muaj tus tiv thaiv rub tawm ntxiv yog tias koj tseem txaus siab rau EEPROM, tsim qhov kev sib txuas no tseem siv I2C EEPROM.pdf rau 24C16, tab sis ceeb toom tias piv txwv siv ATmega168. Qhov Circuit Court no yooj yim heev. Raws li tau hais los saum toj no, cov chaw nyob yuav tsum tsis quav ntsej. Tsuas yog txuas lub zog thiab hauv av. Tsis txhob txuas SDA thiab SCL tsuas yog txij li peb tseem tsis tau ua tiav kev sim nrog Ram. Peb yuav pib peb qhov kev sim sim nrog ATtiny2313 txuas nrog PCA8574A Port Expander thiab rau PCF8570 Ram. Qhov kev zov me nyuam yuav sau qee tus lej mus rau Ram, tom qab ntawv nyeem lawv rov qab thiab tso tawm rau ntawm Chaw Nres Nkoj Hloov pauv koj cov npe ua haujlwm rau RAM raws li USI I2C. Siv cov ntawv ua los ua ke thiab rub tawm USI_I2C_RAM.c. Nco ntsoov tias cov ntaub ntawv tsav tsheb I2C zoo ib yam rau cov uas peb tau siv ua ntej. Nqa lub zog thiab koj yuav tsum pom ib qho ntsais ntawm LED 1 (PD6). Cov ntaub ntawv yuav raug sau rau thawj 4 bytes nco. Nias lub pob thiab ob bytes yuav rov nyeem thiab tso tawm. Koj yuav tsum pom ib lub teeb ci LED ntawm Chaw Nres Nkoj Nkoj (P0), ob ncua sijhawm thib ob, tom qab ntawd ob lub teeb ci LED (P0 thiab P1). Lwm qhov ob ncua sijhawm thib ob thiab LEDs yuav tsum tua. Nias lub pob dua kom pib ua ntu zus. Kev debugging zoo ib yam li cov txheej txheem tau piav qhia saum toj no. Qhib USI_I2C_RAM.c. Nws yuav tsum zoo li zoo ib yam li cov cai dhau los. Qhov sib txawv tseem ceeb yog cov ntsiab lus ntawm kev nyeem thiab sau kev nco. Saib ntawm txoj hauv kev uas cov ntawv tsis raug thauj khoom ua ntej qhov kev hu uas ua tau tiag tiag sau. Thawj byte yog tus qhev nyob nrog kev nyeem/sau me ntsis teeb tsa kom tsim nyog. Tab sis tom ntej byte yog qhov chaw nyob nco uas pib sau cov ntaub ntawv. Tom qab ntawd los qhov tseeb cov ntaub ntawv bytes uas yuav raug xa mus rau hauv lub cim xeeb pib ntawm qhov chaw nyob uas peb tau teev tseg. Peb hais qhia cov lus me me li 6. Yog li peb pib sau ntawv ntawm chaw nyob 00 thiab sau qhov tseem ceeb 01, 03, 02 thiab 06 rau hauv qhov chaw nco 00 txog 03. Txhawm rau nyeem cov ntaub ntawv rov qab los ntawm lub cim xeeb peb yuav tsum siv USI_TWI_Start_Random_Read ua haujlwm. Cov lus tsis tau txais tus qhev qhov chaw nyob hauv thawj byte thiab qhov chaw nyob pib hauv ob byte. Tom qab ntawd hu lub luag haujlwm nrog cov lus me me teeb tsa rau tus lej bytes los nyeem ntxiv 2. Nco ntsoov tias kev nyeem/sau me ntsis tsis muaj teeb meem txij li kev nyeem yuav ua tiav tsis hais yam twg. Cov ntaub ntawv xa rov qab yuav pib hauv qhov chaw thib ob hauv cov lus tsis. Thaum cov ntaub ntawv raug nyeem hauv, nws tau ntxeev rau tso saib ntawm Chaw Nkoj Nkoj thiab sau ib byte ntawm ib lub sijhawm rau nws nrog ncua ntawm qhov txiaj ntsig. Thaum kawg, Qhov Chaw Txuas Hluav Taws Xob LEDs raug tua. Cov ntawv sau mus rau Chaw Nkoj Nkoj Nkoj yog qhov zoo ib yam rau qhov tau ua hauv cov piv txwv dhau los. Txhawm rau lom zem, koj tuaj yeem tsis txaus siab rau #define DEBUG nqe lus saum toj no thiab pom ntau qhov ntsais ntsais LEDs. Hloov koj cov npe ua haujlwm rau EEPROM hauv qab TWI I2C. Siv cov ntawv ua los sau thiab rub tawm TWI_I2C_EEPROM.c. Nco ntsoov tias cov ntaub ntawv tsav tsheb I2C zoo ib yam rau cov uas peb siv ua ntej rau PCA8574A. Txhawm rau sim qhov program, tshem tawm ATtiny2313 thiab txuas ATmega168. Tawm ntawm I2C lub tsheb npav mus rau Ram thiab txuas lub zog. Cov txiaj ntsig tau sib txawv txij li tam sim no peb tab tom sau thiab nyeem cov ntaub ntawv ntau ntxiv. LED 1 ntawm PD7 yuav tsum ntsais thaum pib. Nias lub pob thiab cov ntaub ntawv yuav rov qab los ntawm lub cim xeeb thiab nthuav tawm. Cov LEDs ntawm PCA8574 yuav tsum ntsais cov kab hauv qab no: P1, P0 & P2, (tag nrho tawm), P0 & P1, P1 & P2. Thaum kawg Ports LEDs yuav tsum tawm mus. Nias lub pob dua kom rov ua qhov no. Oh, tab sis tos, koj hais. Puas yog txoj haujlwm no rau EEPROM? Txij li thaum peb tab tom nkag mus rau lub cim xeeb ntaus ntawv ntawm tib I2C chaw nyob, tib txoj haujlwm ua haujlwm rau ob qho tib si Ram thiab EEPROM. Fais fab thiab txav SDA thiab SCL los ntawm Ram mus rau EEPROM thiab rov ua haujlwm dua. Nws yuav tsum ua haujlwm zoo ib yam nkaus. Nco ntsoov tias EEPROM thiab Ram tsis tuaj yeem txuas nrog I2C tsheb npav tib lub sijhawm vim lawv sib koom tib qhov chaw nyob. (Cov neeg ntse ntawm koj tuaj yeem txiav txim siab hloov qhov programmable chaw nyob ntawm Ram, tab sis qhov ntawd tseem yuav tsis ua haujlwm. 24C16 siv tag nrho cov block ntawm qhov chaw nyob uas tuaj yeem ua haujlwm rau Ram.) OK, cia saib ntawm qhov program kawg no.. Qhib TWI_I2C_EEPROM.c. Thawj qhov uas yuav tsum tau ceeb toom yog tias kuv tau hais qhia yuav ua li cas thiaj ua tiav 24C16 EEPROM. Nws tuaj yeem nkag mus rau hauv 256 byte chunks ntawm 8 qhov sib txawv I2C qhev chaw nyob. Saib yuav ua li cas MEMORY_ADDR tau txhais tias yog qhov chaw nyob pib ntawm 50 hexadecimal; yog vim li cas Ram ua haujlwm. Yog tias koj xav nkag mus rau lwm qhov thaiv ntawm 24C16, tom qab ntawd siv lwm qhov chaw nyob raws li kuv tau hais tseg. Saib seb kuv teeb tsa los sau rau hauv lub cim xeeb li cas. Ua ntej tus qhev nyob nrog nyeem/sau me ntsis teeb tau muab tso rau hauv qhov tsis, tom qab ntawd pib qhov chaw nyob ntawm 00, tom qab ntawd 16 bytes ntawm cov ntaub ntawv. Kev ua haujlwm TWI_Start_Read_Write raug hu los sau cov ntaub ntawv (zoo li ua ntej) nrog cov lus me me teeb tsa rau 18. Thaum lub pob nyem, peb siv TWI_Start_Random_Read thiab TWI_Read_Data_From_Buffer los nyeem cov ntaub ntawv rov qab. Txhua qhov thib peb byte tau nthuav tawm ntawm LEDs Chaw Nres Nkoj. Thaum kawg, LEDs raug kaw kom tos lub pob nyem tom ntej. Koj yuav xav tsis thoob vim li cas kuv thiaj xaiv los sau 16 bytes. Yog tias koj nyeem cov ntawv cov ntaub ntawv kom zoo, koj yuav pom tias 24C16 sau lub voj voog thaum twg nws tau txais 16 bytes txawm tias ntau bytes raug xa mus. Yog li ntawd zoo li tus lej zoo siv. Yog tias koj xaiv nce qhov no, koj yuav tau hloov qhov MESSAGEBUF_SIZE qhov loj me. Koj tseem yuav tau hloov tus nqi TWI_BUFFER_SIZE hauv TWI_Master.h. Qhov no yog vim tus neeg tsav tsheb luam cov ntaub ntawv los ntawm cov lus tsis siv rau los ntawm kev cuam tshuam kev pabcuam niaj hnub. Nrog koj zoo siab! Tam sim no koj tau npaj siv I2C npav hauv koj tus kheej cov phiaj xwm!

Kauj Ruam 7: Web Resources

Nov yog cov kev txuas mus rau cov ntawv teev tseg rau cov khoom siv rau kev sim. Koj yuav tsum tau txais cov no yog tias koj tsis tau txais lwm yam. Port ExpanderRamEEPROM (Lawv nyiam siv cov lej sib dhos hauv lawv qhov URL, yog li kuv tsis tuaj yeem suav nrog lawv nyob ntawm no. Thov txim.] Txhawm rau mus rau thaj chaw I2C, xaiv Kev Sib Txuas los ntawm Cov Khoom Sau. nkag mus rau txhua cov ntaub ntawv teev tseg thiab cov ntawv sau tseg uas lawv muab. I2C cov lus piav qhia hauv tsheb npav thiab cov lus qhia tshwj xeeb yog nyob ntawm no. Tau txais ATtiny2313 thiab ATmega168 cov ntawv teev tseg (cov ntaub ntawv phau ntawv?) los ntawm Atmel. Atmel daim ntawv thov sau tseg ntawm no. Saib AVR310 thiab AVR315. Tau txais cov cai thiab.

Kauj Ruam 8: Sau rau Geeks

Txog qhov geek tseeb uas xav paub cov ntsiab lus, ntawm no yog qee yam yuav tsum nco ntsoov yog tias koj saib ntawm Atmel Apps Cov Lus Cim thiab tus lej tsav tsheb:- Txoj hauv kev hais thiab hais kom ua I2C cov cuab yeej tsis yog ib feem ntawm qhov tshwj xeeb! Lwm yam tshaj li tus qhev nyob thiab nyeem/sau me ntsis, lus txib, hom, thiab lwm yam tsis tau hais tshwj xeeb thiab tshwj xeeb rau ib qho khoom siv. Txhawm rau ua qhov no kom meej, nco ntsoov tias cov phiaj xwm siv hauv Atmel piv txwv tsuas yog siv rau qhov piv txwv ntawd, thiab zoo nkauj npaum li tsis yog tus qauv. + Nrog USI, kev ntsuas moos tau muab los ntawm software; nrog TWI nws tau muab los ntawm Tus Nqi Tus Nqi Generator. + Txoj kev USI tsis siv cuam tshuam; the TWI. Qhov no ua rau muaj kev nkag siab zoo txij li Mega tsev neeg (siv TWI) tuaj yeem ua ntau yam ntxiv thiab yuav tsum tsis txhob cuam tshuam los ntawm I2C hloov chaw. Kev cuam tshuam kev cuam tshuam uas tau tsav rau USI yeej ua tau, nws tsuas yog tsis tau ua tiav hauv Cov Lus Qhia no. + USI kho vajtse tsis zoo rau I2C thiab tuaj yeem ua haujlwm tsuas yog 8 qhov hloov pauv. Qhov no txhais tau tias ob qhov kev hloov pauv yuav tsum tau xa tus thib cuaj (xws li NACK lossis ACK). TWI kho vajtse ua haujlwm qhov no tau txais. Qhov no ua rau USI kev siv tsav tsheb nyuaj me ntsis. + Kev txheeb xyuas qhov yuam kev rau TWI tau ua haujlwm hauv kho vajtse. USI yuav tsum tau tuav hauv software uas ua rau qee yam nyuaj. + TWI kho vajtse tswj kev teeb tsa ntawm chaw nres nkoj ncaj qha. USI kho vajtse xav kom cov khoom me me tau teeb tsa ua ntej qhov chaw nres nkoj tuaj yeem siv tau. Koj yuav pom qhov no hauv Master_Initialize niaj hnub rau USI.- Atmel hais tias nws muaj peev xwm siv AVR chaw nres nkoj rub-ups rau I2C tsheb npav rub. Kuv tsis tau nrhiav ib txoj hauv kev kom txoj hauv kev ntawd ua haujlwm. Siv ob sab nraud sab nraud zoo li cov phiaj xwm yooj yim zoo nkauj, yog li kuv tsis siv sijhawm ntau ntawm qhov no.

Pom zoo: