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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2019-02-03T01:39:10+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=8&amp;t=21933&amp;mode</id>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2019-02-03T01:39:10+01:00</updated>
<published>2019-02-03T01:39:10+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216337#p216337</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216337#p216337"/>
<title type="html"><![CDATA[Re: Attiny2313 software i2c]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216337#p216337"><![CDATA[
<div class="quotetitle"><b>Quote:</b></div><div class="quotecontent"><br />Dla mnie lepiej czytelne osobno.<br /></div><br />A kto ci zabronić się bawić w ten sposób ? no kto - chcesz to się męcz<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 3 lut 2019, o 01:39</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wchpikus]]></name></author>
<updated>2019-02-02T23:14:12+01:00</updated>
<published>2019-02-02T23:14:12+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216334#p216334</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216334#p216334"/>
<title type="html"><![CDATA[Re: Attiny2313 software i2c]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216334#p216334"><![CDATA[
A co za roznica czy jest w jednej zmiennej czy w buforze..zajmuje tyle samo chyba?<br />Dla mnie lepiej czytelne osobno.<br /><br />Wysłane z mojego SM-G950F przy użyciu Tapatalka<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3859">wchpikus</a> — 2 lut 2019, o 23:14</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2019-02-02T22:06:03+01:00</updated>
<published>2019-02-02T22:06:03+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216333#p216333</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216333#p216333"/>
<title type="html"><![CDATA[Re: Attiny2313 software i2c]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216333#p216333"><![CDATA[
<div class="quotetitle">wchpikus napisał(a):</div><div class="quotecontent"><br />A po co ladujesz do bufora ....<br /></div><br />Bo to jest zdrowe i normalne podejście ...<br /><br /><div class="quotetitle">wchpikus napisał(a):</div><div class="quotecontent"><br />.... zamiast bezposrednio do zmiennych?<br /></div><br />A to jest dopiero niestety ale bezsens ... i strata czasu już nie mówiąc o niepotrzebnym tragicznym wydłużaniu i gmatwaniu kodu źródłowego<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 2 lut 2019, o 22:06</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wchpikus]]></name></author>
<updated>2019-02-02T17:39:22+01:00</updated>
<published>2019-02-02T17:39:22+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216330#p216330</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216330#p216330"/>
<title type="html"><![CDATA[Re: Attiny2313 software i2c]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216330#p216330"><![CDATA[
A po co ladujesz do bufora zamiast bezposrednio do zmiennych?<br /><br />Zczytaj co masz w calym buforze po zczytaniu, cos chyba zle tam jest..<br /><br />Wysłane z mojego SM-G950F przy użyciu Tapatalka<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=3859">wchpikus</a> — 2 lut 2019, o 17:39</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[BARVX]]></name></author>
<updated>2019-02-02T17:34:12+01:00</updated>
<published>2019-02-02T17:34:12+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216329#p216329</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216329#p216329"/>
<title type="html"><![CDATA[Attiny2313 software i2c]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=21933&amp;p=216329#p216329"><![CDATA[
Witam<br />Korzystam z tej biblioteki do programowej obsługi i2c.<br /><br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br /><br />#include &quot;i2csoft.h&quot;<br /><br />#define Q_DEL _delay_loop_2(3)<br />#define H_DEL _delay_loop_2(5)<br /><br /><br />void SoftI2C_Init()<br />{<br />SDAPORT&amp;=(1&lt;&lt;SDA);<br />SCLPORT&amp;=(1&lt;&lt;SCL);<br /><br />SOFT_I2C_SDA_HIGH;<br />SOFT_I2C_SCL_HIGH;<br /><br />}<br />void SoftI2C_Start()<br />{<br />SOFT_I2C_SCL_HIGH;<br />H_DEL;<br /><br />SOFT_I2C_SDA_LOW;<br />H_DEL;  <br />}<br /><br />void SoftI2C_Stop()<br />{<br /> SOFT_I2C_SDA_LOW;<br /> H_DEL;<br /> SOFT_I2C_SCL_HIGH;<br /> Q_DEL;<br /> SOFT_I2C_SDA_HIGH;<br /> H_DEL;<br />}<br /><br />uint8_t SoftI2C_Write_Byte(uint8_t data)<br />{<br /> <br /> uint8_t i;<br /> <br /> for(i=0;i&lt;8;i++)<br /> {<br />SOFT_I2C_SCL_LOW;<br />Q_DEL;<br /><br />if(data &amp; 0x80)<br />SOFT_I2C_SDA_HIGH;<br />else<br />SOFT_I2C_SDA_LOW;<br /><br />H_DEL;<br /><br />SOFT_I2C_SCL_HIGH;<br />H_DEL;<br /><br />while((SCLPIN &amp; (1&lt;&lt;SCL))==0);<br /><br />data=data&lt;&lt;1;<br />}<br /> <br />//The 9th clock (ACK Phase)<br />SOFT_I2C_SCL_LOW;<br />Q_DEL;<br /><br />SOFT_I2C_SDA_HIGH;<br />H_DEL;<br /><br />SOFT_I2C_SCL_HIGH;<br />H_DEL;<br /><br />uint8_t ack=!(SDAPIN &amp; (1&lt;&lt;SDA));<br /><br />SOFT_I2C_SCL_LOW;<br />H_DEL;<br /><br />return ack;<br /> <br />}<br /> <br /> <br />uint8_t SoftI2C_Read_Byte(uint8_t ack)<br />{<br />uint8_t data=0x00;<br />uint8_t i;<br /><br />for(i=0;i&lt;8;i++)<br />{<br /><br />SOFT_I2C_SCL_LOW;<br />H_DEL;<br />SOFT_I2C_SCL_HIGH;<br />H_DEL;<br /><br />while((SCLPIN &amp; (1&lt;&lt;SCL))==0);<br /><br />if(SDAPIN &amp;(1&lt;&lt;SDA))<br />data|=(0x80&gt;&gt;i);<br /><br />}<br /><br />SOFT_I2C_SCL_LOW;<br />Q_DEL;//Soft_I2C_Put_Ack<br /><br />if(ack)<br />{<br />SOFT_I2C_SDA_LOW;<br />}<br />else<br />{<br />SOFT_I2C_SDA_HIGH;<br />}<br />H_DEL;<br /><br />SOFT_I2C_SCL_HIGH;<br />H_DEL;<br /><br />SOFT_I2C_SCL_LOW;<br />H_DEL;<br /><br />return data;<br /><br />}<br /><br /> void SoftI2C_Write_Buf(uint8_t SLA, uint8_t adr, uint8_t len, uint8_t *buf)<br /> {<br /><br /> SoftI2C_Start();<br /> SoftI2C_Write_Byte(SLA);<br /> SoftI2C_Write_Byte(adr);<br /> while(len--) SoftI2C_Write_Byte(*buf++);<br /> SoftI2C_Stop();<br /> }<br /><br /><br />void SoftI2C_Read_Buf(uint8_t SLA, uint8_t adr, uint8_t len, uint8_t *buf)<br />{<br /><br />SoftI2C_Start();<br />SoftI2C_Write_Byte(SLA);<br />SoftI2C_Write_Byte(adr);<br />SoftI2C_Start();<br />SoftI2C_Write_Byte(SLA+1);<br />while(len--) *buf++ = SoftI2C_Read_Byte(len ? NACK : ACK);<br />SoftI2C_Stop();<br />}<br /><br />// konwersja liczby dziesiętnej na BCD<br />uint8_t dec2bcd(uint8_t dec) {<br />return ((dec / 10)&lt;&lt;4) | (dec % 10);<br />}<br /><br />// konwersja liczby BCD na dziesiętną<br />uint8_t bcd2dec(uint8_t bcd) {<br />    return ((((bcd) &gt;&gt; 4) &amp; 0x0F) * 10) + ((bcd) &amp; 0x0F);<br />}[/syntax]<br /><br />Za pomocą tej biblioteki próbuje obsługiwać ds1307. Napisałem program którym chcę odczytać godzinę, ale po odczycie jedynie sekundy są dobrze odczytywane a godzina i minuty pokazuje jakiś bzdury. <br /><br />[syntax=c]#include &lt;avr/io.h&gt;<br />#include &lt;util/delay.h&gt;<br />#include &lt;avr/interrupt.h&gt;<br /><br /><br />#include &quot;HD44780.h&quot;<br /><br />#include &quot;i2csoft.h&quot;<br /><br /><br />volatile uint8_t flaga;<br /><br /><br />int main(void)<br />{<br />DDRB |= (1&lt;&lt;PB2);<br /><br />PORTD |= (1&lt;&lt;PD2);<br /><br />LCD_Initalize();<br /><br />SoftI2C_Init();<br /><br />MCUCR |= (1&lt;&lt;ISC01);<br />GIMSK |= (1&lt;&lt;INT0);<br /><br />sei();<br /><br />uint8_t bufor&#91;10&#93;,sekundy,minuty,godziny;<br /><br /><br />bufor&#91;0&#93;=dec2bcd(34);//sekundy<br />bufor&#91;1&#93;=dec2bcd(10);//minuty<br />bufor&#91;2&#93;=dec2bcd(23);//godziny<br />//bufor&#91;3&#93;=dec2bcd(6);//pn-nd<br />//bufor&#91;4&#93;=dec2bcd(23);//1-31<br />//bufor&#91;5&#93;=dec2bcd(8);//miesiac<br />//bufor&#91;6&#93;=dec2bcd(18);//rok<br />bufor&#91;7&#93;=dec2bcd(10);//SQW 1Hz<br /><br />SoftI2C_Write_Buf(208,0,8,bufor);<br /><br /><br /><br /><br />while(1)<br />{<br />if(flaga)<br />{<br />SoftI2C_Read_Buf(208, 0, 8, bufor);<br /><br /><br />sekundy = bcd2dec( bufor&#91;0&#93; );<br />minuty = bcd2dec( bufor&#91;1&#93; );<br />godziny = bcd2dec( bufor&#91;2&#93; );<br />//dzien = bcd2dec( bufor&#91;3&#93; );<br />//data = bcd2dec( bufor&#91;4&#93; );<br />//miesiac = bcd2dec( bufor&#91;5&#93; );<br />//rok = bcd2dec( bufor&#91;6&#93; );<br /><br />LCD_GoTo(4, 0);<br />if(godziny&lt;10) LCD_WriteText(&quot;0&quot;);<br />Liczba(godziny);<br /><br />LCD_WriteText(&quot;/&quot;);<br /><br />if(minuty&lt;10) LCD_WriteText(&quot;0&quot;);<br />Liczba(minuty);<br /><br />LCD_WriteText(&quot;/&quot;);<br /><br />if(sekundy&lt;10)LCD_WriteText(&quot;0&quot;);<br />Liczba(sekundy);<br />flaga = 0;<br /><br />}<br /><br /><br />}<br />}<br /><br />ISR(INT0_vect)<br />{<br />flaga=1;<br />//PORTB ^= (1&lt;&lt;PB2);<br />}[/syntax]<br />Ktoś wie gdzie może być błąd. Piny SDA, SCL i SQW są podciągnięte do VCC przez rezystory 4,7k<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=15944">BARVX</a> — 2 lut 2019, o 17:34</p><hr />
]]></content>
</entry>
</feed>