<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=2044&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2013-01-06T18:43:54+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=2044&amp;mode</id>
<entry>
<author><name><![CDATA[p_zag]]></name></author>
<updated>2013-01-06T18:43:54+01:00</updated>
<published>2013-01-06T18:43:54+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23670#p23670</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23670#p23670"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23670#p23670"><![CDATA[
Witam<br />Jak by kogoś interesował ten temat to na stronie <a href="http://www.mikrocontroller.net/topic/87597#new"  class="postlink">http://www.mikrocontroller.net/topic/87597#new</a> jest ciekawy artykuł o nazwie &quot;AVR TWI Master und Slave Funtionen in C&quot;, co prawda po niemiecku, ale z pomocą tłumacza z goole.pl można co nie co zrozumieć. Tu jest źródełko -&gt; &quot;TWI_Master-Slave_C_Functions.zip&quot; właśnie z tej strony.<br />Dla tych co lubią asemblera też coś się znajdzie <a href="http://www.mikrocontroller.net/topic/31404#new"  class="postlink">http://www.mikrocontroller.net/topic/31404#new</a> -&gt; &quot;TWI / I2C einf. MASTER SLAVE Beispiel(Assembler) ATmega8&quot;, ale i tu też jest coś w języku C.<br /><br />Piotr<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=539">p_zag</a> — 6 sty 2013, o 18:43</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2013-01-06T09:08:19+01:00</updated>
<published>2013-01-06T09:08:19+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23587#p23587</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23587#p23587"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23587#p23587"><![CDATA[
<div class="quotetitle">krafin napisał(a):</div><div class="quotecontent"><br />........ oraz podobne nabiera się bardzo złych nawyków.<br /></div><br /><br />Na prawdę chodziło mi tylko o to aby właśnie zaskoczyć o co u nas chodzi <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> cieszę się i dlatego myślę, że dalej już wszystko będzie dobrze.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 6 sty 2013, o 09:08</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[krafin]]></name></author>
<updated>2013-01-06T00:40:33+01:00</updated>
<published>2013-01-06T00:40:33+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23572#p23572</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23572#p23572"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23572#p23572"><![CDATA[
Bardzo przepraszam, ale naprawdę nie chodziło mi o pokazanie jaki jestem mądry, czy co gorsza o obrażanie kogoś.<br />Po prostu &quot;nie wyczułem&quot; jeszcze atmosfery tego forum, a czytając forum elektroda.pl oraz podobne nabiera się bardzo złych nawyków.<br /><br />Dlatego jeszcze raz bardzo przepraszam.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=487">krafin</a> — 6 sty 2013, o 00:40</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-01-05T11:50:29+01:00</updated>
<published>2013-01-05T11:50:29+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23434#p23434</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23434#p23434"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23434#p23434"><![CDATA[
p_zag  - dzięki wielkie za podzielenie się kodem. generalnie też tego szukałem żeby jak to ująłeś &quot;skorzystać z gotowych klocków&quot; bo moja wiedza na temat C nie jest na poziomie żeby samemu zrobić z datasheeta biblioteki!!!<br />Tak, że jeszcze raz dzięki wielkie:)<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 5 sty 2013, o 11:50</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[p_zag]]></name></author>
<updated>2013-01-05T00:13:49+01:00</updated>
<published>2013-01-05T00:13:49+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23405#p23405</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23405#p23405"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23405#p23405"><![CDATA[
Ups!....<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=539">p_zag</a> — 5 sty 2013, o 00:13</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2013-01-05T00:04:50+01:00</updated>
<published>2013-01-05T00:04:50+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23400#p23400</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23400#p23400"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23400#p23400"><![CDATA[
p_zag ---&gt; czy ty przypadkiem nie zrozumałeś TOTALNIE opacznie tych uwag???? przecież skierowałem je do autora tego postu (TYLKO do niego) czyli do kolegi krafin. Więc co ty piszesz ??? jakie gromy na ciebie ??? eeeh <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 5 sty 2013, o 00:04</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[p_zag]]></name></author>
<updated>2013-01-05T01:17:52+01:00</updated>
<published>2013-01-05T00:02:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23399#p23399</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23399#p23399"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23399#p23399"><![CDATA[
No i posypały się gromy na mnie. No, cóż ja też jestem początkujący, języka C uczyłem się sam z internetu a na ile go umiem - to jet dobre pytanie. Kiedyś potrzebowałem komunikacji między atmegami przez TWI to szukałem, szukałem, i szukałem aż znalazłem to co wyżej opublikowałem i co mi zadziałało, więc podzieliłem się tym co znalazłem, kto potrzebuje to skorzysta, kto chce na podstawie noty katalogowej sam dochodzić jak stworzyć komunikacje to proszę bardzo to czynić. Ja procedury z tych bibliotek traktuje jak &quot;gotowe klocki lego&quot; i je dla własnych potrzeb zestawiam nieco je modyfikując. I z nich buduje komunikację na szynie TWI. Z pliku &quot;General.h&quot; używam tylko [syntax=c]#define TRUE    1<br />#define FALSE   0[/syntax]resztę usuwam, a zamieściłem ten plik , bo był w komplecie. Nigdy nie twierdzę, że jestem mądrzejszy od szanownych kolegów, wręcz przeciwnie sam potrzebuje pomocy, dlatego bardzo bym był ciekawy poradnika video o magistrali TWI &quot;od a do z&quot;.<br /><br />Piotr<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=539">p_zag</a> — 5 sty 2013, o 00:02</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[krafin]]></name></author>
<updated>2013-01-04T22:20:33+01:00</updated>
<published>2013-01-04T22:20:33+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23378#p23378</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23378#p23378"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23378#p23378"><![CDATA[
Bardzo nie podoba mi się w pliku General.h ta struktura, zabiera ona niepotrzebnie miejsce we flashu, więc można to spokojnie odrobinkę przerobić.<br /><br />Po 2 to co rozumiesz poprzez słowo poradnik na temat i2c <img src="https://forum.atnel.pl/images/smilies/icon_e_confused.gif" alt=":?" title="Boi się" /><br />Bo napisać kilka funkcji typu send_i2c(), receive_i2c(), init() itp. to i <span style="color: #FF0000">przy[....cenzura.... mirekk36 ... hola hola panie kolego - tu u nas na forum trochę inne zasady panują ok? .... ] </span>napisze wg noty procesora a można je spokojnie &quot;scalić&quot; z bibliotekami uartu (mam na myśl zastosowanie np. buforu cyklicznego itp.)<br />Ja bardziej byłbym właśnie za poradnikiem odbioru - nadawania pomiędzy prockami (chodzi mi o to jak napisać protokół transmisji, ew. zadbać o brak przekłamań np CRC).<br /><br /><span style="color: #FF0000">[uwaga! celem tego forum nie jest pokazywanie jaki to ja jestem mądry .... tu wchodzą początkujący dla których - może być to problem i to poważny. więc zamiast pisać takie rzeczy - lepiej jest pomóc i np pokazać taki kod napisany własnymi łapkami, jakiś poradnik zrobić na forum]</span><br />Bo właśnie napisanie kodu wg. noty kat. to żaden problem, ale zadbanie o to aby było to uniwersalne, szybkie , spójne jest rzeczą trudniejszą.<br /><br /><br /><span style="color: #FF0000">[ bardzo proszę i gorąco kolegę - o dostosowanie wypowiedzi do tonu naszego forum OK - tylko to się u nas najbardziej liczy i tak już zostanie na zawsze - dobrze ? ]</span><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=487">krafin</a> — 4 sty 2013, o 22:20</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[p_zag]]></name></author>
<updated>2013-01-04T21:12:38+01:00</updated>
<published>2013-01-04T21:12:38+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23366#p23366</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23366#p23366"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23366#p23366"><![CDATA[
Witam.<br /><div class="quotetitle">developer85 napisał(a):</div><div class="quotecontent"><br />Czy ktoś z szanownych kolegów robił może już taką komunikację. Jakieś wskazówki, porady na co zwrócić uwagę.<br />Z tego co wyczytałem najgorzej będzie zrobić proga dla slave?<br /><br />Pozdro<br /></div><br />Komunikacja mikroprocesorów atmega <strong>magistralą sprzętową TWI</strong> jest bajecznie łatwa pod warunkiem zastosowania odpowiedniej biblioteki dla atmegi-master i odpowiedniej biblioteki atmegi-slave(może być ich kilka), i tu właśnie przychodzi z pomocą pan <strong>Manfred Langemann</strong> autor tych bibliotek. Ja tylko dodam, że u mnie komunikacja z atmegami po TWI działa w dwie strony bez problemów - oczywiście dostosowałem(w niewielkim stopniu) te biblioteki od swoich potrzeb. Porty SDA i SCL są ustawiane automatycznie przez sprzętowe TWI. Atmegi zasilam tak jakbym korzystał z ADC. Przy atmega-master port SDA jest podłączony przez rezystor 4,7kOm do plusa zasilania, i port SCL jest podłączony przez rezystor 4,7kOm do plusa zasilania. Przy atmega-slave takich rezystorów niema. Wszystkie porty SDA są połączone ze sobą, wszystkie porty SCL  są połączone ze sobą, wszystkie masy procesorów atmega są połączone ze sobą. Korzystam z procesorów Atmega8(docelowo trzy: 1 master i 2 slave) taktowanych &quot;wewnętrznie RC&quot; 8MHz docelowo będą kwarce.<br /><br />TWI_Slave.h<br />[syntax=c]/*******************************************************<br /> Author:                                        Manfred Langemann<br /> mailto:                                        Manfred.Langemann ät t-online.de<br /> Begin of project:                      04.01.2008<br /> Latest version generated:      04.01.2008<br /> Filename:                                      TWI_Slave.h<br /> Description:                           TWI slave functions include file<br /><br /> ********************************************************/<br />#ifndef _TWIS<br />#define _TWIS<br /><br />#define TWIS_ReadBytes          0x60<br />#define TWIS_WriteBytes         0xA8<br /><br />/****************************************************************************<br />  Public Function definitions<br />****************************************************************************/<br />uint8_t TWIS_Init (uint8_t Address, uint32_t Bitrate);<br />void    TWIS_Stop (void);<br />void    TWIS_Write (uint8_t byte);<br />uint8_t TWIS_ReadAck (void);<br />uint8_t TWIS_ReadNack (void);<br />uint8_t TWIS_ResonseRequired (uint8_t *TWI_ResonseType);<br /><br />#endif[/syntax]<br /><br />TWI_Slave.c<br />[syntax=c]/*******************************************************<br /> Author:                                        Manfred Langemann<br /> mailto:                                        Manfred.Langemann ät t-online.de<br /> Begin of project:                      04.01.2008<br /> Latest version generated:      04.01.2008<br /> Filename:                                      TWI_Slave.c<br /> Description:                           TWI slave functions<br /><br /> -------------------------------------------------------<br /> Program Example<br /> -------------------------------------------------------<br />#include &quot;General.h&quot;<br />#include &quot;TWI_Slave.h&quot;<br /><br />int main (void)<br />        {<br />        uint8_t         i=0;<br />        uint8_t         j=0;<br />        uint8_t         byte[8];<br />        uint8_t         TWIS_ResonseType;<br /><br /> // Clear any interrupt<br />        cli ();<br /><br /> // Wait 0.5 second for POR<br />        Delay_ms (500);<br /><br /> // Initiate the TWI slave interface<br />        TWIS_Init (15, 100000);<br /><br /> // Endless loop<br />        while (1)<br />                {<br /><br /> // Is something to do for the TWI slave interface ?<br />                if (TWIS_ResonseRequired (&amp;TWIS_ResonseType))<br />                        {<br />                        switch (TWIS_ResonseType)<br />                                {<br /> // TWI requests to read a byte from the master.<br /> // It is implicitely assumed, that the master<br /> // sends 8 bytes.<br /><br />                                case TWIS_ReadBytes:<br />                                        for (i=0;i&lt;7;i++)<br />                                                {<br />                                                byte[0] = TWIS_ReadAck ();<br />                                                }<br />                                        byte[7] = TWIS_ReadNack ();<br />                                        TWIS_Stop ();<br />                                        break;<br /><br /> // TWI requests to write a byte to the master.<br /> // It is implicitely assumed, that the master<br /> // is prepared to receive 8 bytes.<br /><br />                                case TWIS_WriteBytes:<br />                                        for (i=0;i&lt;8;i++)<br />                                                {                  <br />                                                TWIS_Write (j++);<br />                                                }<br />                                    TWIS_Stop ();<br />                                        break;<br />                                }<br />                        }<br /> // Do something else ....... e.g.:<br />                i++;<br />                }<br />        return 0;<br />        }<br /> ********************************************************/<br />#include &lt;stdio.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br />#include &quot;General.h&quot;<br />#include &quot;TWI_Slave.h&quot;<br /><br />/****************************************************************************<br />  TWI State codes<br />****************************************************************************/<br />// General TWI Master staus codes                      <br />#define TWI_START                                       0x08  // START has been transmitted  <br />#define TWI_REP_START                           0x10  // Repeated START has been transmitted<br />#define TWI_ARB_LOST                            0x38  // Arbitration lost<br /><br />// TWI Master Transmitter staus codes                      <br />#define TWI_MTX_ADR_ACK                         0x18  // SLA+W has been tramsmitted and ACK received<br />#define TWI_MTX_ADR_NACK                        0x20  // SLA+W has been tramsmitted and NACK received<br />#define TWI_MTX_DATA_ACK                        0x28  // Data byte has been tramsmitted and ACK received<br />#define TWI_MTX_DATA_NACK                       0x30  // Data byte has been tramsmitted and NACK received<br /><br />// TWI Master Receiver staus codes  <br />#define TWI_MRX_ADR_ACK                         0x40  // SLA+R has been tramsmitted and ACK received<br />#define TWI_MRX_ADR_NACK                        0x48  // SLA+R has been tramsmitted and NACK received<br />#define TWI_MRX_DATA_ACK                        0x50  // Data byte has been received and ACK tramsmitted<br />#define TWI_MRX_DATA_NACK                       0x58  // Data byte has been received and NACK tramsmitted<br /><br />// TWI Slave Transmitter staus codes<br />#define TWI_STX_ADR_ACK                         0xA8  // Own SLA+R has been received; ACK has been returned<br />#define TWI_STX_ADR_ACK_M_ARB_LOST      0xB0  // Arbitration lost in SLA+R/W as Master; own SLA+R has been received; ACK has been returned<br />#define TWI_STX_DATA_ACK                        0xB8  // Data byte in TWDR has been transmitted; ACK has been received<br />#define TWI_STX_DATA_NACK                       0xC0  // Data byte in TWDR has been transmitted; NOT ACK has been received<br />#define TWI_STX_DATA_ACK_LAST_BYTE      0xC8  // Last data byte in TWDR has been transmitted (TWEA = 0); ACK has been received<br /><br />// TWI Slave Receiver staus codes<br />#define TWI_SRX_ADR_ACK                         0x60  // Own SLA+W has been received ACK has been returned<br />#define TWI_SRX_ADR_ACK_M_ARB_LOST      0x68  // Arbitration lost in SLA+R/W as Master; own SLA+W has been received; ACK has been returned<br />#define TWI_SRX_GEN_ACK                         0x70  // General call address has been received; ACK has been returned<br />#define TWI_SRX_GEN_ACK_M_ARB_LOST      0x78  // Arbitration lost in SLA+R/W as Master; General call address has been received; ACK has been returned<br />#define TWI_SRX_ADR_DATA_ACK            0x80  // Previously addressed with own SLA+W; data has been received; ACK has been returned<br />#define TWI_SRX_ADR_DATA_NACK           0x88  // Previously addressed with own SLA+W; data has been received; NOT ACK has been returned<br />#define TWI_SRX_GEN_DATA_ACK            0x90  // Previously addressed with general call; data has been received; ACK has been returned<br />#define TWI_SRX_GEN_DATA_NACK           0x98  // Previously addressed with general call; data has been received; NOT ACK has been returned<br />#define TWI_SRX_STOP_RESTART            0xA0  // A STOP condition or repeated START condition has been received while still addressed as Slave<br /><br />// TWI Miscellaneous status codes<br />#define TWI_NO_STATE                            0xF8  // No relevant state information available; TWINT = 0<br />#define TWI_BUS_ERROR                           0x00  // Bus error due to an illegal START or STOP condition<br /><br />/*******************************************************<br /> Public Function: TWIS_Init<br /><br /> Purpose: Initialise the TWI Slave Interface<br /><br /> Input Parameter:<br />        - uint8_t       Slave address<br />        - uint32_t      TWI_Bitrate (Hz)<br /><br /> Return Value: uint8_t<br />        - FALSE:        Bitrate too high<br />        - TRUE: Bitrate OK<br /><br />*******************************************************/<br />uint8_t TWIS_Init (uint8_t Address, uint32_t Bitrate)<br />        {<br />/*<br />** Set the TWI bitrate<br />** If TWBR is less 11, then error<br />*/<br />        TWBR = ((F_CPU/Bitrate)-16)/2;<br />        if (TWBR &lt; 11) return FALSE;<br />/*<br />** Set the TWI slave address<br />*/<br />        TWAR = (Address &lt;&lt; 1);<br />/*<br />** Activate TWI interface<br />*/<br />        TWCR = (1&lt;&lt;TWEN)|(1&lt;&lt;TWEA);<br /><br />        return TRUE;<br />        }<br />/*******************************************************<br /> Public Function: TWIS_Stop<br /><br /> Purpose: Stop the TWI Slave Interface<br /><br /> Input Parameter: None<br /><br /> Return Value: None<br /><br />*******************************************************/<br />void TWIS_Stop (void)<br />        {<br />        TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWSTO)|(1&lt;&lt;TWEA);<br />        }<br />/*******************************************************<br /> Public Function: TWIS_Write<br /><br /> Purpose: Write a byte to the master<br /><br /> Input Parameter:<br />        - uint8_t       Byte to be sent<br /><br /> Return Value: uint8_t<br />        - TRUE:         OK, Byte sent<br />        - FALSE:        Error in byte transmission<br /><br />*******************************************************/<br />void TWIS_Write (uint8_t byte)<br />        {<br />        TWDR = byte;<br />        TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWEA);<br />        while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />        }<br />/*******************************************************<br /> Public Function: TWIS_ReadAck<br /><br /> Purpose: Read a byte from the master and request next byte<br /><br /> Input Parameter: None<br /><br /> Return Value: uint8_t<br />        - uint8_t       Read byte<br /><br />*******************************************************/<br />uint8_t TWIS_ReadAck (void)<br />        {<br />        TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWEA);<br />        while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />        return TWDR;<br />        }<br />/*******************************************************<br /> Public Function: TWIS_ReadNack<br /><br /> Purpose: Read the last byte from the master<br /><br /> Input Parameter: None<br /><br /> Return Value: uint8_t<br />        - uint8_t       Read byte<br /><br />*******************************************************/<br />uint8_t TWIS_ReadNack (void)<br />        {<br />        TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN);<br />        while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />        return TWDR;<br />        }<br />/*******************************************************<br /> Public Function: TWIS_ResonseRequired<br /><br /> Purpose: Get the response type to be performed by slave<br /><br /> Input Parameter:<br />        - uint8_t*      Pointer to response type<br />        on return:<br />                TWIS_ReadBytes  --&gt; Read byte(s) from master<br />                TWIS_WriteBytes --&gt; Write byte(s) to master<br /><br /> Return Value: uint8_t<br />        Response required<br />                TRUE: Yes, response required<br />                FALSE: No response required<br /><br />*******************************************************/<br />uint8_t TWIS_ResonseRequired (uint8_t *TWI_ResonseType)<br />        {<br />        *TWI_ResonseType = TWSR;<br />        return TWCR &amp; (1&lt;&lt;TWINT);<br />        }<br /><br />[/syntax]<br /><br />TWI_Master.h<br />[syntax=c]/*******************************************************<br />Author: Manfred Langemann<br />mailto: Manfred.Langemann ät t-online.de<br />Begin of project: 04.01.2008<br />Latest version generated: 04.01.2008<br />Filename: TWI_Master.h<br />Description: TWI Master functions include file<br /><br />********************************************************/<br />#ifndef _TWIM<br />#define _TWIM<br /><br />#define TWIM_READ 1<br />#define TWIM_WRITE 0<br /><br />uint8_tTWIM_Init (uint32_t TWI_Bitrate);<br />uint8_t TWIM_Start (uint8_t address, uint8_t TWIM_Type);<br />voidTWIM_Stop (void);<br />uint8_tTWIM_Write (uint8_t byte);<br />uint8_tTWIM_ReadAck (void);<br />uint8_tTWIM_ReadNack (void);<br /><br />#endif[/syntax]<br /><br />TWI_Master.c<br />[syntax=c]/*******************************************************<br />Author: Manfred Langemann<br />mailto: Manfred.Langemann ät t-online.de<br />Begin of project: 04.01.2008<br />Latest version generated: 04.01.2008<br />Filename: TWI_Master.c<br />Description: TWI Master functions<br /><br />Master code adapted form Peter Fleury &lt;pfleury@gmx.ch&gt;<br /><!-- m --><a class="postlink" href="http://jump.to/fleury" >http://jump.to/fleury</a><!-- m --><br />--------------------------------------------------------<br />Program Example<br />--------------------------------------------------------<br /><br />int main (void)<br />{<br />uint8_t i=0;<br />uint8_t j=0;<br />uint8_t Data[8];<br />uint8_t SlaveAddress = 15;<br /><br />// Clear any interrupt<br />cli ();<br /><br />// Wait 1 second for POR<br />Delay_ms (1000);<br /><br />// Initiate RS232<br />RS232_Init ();<br />printf (&quot;Hello world...\n&quot;);<br /><br />// Initiate TWI Master with bitrate of 100000 Hz<br />TWIM_Init (100000);<br /><br />// Endless loop<br />while (1)<br />{<br />// Read byte(s) from the slave.<br />// It is implicitely assumed, that the slave will send<br />// 8 bytes.<br />if (!TWIM_Start (SlaveAddress, TWIM_READ))<br />{<br />TWIM_Stop ();<br />printf (&quot;Could not start TWI Bus for READ\n&quot;);<br />}<br />else<br />{<br />for (i=0;i&lt;7;i++)<br />{<br />Data[i] = TWIM_ReadAck ();<br />}<br />Data[7] = TWIM_ReadNack ();<br />printf (&quot;Reading Byte %d: %d\n&quot;, i, Data[i]);<br />TWIM_Stop ();<br />Delay_ms (1000);<br />}<br /><br />// Write byte(s) to the slave.<br />// It is implicitely assumed, that the slave will<br />// accepts 8 bytes<br /><br />if (!TWIM_Start (SlaveAddress, TWIM_WRITE))<br />{<br />TWIM_Stop ();<br />printf (&quot;Could not start TWI Bus for WRITE\n&quot;);<br />}<br />else<br />{<br />for (i=0;i&lt;8;i++)<br />{<br />TWIM_Write (j++);<br />printf (&quot;Byte %d sent\n&quot;, j);<br />}<br />TWIM_Stop ();<br />Delay_ms (1000);<br />}<br /><br />// Do something else<br />i++;<br />}<br /><br />return 0;<br />}<br /><br />********************************************************/<br />#include &lt;stdio.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br />#include &quot;General.h&quot;<br />#include &quot;TWI_Master.h&quot;<br /><br />/****************************************************************************<br />TWI State codes<br />****************************************************************************/<br />// General TWI Master staus codes<br />#define TWI_START 0x08 // START has been transmitted<br />#define TWI_REP_START 0x10 // Repeated START has been transmitted<br />#define TWI_ARB_LOST 0x38 // Arbitration lost<br /><br />// TWI Master Transmitter staus codes<br />#define TWI_MTX_ADR_ACK 0x18 // SLA+W has been tramsmitted and ACK received<br />#define TWI_MTX_ADR_NACK 0x20 // SLA+W has been tramsmitted and NACK received<br />#define TWI_MTX_DATA_ACK 0x28 // Data byte has been tramsmitted and ACK received<br />#define TWI_MTX_DATA_NACK 0x30 // Data byte has been tramsmitted and NACK received<br /><br />// TWI Master Receiver staus codes<br />#define TWI_MRX_ADR_ACK 0x40 // SLA+R has been tramsmitted and ACK received<br />#define TWI_MRX_ADR_NACK 0x48 // SLA+R has been tramsmitted and NACK received<br />#define TWI_MRX_DATA_ACK 0x50 // Data byte has been received and ACK tramsmitted<br />#define TWI_MRX_DATA_NACK 0x58 // Data byte has been received and NACK tramsmitted<br /><br />// TWI Slave Transmitter staus codes<br />#define TWI_STX_ADR_ACK 0xA8 // Own SLA+R has been received; ACK has been returned<br />#define TWI_STX_ADR_ACK_M_ARB_LOST 0xB0 // Arbitration lost in SLA+R/W as Master; own SLA+R has been received; ACK has been returned<br />#define TWI_STX_DATA_ACK 0xB8 // Data byte in TWDR has been transmitted; ACK has been received<br />#define TWI_STX_DATA_NACK 0xC0 // Data byte in TWDR has been transmitted; NOT ACK has been received<br />#define TWI_STX_DATA_ACK_LAST_BYTE 0xC8 // Last data byte in TWDR has been transmitted (TWEA = “0”); ACK has been received<br /><br />// TWI Slave Receiver staus codes<br />#define TWI_SRX_ADR_ACK 0x60 // Own SLA+W has been received ACK has been returned<br />#define TWI_SRX_ADR_ACK_M_ARB_LOST 0x68 // Arbitration lost in SLA+R/W as Master; own SLA+W has been received; ACK has been returned<br />#define TWI_SRX_GEN_ACK 0x70 // General call address has been received; ACK has been returned<br />#define TWI_SRX_GEN_ACK_M_ARB_LOST 0x78 // Arbitration lost in SLA+R/W as Master; General call address has been received; ACK has been returned<br />#define TWI_SRX_ADR_DATA_ACK 0x80 // Previously addressed with own SLA+W; data has been received; ACK has been returned<br />#define TWI_SRX_ADR_DATA_NACK 0x88 // Previously addressed with own SLA+W; data has been received; NOT ACK has been returned<br />#define TWI_SRX_GEN_DATA_ACK 0x90 // Previously addressed with general call; data has been received; ACK has been returned<br />#define TWI_SRX_GEN_DATA_NACK 0x98 // Previously addressed with general call; data has been received; NOT ACK has been returned<br />#define TWI_SRX_STOP_RESTART 0xA0 // A STOP condition or repeated START condition has been received while still addressed as Slave<br /><br />// TWI Miscellaneous status codes<br />#define TWI_NO_STATE 0xF8 // No relevant state information available; TWINT = “0”<br />#define TWI_BUS_ERROR 0x00 // Bus error due to an illegal START or STOP condition<br /><br />/*******************************************************<br />Public Function: TWIM_Init<br /><br />Purpose: Initialise the TWI Master Interface<br /><br />Input Parameter:<br />- uint16_t TWI_Bitrate (Hz)<br /><br />Return Value: uint8_t<br />- FALSE: Bitrate too high<br />- TRUE: Bitrate OK<br /><br />*******************************************************/<br />uint8_t TWIM_Init (uint32_t TWI_Bitrate)<br />{<br />/*<br />** Set TWI bitrate<br />** If bitrate is too high, then error return<br />*/<br /><br />TWBR=11;<br />// TWBR = ((F_CPU/TWI_Bitrate)-16)/2;<br />// if (TWBR &lt; 11) return FALSE;<br /><br />return TRUE;<br />}<br />/*******************************************************<br />Public Function: TWIM_Start<br /><br />Purpose: Start the TWI Master Interface<br /><br />Input Parameter:<br />- uint8_t Device address<br />- uint8_t Type of required Operation:<br />TWIM_READ: Read data from the slave<br />TWIM_WRITE: Write data to the slave<br /><br />Return Value: uint8_t<br />- TRUE: OK, TWI Master accessible<br />- FALSE: Error in starting TWI Master<br /><br />*******************************************************/<br />uint8_t TWIM_Start (uint8_t Address, uint8_t TWIM_Type)<br />{<br />uint8_ttwst;<br />/*<br />** Send START condition<br />*/<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWSTA)|(1&lt;&lt;TWEN);<br />/*<br />** Wait until transmission completed<br />*/<br />while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />/*<br />** Check value of TWI Status Register. Mask prescaler bits.<br />*/<br />twst = TWSR &amp; 0xF8;<br />if ((twst != TWI_START) &amp;&amp; (twst != TWI_REP_START)) return FALSE;<br />/*<br />** Send device address<br />*/<br />TWDR = (Address&lt;&lt;1) + TWIM_Type;<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN);<br />/*<br />** Wait until transmission completed and ACK/NACK has been received<br />*/<br />while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />/*<br />** Check value of TWI Status Register. Mask prescaler bits.<br />*/<br />twst = TWSR &amp; 0xF8;<br />if ((twst != TWI_MTX_ADR_ACK) &amp;&amp; (twst != TWI_MRX_ADR_ACK)) return FALSE;<br /><br />return TRUE;<br />}<br />/*******************************************************<br />Public Function: TWIM_Stop<br /><br />Purpose: Stop the TWI Master<br /><br />Input Parameter: None<br /><br />Return Value: None<br /><br />*******************************************************/<br />void TWIM_Stop (void)<br />{<br />/*<br />** Send stop condition<br />*/<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWSTO);<br />/*<br />** Wait until stop condition is executed and bus released<br />*/<br />while (TWCR &amp; (1&lt;&lt;TWINT));<br />}<br />/*******************************************************<br />Public Function: TWIM_Write<br /><br />Purpose: Write a byte to the slave<br /><br />Input Parameter:<br />- uint8_t Byte to be sent<br /><br />Return Value: uint8_t<br />- TRUE: OK, Byte sent<br />- FALSE: Error in byte transmission<br /><br />*******************************************************/<br />uint8_t TWIM_Write (uint8_t byte)<br />{<br />uint8_t twst;<br />/*<br />** Send data to the previously addressed device<br />*/<br />TWDR = byte;<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN);<br />/*<br />** Wait until transmission completed<br />*/<br />while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br />/*<br />** Check value of TWI Status Register. Mask prescaler bits<br />*/<br />twst = TWSR &amp; 0xF8;<br />if (twst != TWI_MTX_DATA_ACK) return 1;<br /><br />return 0;<br />}<br />/*******************************************************<br />Public Function: TWIM_ReadAck<br /><br />Purpose: Read a byte from the slave and request next byte<br /><br />Input Parameter: None<br /><br />Return Value: uint8_t<br />- uint8_t Read byte<br /><br />*******************************************************/<br />uint8_t TWIM_ReadAck (void)<br />{<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN)|(1&lt;&lt;TWEA);<br />while (!(TWCR &amp; (1&lt;&lt;TWINT)));<br /><br />return TWDR;<br />}<br />/*******************************************************<br />Public Function: TWIM_ReadAck<br /><br />Purpose: Read the last byte from the slave<br /><br />Input Parameter: None<br /><br />Return Value: uint8_t<br />- uint8_t Read byte<br /><br />*******************************************************/<br />uint8_t TWIM_ReadNack (void)<br />{<br />TWCR = (1&lt;&lt;TWINT)|(1&lt;&lt;TWEN);<br />while(!(TWCR &amp; (1&lt;&lt;TWINT)));<br /><br />return TWDR;<br />}[/syntax]<br /><br />General.h<br />[syntax=c]#ifndef _General<br /><br />#define _General<br /><br />#define TRUE    1<br />#define FALSE   0<br />/*<br />** Here are some deinitions, used in all programs<br />*/<br />#define SYSCLOCK                                8000000 // Quarz Frequenz in Hz<br /><br /><br />#define SET_BIT(PORT, BITNUM)   ((PORT) |= (1&lt;&lt;(BITNUM)))<br />#define CLEAR_BIT(PORT, BITNUM) ((PORT) &amp;= ~(1&lt;&lt;(BITNUM)))<br />#define TOOGLE_BIT(PORT,BITNUM) ((PORT) ^= (1&lt;&lt;(BITNUM)))<br /><br /><br />struct BitsOfByte<br />        {<br />        uint8_t b0:1;<br />        uint8_t b1:1;<br />        uint8_t b2:1;<br />        uint8_t b3:1;<br />        uint8_t b4:1;<br />        uint8_t b5:1;<br />        uint8_t b6:1;<br />        uint8_t b7:1;<br />        } __attribute__((__packed__));<br /><br /><br />#define SBIT(port,pin) ((*(volatile struct BitsOfByte*)&amp;port).b##pin)<br /><br />#endif<br />[/syntax]<br /><br />Przykłady jak zastosować biblioteki w swoich programach zamieszczone sa w plikach *.c przez ich autora, więc nie powinno być kłopotów z dostosowaniem do swoich potrzeb.<br /><strong>Mam nadzieje, że pan Mirek kiedyś o sprzetowej magistrali TWI zrobi poradnik video.</strong><br /><br />Piotr<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=539">p_zag</a> — 4 sty 2013, o 21:12</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-01-04T08:41:09+01:00</updated>
<published>2013-01-04T08:41:09+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23293#p23293</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23293#p23293"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23293#p23293"><![CDATA[
Pewnie że mam wolnego INT0-a, generalnie pomysł z programowym UART-em mnie zadowala w pełni.<br />Ale jeśli Antystatyczny chcesz się pobawić to czemu nie, przyda się nie tylko nam ale myślę wielu urzytkownikom.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 4 sty 2013, o 08:41</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-01-03T17:51:00+01:00</updated>
<published>2013-01-03T17:51:00+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23208#p23208</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23208#p23208"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23208#p23208"><![CDATA[
dzięki za podpowiedzi:)<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 3 sty 2013, o 17:51</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2013-01-03T17:20:39+01:00</updated>
<published>2013-01-03T17:20:39+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23196#p23196</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23196#p23196"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23196#p23196"><![CDATA[
<div class="quotetitle">developer85 napisał(a):</div><div class="quotecontent"><br />Wpadł mi jeszcze jeden pomysł do głowy: ewentualnie zastosować procka w dwoma UART-mi? i problem transmisji z głowy:)<br /></div><br /><br />Ja zawsze jak miałem się zabrać za komunikację I2C master/slave to kończyło się to zwykle właśnie na UART <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> .... nawet metodą programową jak słusznie wyżej podpowiada SunRiver. Wszystko zależy do czego i jaka ma być to transmisja na tym kanale że tak powiem. Jeśli TYLKO coś wysłać to UART programowy może okazać się zbawieniem <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> i będzie TYLKO jedna linia <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 3 sty 2013, o 17:20</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[SunRiver]]></name></author>
<updated>2013-01-03T17:08:10+01:00</updated>
<published>2013-01-03T17:08:10+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23193#p23193</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23193#p23193"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23193#p23193"><![CDATA[
zawsze możesz zrobić uarta programowego<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=58">SunRiver</a> — 3 sty 2013, o 17:08</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-01-03T16:31:30+01:00</updated>
<published>2013-01-03T16:31:30+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23188#p23188</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23188#p23188"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23188#p23188"><![CDATA[
Jestem własnie zmuszony użyć I2C do takiej specyficznej komunikacji bo mam tylko dwa &quot;kabelki&quot; wolne. Ok poszperam w necie i jeśli coś będzie nie teges to napisze:)<br /><br /><strong><span style="color: #808000">------------------------ [ Dodano po: 20 minutach ]</span></strong><br /><br />Wpadł mi jeszcze jeden pomysł do głowy: ewentualnie zastosować procka w dwoma UART-mi? i problem transmisji z głowy:)<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 3 sty 2013, o 16:31</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2013-01-03T16:19:40+01:00</updated>
<published>2013-01-03T16:19:40+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23186#p23186</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23186#p23186"/>
<title type="html"><![CDATA[Re: I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23186#p23186"><![CDATA[
<div class="quotetitle">developer85 napisał(a):</div><div class="quotecontent"><br />Z tego co wyczytałem najgorzej będzie zrobić proga dla slave?<br /></div><br /><br />No troszkę będzie z tym roboty, sam nie robiłem tego ale można w necie znaleźć różne gotowe biblkioteki ze Slave I2C sprzętowym - nie powinno być źle. Można je albo zaadaptować albo podpatrzeć i przerobić pod siebie. Na pewno gdzieś takie po drodze widziałem gdy interesowałem się kiedyś tym tematem.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 3 sty 2013, o 16:19</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[developer85]]></name></author>
<updated>2013-01-03T16:15:13+01:00</updated>
<published>2013-01-03T16:15:13+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23184#p23184</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23184#p23184"/>
<title type="html"><![CDATA[I2C - dwa procki]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=2044&amp;p=23184#p23184"><![CDATA[
Witam!<br />Czy ktoś z szanownych kolegów robił może już taką komunikację. Jakieś wskazówki, porady na co zwrócić uwagę.<br />Z tego co wyczytałem najgorzej będzie zrobić proga dla slave?<br /><br />Pozdro<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=390">developer85</a> — 3 sty 2013, o 16:15</p><hr />
]]></content>
</entry>
</feed>