<?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=8&amp;t=21103&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2018-08-09T10:36:26+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=8&amp;t=21103&amp;mode</id>
<entry>
<author><name><![CDATA[micky]]></name></author>
<updated>2018-08-09T10:36:26+01:00</updated>
<published>2018-08-09T10:36:26+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210581#p210581</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210581#p210581"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210581#p210581"><![CDATA[
Z tego co ludzie pisali na tym forum to Mirka programy dają się odpalić w wirtualnej maszynie - więc zawsze jest jakaś altetnatywa aby i pod linuxem korzystać z dobrodziejstw twórczości Mirka.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1546">micky</a> — 9 sie 2018, o 10:36</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[GoRo3]]></name></author>
<updated>2018-08-08T06:25:49+01:00</updated>
<published>2018-08-08T06:25:49+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210556#p210556</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210556#p210556"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210556#p210556"><![CDATA[
<div class="quotetitle">micky napisał(a):</div><div class="quotecontent"><br />Odpal Mirkowy i2c scanner. Bo adres wypluty z Arduinowego scannera trza pomnożyć przez 2 tak jak kolega wcześniej pisał. Może masz złe kontakty, że kapryśnie działa?<br /></div><br /><br />Niestety programy Mirka, o ile bardzo przydatne dlamnie bezużyteczne ponieważ nigdzie nie mam Windowsa <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> <br /><br />Nie mniej dzięki za podpowiedzi, będę analizował dalej bo dzisiaj kolega w pracy podrzuci mi analizator stanów logicznych.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=18553">GoRo3</a> — 8 sie 2018, o 06:25</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[micky]]></name></author>
<updated>2018-08-08T05:20:11+01:00</updated>
<published>2018-08-08T05:20:11+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210554#p210554</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210554#p210554"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210554#p210554"><![CDATA[
Odpal Mirkowy i2c scanner. Bo adres wypluty z Arduinowego scannera trza pomnożyć przez 2 tak jak kolega wcześniej pisał. Może masz złe kontakty, że kapryśnie działa?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=1546">micky</a> — 8 sie 2018, o 05:20</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[GoRo3]]></name></author>
<updated>2018-08-07T22:20:30+01:00</updated>
<published>2018-08-07T22:20:30+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210545#p210545</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210545#p210545"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210545#p210545"><![CDATA[
Dzięki za szybką odpowiedź. <br /><br />Mam rezystory 4,7K pod Vcc podpięte. A0,A1,A2 pod GND. Skaner pluje adresem 0x38, więc taki testowałem, jak i również całą iterację po puli adresów. <br /><br />Chociaż teraz mam dziwną rzeczy. NIby coś się ruszyło na adresie 0x70, jednak dioda kontrolna ciągle mi zgłasza błąd nr 0x05 czyli według biblioteki:<br />[syntax=c]USI_TWI_NO_ACK_ON_DATA      0x05  // The slave did not acknowledge  all data[/syntax]<br /><br />Oraz jest dosyć kapryśny, nie działa za każdym razem ale ruszyło....  Wiecie co to może być?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=18553">GoRo3</a> — 7 sie 2018, o 22:20</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2018-08-07T20:42:02+01:00</updated>
<published>2018-08-07T20:42:02+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210540#p210540</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210540#p210540"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210540#p210540"><![CDATA[
<div class="quotetitle">krish napisał(a):</div><div class="quotecontent"><br />Oczywiście najlepiej przeskanować sobie wszystkie adresy i2c.<br /></div><br />Dokładnie <img src="https://forum.atnel.pl/images/smilies/icon_e_wink.gif" alt=";)" title="Puszcza oko" /> albo zajrzeć do noty PDF swojej wersji scalaka gdzie jest podany adres<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 7 sie 2018, o 20:42</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[krish]]></name></author>
<updated>2018-08-07T21:09:45+01:00</updated>
<published>2018-08-07T20:38:14+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210539#p210539</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210539#p210539"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210539#p210539"><![CDATA[
Jest różnica w adresowaniu między ..8574 a ...8574A ( dla ..8574A powinno być w notacji 8-bitowej od 0x70 do 0x7e; 7-bitowa: 0x38 do 0x3f).<br />Oczywiście najlepiej przeskanować sobie wszystkie adresy i2c.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=2273">krish</a> — 7 sie 2018, o 20:38</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mczarny]]></name></author>
<updated>2018-08-07T20:15:21+01:00</updated>
<published>2018-08-07T20:15:21+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210538#p210538</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210538#p210538"/>
<title type="html"><![CDATA[Re: USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210538#p210538"><![CDATA[
cześć<br />Myślę, że jak zwykle w takich wypadkach masz coś źle z adresem na szynie I2C.<br />Napisz jak masz podłączone piny A0,A1,A2 bo od tego zależy adres układu - to po pierwsze<br />Arduino korzysta z adresowania 7bit, biblioteki dla AVR-a przeważnie z adresu 8bit gdzie ostatni bit jest &quot;0&quot; lub &quot;1&quot; w zależności czy czytasz układ czy do niego zapisujesz.<br />Oczywiście linie I2C masz sprzętowo podciągnięte rezystorami do Vcc?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=4651">mczarny</a> — 7 sie 2018, o 20:15</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[GoRo3]]></name></author>
<updated>2018-08-07T19:27:47+01:00</updated>
<published>2018-08-07T19:27:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210536#p210536</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210536#p210536"/>
<title type="html"><![CDATA[USI AVR +  PCF8574AP - problem z komunikacją]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21103&amp;p=210536#p210536"><![CDATA[
Cześć Wam! <br /><br /> Niestety muszę przyznać, że poległem w kwesti ustawienia USI na AtTinny 85 aby móc komunikować się po i2c z urządzeniem PCF8574AP.  <img src="https://forum.atnel.pl/images/smilies/icon_redface.gif" alt=":oops:" title="Zawstydzony" /> <br /><br />Proszę szanowne grono o pomoc w mojej kwestii bo już nie wiem co jest nie tak a siedzę nad tym od 4 dni (cały weekend zmarnowany:( ).<br /><br />Chciałem napisać własny sterownik do rejestru przesównego pod i2c + LCD. Niestety po podłączeniu wszystkiego oraz skonfigurowaniu biblioteki z noty AVR (AVR310 - USI Master), rejestr nawet nie drgnie. Tzn diody jakie podpiołem nie chcą się świecić. Diody do PCF'a są podpięte anodą do + przez rezystor do nóżki scalaka. Dodam, że jak podłączam pod arduino i puszczam prosty program do sterowania i2c to wszystko działa, tylko na moim AVR nie chcę. <br /><br />Próbowałem już wszystkiego co znalazłem na sieci żadne rozwiązanie niestety nie działa a mnie dodatkowo irytuje to, że na forach angielskich nikt nie ma z tą biblioteką problemów. <br /><br />Poniżej przesyłam kod, w którym próbuje wysłać sygnał na każdy adres po kolei. Niestety i to nie działa. Macie może jakąś podpowiedź do tego? <br /><br />dodatkowo, adres w deklaracji define to adres jaki mi wypluł i2c scanner na arduino. Próbowałem się z nim komunikować ale bez rezultatu. <br /><br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;inttypes.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br />#include &quot;USI_TWI_MASTER.h&quot;<br /><br />#define ADDR 0x38<br /><br />void prtnt_state(uint8_t state) {<br />for (int i = 0; i &lt;= state; i++) {<br /><br />PORTB |= (1 &lt;&lt; PB4);<br />_delay_ms(225);<br />PORTB &amp;= ~(1 &lt;&lt; PB4);<br />_delay_ms(225);<br />}<br />}<br /><br />int main(void) {<br /><br />uint8_t buffer&#91;2&#93;;<br />uint8_t TWI_targetSlaveAddress;<br />static unsigned char state;<br />uint8_t i = 0;<br /><br />PORTB |= (1 &lt;&lt; PB4);<br />DDRB |= (1 &lt;&lt; PB4);<br />PORTB &amp;= ~(1 &lt;&lt; PB4);<br /><br />TWI_targetSlaveAddress = ADDR;<br /><br />buffer&#91;0&#93; = (TWI_targetSlaveAddress &lt;&lt; TWI_ADR_BITS) | 0;<br />buffer&#91;1&#93; = 0x00;<br /><br />USI_TWI_Master_Initialise();<br /><br />while (1) {<br /><br />_delay_ms(2500);<br /><br />while (i &lt; 0xff) {<br /><br />buffer&#91;0&#93; = (i &lt;&lt; TWI_ADR_BITS) | 0;<br />state = USI_TWI_Start_Transceiver_With_Data(buffer, 2);<br /><br />i++;<br />}<br /><br />if (!state) {<br />prtnt_state(USI_TWI_Get_State_Info());<br />}<br />}<br />return 0;<br /><br />}[/syntax]<br /><br />bibioteka USI_MASTER.h: <br />[syntax=c]/*****************************************************************************<br />*<br />* Atmel Corporation<br />*<br />* File              : USI_TWI_Master.h<br />* Compiler          : AVRGCC Toolchain version 3.4.2<br />* Revision          : $Revision: 992 $<br />* Date              : $Date: 2013-11-07 $<br />* Updated by        : $Author: Atmel $<br />*<br />* Support mail      : avr@atmel.com<br />*<br />* Supported devices : All device with USI module can be used.<br />*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313<br />*<br />* AppNote           : AVR310 - Using the USI module as a TWI Master<br />*<br />* Description       : This is an implementation of an TWI master using<br />*                     the USI module as basis. The implementation assumes the AVR to<br />*                     be the only TWI master in the system and can therefore not be<br />*                     used in a multi-master system.<br />* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() <br />*                     function. Hence messages/data are transceived on the bus using<br />*                     the USI_TWI_Start_Transceiver_With_Data() function. If the transceiver<br />*                     returns with a fail, then use USI_TWI_Get_Status_Info to evaluate the <br />*                     couse of the failure.<br />*<br />****************************************************************************/<br />    #include&lt;avr/io.h&gt; <br />//********** Defines **********//<br /><br />// Defines controlling timing limits<br />//#define TWI_FAST_MODE<br /><br />#define SYS_CLK   4000.0  // &#91;kHz&#93;<br /><br />#ifdef TWI_FAST_MODE               // TWI FAST mode timing limits. SCL = 100-400kHz<br />  #define T2_TWI    ((SYS_CLK *1300) /1000000) +1 // &gt;1,3us<br />  #define T4_TWI    ((SYS_CLK * 600) /1000000) +1 // &gt;0,6us<br />  <br />#else                              // TWI STANDARD mode timing limits. SCL &lt;= 100kHz<br />  #define T2_TWI    ((SYS_CLK *4700) /1000000) +1 // &gt;4,7us<br />  #define T4_TWI    ((SYS_CLK *4000) /1000000) +1 // &gt;4,0us<br />#endif<br /><br />// Defines controling code generating<br />//#define PARAM_VERIFICATION<br />//#define NOISE_TESTING<br />//#define SIGNAL_VERIFY<br /><br />//USI_TWI messages and flags and bit masks<br />//#define SUCCESS   7<br />//#define MSG       0<br />/****************************************************************************<br />  Bit and byte definitions<br />****************************************************************************/<br />#define TWI_READ_BIT  0       // Bit position for R/W bit in &quot;address byte&quot;.<br />#define TWI_ADR_BITS  1       // Bit position for LSB of the slave address bits in the init byte.<br />#define TWI_NACK_BIT  0       // Bit position for (N)ACK bit.<br /><br />#define USI_TWI_NO_DATA             0x00  // Transmission buffer is empty<br />#define USI_TWI_DATA_OUT_OF_BOUND   0x01  // Transmission buffer is outside SRAM space<br />#define USI_TWI_UE_START_CON        0x02  // Unexpected Start Condition<br />#define USI_TWI_UE_STOP_CON         0x03  // Unexpected Stop Condition<br />#define USI_TWI_UE_DATA_COL         0x04  // Unexpected Data Collision (arbitration)<br />#define USI_TWI_NO_ACK_ON_DATA      0x05  // The slave did not acknowledge  all data<br />#define USI_TWI_NO_ACK_ON_ADDRESS   0x06  // The slave did not acknowledge  the address<br />#define USI_TWI_MISSING_START_CON   0x07  // Generated Start Condition not detected on bus<br />#define USI_TWI_MISSING_STOP_CON    0x08  // Generated Stop Condition not detected on bus<br /><br />// Device dependant defines<br /><br />#if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169PA__) | \<br />    defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \<br />    defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \<br />    defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \<br />    defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \<br />    defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__)<br />    #define DDR_USI             DDRE<br />    #define PORT_USI            PORTE<br />    #define PIN_USI             PINE<br />    #define PORT_USI_SDA        PORTE5<br />    #define PORT_USI_SCL        PORTE4<br />    #define PIN_USI_SDA         PINE5<br />    #define PIN_USI_SCL         PINE4<br />#endif<br /><br />#if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \<br />    defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__)<br />    #define DDR_USI             DDRB<br />    #define PORT_USI            PORTB<br />    #define PIN_USI             PINB<br />    #define PORT_USI_SDA        PORTB0<br />    #define PORT_USI_SCL        PORTB2<br />    #define PIN_USI_SDA         PINB0<br />    #define PIN_USI_SCL         PINB2<br />#endif<br /><br />#if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__)<br />    #define DDR_USI             DDRB<br />    #define PORT_USI            PORTB<br />    #define PIN_USI             PINB<br />    #define PORT_USI_SDA        PORTB5<br />    #define PORT_USI_SCL        PORTB7<br />    #define PIN_USI_SDA         PINB5<br />    #define PIN_USI_SCL         PINB7<br />#endif<br /><br />// General defines<br />#define TRUE  1<br />#define FALSE 0<br /><br />//********** Prototypes **********//<br /><br />void              USI_TWI_Master_Initialise( void );<br /> unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char * , unsigned char );<br />unsigned char USI_TWI_Get_State_Info( void );[/syntax]<br /><br />USI_Master.c:<br />[syntax=c]/*****************************************************************************<br />*<br />* Atmel Corporation<br />*<br />* File              : USI_TWI_Master.c<br />* Compiler          : AVRGCC Toolchain version 3.4.2<br />* Revision          : $Revision: 992 $<br />* Date              : $Date: 2013-11-07 $<br />* Updated by        : $Author: Atmel $<br />*<br />* Support mail      : avr@atmel.com<br />*<br />* Supported devices : All device with USI module can be used.<br />*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313<br />*<br />* AppNote           : AVR310 - Using the USI module as a TWI Master<br />*<br />* Description       : This is an implementation of an TWI master using<br />*                     the USI module as basis. The implementation assumes the AVR to<br />*                     be the only TWI master in the system and can therefore not be<br />*                     used in a multi-master system.<br />* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() <br />*                     function. Hence messages/data are transceived on the bus using<br />*                     the USI_TWI_Transceive() function. The transceive function <br />*                     returns a status byte, which can be used to evaluate the <br />*                     success of the transmission.<br />*<br />****************************************************************************/<br />#include &lt;avr/io.h&gt;<br />#include &quot;USI_TWI_Master.h&quot;<br />#include &lt;util/delay.h&gt;<br /><br />unsigned char USI_TWI_Master_Transfer( unsigned char );<br />unsigned char USI_TWI_Master_Stop( void );<br /><br />union  USI_TWI_state<br />{<br />  unsigned char errorState;         // Can reuse the TWI_state for error states due to that it will not be need if there exists an error.<br />  struct<br />  {<br />    unsigned char addressMode         : 1;<br />    unsigned char masterWriteDataMode : 1;<br />    unsigned char unused              : 6;<br />  }; <br />}   USI_TWI_state;<br /><br />/*---------------------------------------------------------------<br /> USI TWI single master initialization function<br />---------------------------------------------------------------*/<br />void USI_TWI_Master_Initialise( void )<br />{<br />  PORT_USI |= (1&lt;&lt;PIN_USI_SDA);           // Enable pullup on SDA, to set high as released state.<br />  PORT_USI |= (1&lt;&lt;PIN_USI_SCL);           // Enable pullup on SCL, to set high as released state.<br />  <br />  DDR_USI  |= (1&lt;&lt;PIN_USI_SCL);           // Enable SCL as output.<br />  DDR_USI  |= (1&lt;&lt;PIN_USI_SDA);           // Enable SDA as output.<br />  <br />  USIDR    =  0xFF;                       // Preload dataregister with &quot;released level&quot; data.<br />  USICR    =  (0&lt;&lt;USISIE)|(0&lt;&lt;USIOIE)|                            // Disable Interrupts.<br />              (1&lt;&lt;USIWM1)|(0&lt;&lt;USIWM0)|                            // Set USI in Two-wire mode.<br />              (1&lt;&lt;USICS1)|(0&lt;&lt;USICS0)|(1&lt;&lt;USICLK)|                // Software stobe as counter clock source<br />              (0&lt;&lt;USITC);<br />  USISR   =   (1&lt;&lt;USISIF)|(1&lt;&lt;USIOIF)|(1&lt;&lt;USIPF)|(1&lt;&lt;USIDC)|      // Clear flags,<br />              (0x0&lt;&lt;USICNT0);                                     // and reset counter.<br />}<br /><br />/*---------------------------------------------------------------<br />Use this function to get hold of the error message from the last transmission<br />---------------------------------------------------------------*/<br />unsigned char USI_TWI_Get_State_Info( void )<br />{<br />  return ( USI_TWI_state.errorState );                            // Return error state.<br />}<br /><br />/*---------------------------------------------------------------<br /> USI Transmit and receive function. LSB of first byte in data <br /> indicates if a read or write cycles is performed. If set a read<br /> operation is performed.<br /><br /> Function generates (Repeated) Start Condition, sends address and<br /> R/W, Reads/Writes Data, and verifies/sends ACK.<br /> <br /> Success or error code is returned. Error codes are defined in <br /> USI_TWI_Master.h<br />---------------------------------------------------------------*/<br />unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char *msg, unsigned char msgSize)<br />{<br />  unsigned char tempUSISR_8bit = (1&lt;&lt;USISIF)|(1&lt;&lt;USIOIF)|(1&lt;&lt;USIPF)|(1&lt;&lt;USIDC)|      // Prepare register value to: Clear flags, and<br />                                 (0x0&lt;&lt;USICNT0);                                     // set USI to shift 8 bits i.e. count 16 clock edges.<br />  unsigned char tempUSISR_1bit = (1&lt;&lt;USISIF)|(1&lt;&lt;USIOIF)|(1&lt;&lt;USIPF)|(1&lt;&lt;USIDC)|      // Prepare register value to: Clear flags, and<br />                                 (0xE&lt;&lt;USICNT0);                                     // set USI to shift 1 bit i.e. count 2 clock edges.<br /><br />  USI_TWI_state.errorState = 0;<br />  USI_TWI_state.addressMode = TRUE;<br /><br />#ifdef PARAM_VERIFICATION<br />  if(msg &gt; (unsigned char*)RAMEND)                 // Test if address is outside SRAM space<br />  {<br />    USI_TWI_state.errorState = USI_TWI_DATA_OUT_OF_BOUND;<br />    return (FALSE);<br />  }<br />  if(msgSize &lt;= 1)                                 // Test if the transmission buffer is empty<br />  {<br />    USI_TWI_state.errorState = USI_TWI_NO_DATA;<br />    return (FALSE);<br />  }<br />#endif<br /><br />#ifdef NOISE_TESTING                                // Test if any unexpected conditions have arrived prior to this execution.<br />  if( USISR &amp; (1&lt;&lt;USISIF) )<br />  {<br />    USI_TWI_state.errorState = USI_TWI_UE_START_CON;<br />    return (FALSE);<br />  }<br />  if( USISR &amp; (1&lt;&lt;USIPF) )<br />  {<br />    USI_TWI_state.errorState = USI_TWI_UE_STOP_CON;<br />    return (FALSE);<br />  }<br />  if( USISR &amp; (1&lt;&lt;USIDC) )<br />  {<br />    USI_TWI_state.errorState = USI_TWI_UE_DATA_COL;<br />    return (FALSE);<br />  }<br />#endif<br /><br />  if ( !(*msg &amp; (1&lt;&lt;TWI_READ_BIT)) )                // The LSB in the address byte determines if is a masterRead or masterWrite operation.<br />  {<br />    USI_TWI_state.masterWriteDataMode = TRUE;<br />  }<br /><br />/* Release SCL to ensure that (repeated) Start can be performed */<br />  PORT_USI |= (1&lt;&lt;PIN_USI_SCL);                     // Release SCL.<br />  while( !(PIN_USI &amp; (1&lt;&lt;PIN_USI_SCL)) );          // Verify that SCL becomes high.<br />#ifdef TWI_FAST_MODE<br />  _delay_us( T4_TWI/4 );                         // Delay for T4TWI if TWI_FAST_MODE<br />#else<br />  _delay_us( T2_TWI/4 );                         // Delay for T2TWI if TWI_STANDARD_MODE<br />#endif<br /><br />/* Generate Start Condition */<br />  PORT_USI &amp;= ~(1&lt;&lt;PIN_USI_SDA);                    // Force SDA LOW.<br />  _delay_us( T4_TWI/4 );                         <br />  PORT_USI &amp;= ~(1&lt;&lt;PIN_USI_SCL);                    // Pull SCL LOW.<br />  PORT_USI |= (1&lt;&lt;PIN_USI_SDA);                     // Release SDA.<br /><br />#ifdef SIGNAL_VERIFY<br />  if( !(USISR &amp; (1&lt;&lt;USISIF)) )<br />  {<br />    USI_TWI_state.errorState = USI_TWI_MISSING_START_CON;  <br />    return (FALSE);<br />  }<br />#endif<br /><br />/*Write address and Read/Write data */<br />  do<br />  {<br />    /* If masterWrite cycle (or inital address tranmission)*/<br />    if (USI_TWI_state.addressMode || USI_TWI_state.masterWriteDataMode)<br />    {<br />      /* Write a byte */<br />      PORT_USI &amp;= ~(1&lt;&lt;PIN_USI_SCL);                // Pull SCL LOW.<br />      USIDR     = *(msg++);                        // Setup data.<br />      USI_TWI_Master_Transfer( tempUSISR_8bit );    // Send 8 bits on bus.<br />      <br />      /* Clock and verify (N)ACK from slave */<br />      DDR_USI  &amp;= ~(1&lt;&lt;PIN_USI_SDA);                // Enable SDA as input.<br />      if( USI_TWI_Master_Transfer( tempUSISR_1bit ) &amp; (1&lt;&lt;TWI_NACK_BIT) ) <br />      {<br />        if ( USI_TWI_state.addressMode )<br />          USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_ADDRESS;<br />        else<br />          USI_TWI_state.errorState = USI_TWI_NO_ACK_ON_DATA;<br />        return (FALSE);<br />      }<br />      USI_TWI_state.addressMode = FALSE;            // Only perform address transmission once.<br />    }<br />    /* Else masterRead cycle*/<br />    else<br />    {<br />      /* Read a data byte */<br />      DDR_USI   &amp;= ~(1&lt;&lt;PIN_USI_SDA);               // Enable SDA as input.<br />      *(msg++)  = USI_TWI_Master_Transfer( tempUSISR_8bit );<br /><br />      /* Prepare to generate ACK (or NACK in case of End Of Transmission) */<br />      if( msgSize == 1)                            // If transmission of last byte was performed.<br />      {<br />        USIDR = 0xFF;                              // Load NACK to confirm End Of Transmission.<br />      }<br />      else<br />      {<br />        USIDR = 0x00;                              // Load ACK. Set data register bit 7 (output for SDA) low.<br />      }<br />      USI_TWI_Master_Transfer( tempUSISR_1bit );   // Generate ACK/NACK.<br />    }<br />  }while( --msgSize) ;                             // Until all data sent/received.<br />  <br />  USI_TWI_Master_Stop();                           // Send a STOP condition on the TWI bus.<br /><br />/* Transmission successfully completed*/<br />  return (TRUE);<br />}<br /><br />/*---------------------------------------------------------------<br /> Core function for shifting data in and out from the USI.<br /> Data to be sent has to be placed into the USIDR prior to calling<br /> this function. Data read, will be return'ed from the function.<br />---------------------------------------------------------------*/<br />unsigned char USI_TWI_Master_Transfer( unsigned char temp )<br />{<br />  USISR = temp;                                     // Set USISR according to temp.<br />                                                    // Prepare clocking.<br />  temp  =  (0&lt;&lt;USISIE)|(0&lt;&lt;USIOIE)|                 // Interrupts disabled<br />           (1&lt;&lt;USIWM1)|(0&lt;&lt;USIWM0)|                 // Set USI in Two-wire mode.<br />           (1&lt;&lt;USICS1)|(0&lt;&lt;USICS0)|(1&lt;&lt;USICLK)|     // Software clock strobe as source.<br />           (1&lt;&lt;USITC);                              // Toggle Clock Port.<br />  do<br />  {<br />    _delay_us( T2_TWI/4 );              <br />    USICR = temp;                          // Generate positve SCL edge.<br />    while( !(PIN_USI &amp; (1&lt;&lt;PIN_USI_SCL)) );// Wait for SCL to go high.<br />    _delay_us( T4_TWI/4 );              <br />    USICR = temp;                          // Generate negative SCL edge.<br />  }while( !(USISR &amp; (1&lt;&lt;USIOIF)) );        // Check for transfer complete.<br />  <br />  _delay_us( T2_TWI/4 );                <br />  temp  = USIDR;                           // Read out data.<br />  USIDR = 0xFF;                            // Release SDA.<br />  DDR_USI |= (1&lt;&lt;PIN_USI_SDA);             // Enable SDA as output.<br /><br />  return temp;                             // Return the data from the USIDR<br />}<br /><br />/*---------------------------------------------------------------<br /> Function for generating a TWI Stop Condition. Used to release <br /> the TWI bus.<br />---------------------------------------------------------------*/<br />unsigned char USI_TWI_Master_Stop( void )<br />{<br />  PORT_USI &amp;= ~(1&lt;&lt;PIN_USI_SDA);           // Pull SDA low.<br />  PORT_USI |= (1&lt;&lt;PIN_USI_SCL);            // Release SCL.<br />  while( !(PIN_USI &amp; (1&lt;&lt;PIN_USI_SCL)) );  // Wait for SCL to go high.<br />  _delay_us( T4_TWI/4 );               <br />  PORT_USI |= (1&lt;&lt;PIN_USI_SDA);            // Release SDA.<br />  _delay_us( T2_TWI/4 );                <br />  <br />#ifdef SIGNAL_VERIFY<br />  if( !(USISR &amp; (1&lt;&lt;USIPF)) )<br />  {<br />    USI_TWI_state.errorState = USI_TWI_MISSING_STOP_CON;    <br />    return (FALSE);<br />  }<br />#endif<br /><br />  return (TRUE);<br />}[/syntax]<br /><br />Z góry dziękuje każdemu kto chce się podzielić wiedzą.<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=18553">GoRo3</a> — 7 sie 2018, o 19:27</p><hr />
]]></content>
</entry>
</feed>