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

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2017-02-04T04:41:28+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=30&amp;t=15927&amp;mode</id>
<entry>
<author><name><![CDATA[mario713]]></name></author>
<updated>2017-02-04T04:41:28+01:00</updated>
<published>2017-02-04T04:41:28+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=181569#p181569</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=181569#p181569"/>
<title type="html"><![CDATA[Re: RTC po SPI problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=181569#p181569"><![CDATA[
Pewnie problem już rozwiązałeś albo pomoc już niepotrzebna ale może innym się przyda np. osobom które trafią tu z google tak jak ja gdy szukałem jak podłączyć ten RTC do mikrokontrolera.<br />A więc:<br /><br />Pewnie zmieniłeś ten kawałek kodu:<br />[syntax=c]//Strobe CE pin of &lt;span class=&quot;posthilit&quot;&gt;DS1302&lt;/span&gt; high and low<br />#define CE_STROBE_HIGH() IO_PIN_STROBE_HIGH(PORTD, 4)<br />#define CE_STROBE_LOW() IO_PIN_STROBE_LOW(PORTD, 4)<br /> <br />//Strobe SCLK pin of &lt;span class=&quot;posthilit&quot;&gt;DS1302&lt;/span&gt; high and low<br />#define SCLK_STROBE_HIGH() IO_PIN_STROBE_HIGH(PORTD, 6)<br />#define SCLK_STROBE_LOW() IO_PIN_STROBE_LOW(PORTD, 6)<br /> <br />//Strobe IO pin of &lt;span class=&quot;posthilit&quot;&gt;DS1302&lt;/span&gt; high and low<br />#define IO_STROBE_HIGH() IO_PIN_STROBE_HIGH(PORTD, 7)<br />#define IO_STROBE_LOW() IO_PIN_STROBE_LOW(PORTD, 7)[/syntax]<br /><br />ale podejrzewam że zapomniałeś o tej części:<br /><br />[syntax=c]//Configure port pin directions for read and write DS1302<br />#define WRITE_MODE() (DDRD |= 0xe0)<br />#define READ_MODE() (DDRD = (DDRD|0xe0)&amp;0xbf)[/syntax]<br /><br />Nie wiem czy to wszystko, czy coś jeszcze trzeba edytować bo sam jeszcze dumam nad tym, bo mi po wyłączeniu zasilania i ponownym włączeniu &quot;cofa&quot; zegar do pewnego momentu a po wyłączeniu na dłuższy czas widać że zegar chodził. Jak rozwiąże swój problem do edytuje post i dodam resztę informacji <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><br /><br />@EDIT<br /><br />Doszedłem do tego że ta część kodu powodowała &quot;cofanie&quot; zegara:<br /><br />[syntax=c]//Disable Clock Halt<br />    reset();<br />    write_byte(DT_SECONDS_READ);<br />    byte_second = read_byte();<br />    reset();<br />    write_byte(DT_SECONDS_WRITE);<br />    write_byte(byte_second &amp; 0x7f);<br />    reset();[/syntax]<br /><br />Teraz wszystko śmiga <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" /><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=16346">mario713</a> — 4 lut 2017, o 04:41</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wozek]]></name></author>
<updated>2016-08-04T21:47:31+01:00</updated>
<published>2016-08-04T21:47:31+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165445#p165445</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165445#p165445"/>
<title type="html"><![CDATA[Re: RTC po SPI problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165445#p165445"><![CDATA[
Sytuacja nieco sie zmienila, tak, jestem lamus, nie zauwazylem, ze GND mi wypadl :/<br /><br />Co prawda nadal nie dziala ale teraz juz wyswietla &quot;00:00:00 2000-00-00&quot; <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /><br /><br />Czy ktos z Was moglbym mi w jakis sposob pomoc ?<br /><br /><br />Pozdrawiam, <br />Wozek<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=14623">wozek</a> — 4 sie 2016, o 21:47</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[mirekk36]]></name></author>
<updated>2016-08-03T20:17:27+01:00</updated>
<published>2016-08-03T20:17:27+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165352#p165352</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165352#p165352"/>
<title type="html"><![CDATA[Re: RTC po SPI problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165352#p165352"><![CDATA[
<span style="color: #FF0000">tylko dlatego że kolega jest nowy na forum to na spokojnie przypomnę, że kod źródłowy a szczególnie tak długi formatujemy wg instrukcji na tym forum: <!-- l --><a class="postlink-local" href="http://forum.atnel.pl/topic7402.html" >topic7402.html</a><!-- l --><br /><br />proszę edytować swój post i poprawić wg instrukcji ok?</span><p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=54">mirekk36</a> — 3 sie 2016, o 20:17</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[wozek]]></name></author>
<updated>2016-08-03T20:37:10+01:00</updated>
<published>2016-08-03T20:13:47+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165351#p165351</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165351#p165351"/>
<title type="html"><![CDATA[RTC po SPI problem]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=15927&amp;p=165351#p165351"><![CDATA[
Czesc, <br /><br />od dwoch wieczorow nie moge sobie poradzic z obsluga RTC (tak wiem, dlugo, ale to dopiero moj trzeci projekcik, wczesnie byla migajaca dioda i samo LCD). <br />Zamiast czasu i daty zalaczone kody wystwietlaja mi 255:85:85 20165-25-255 <img src="https://forum.atnel.pl/images/smilies/icon_e_sad.gif" alt=":(" title="Smutny" /> i nic sie nie zmienia, zawsze te same wartosci. <br />RTC zakupione z botlanda : <!-- m --><a class="postlink" href="https://botland.com.pl/moduly-rtc/4462-zegar-czasu-rzeczywistego-modul-rtc-ds1302-bateria.html?search_query=WSR-04462&amp;results=1" >https://botland.com.pl/moduly-rtc/4462- ... &amp;results=1</a><!-- m --><br />Plytka stykowa sprawdzana osiem razy, program jako calosc dziala nie dziala jedna linijka kodu : ds1302 = get_date_time();<br />Calych kodow nie wklejam, tylko to co od RTC, reszta dziala bez zarzutu, dioda mryga, LCD wystwietla (jak nie wywoluje pobrania czasu to wstawione na sztywno wartosci wyswietlaja sie poprawnie).<br />Dzialanie sprawdzone zarowno z podlaczonym programatorem (zasilanie z niego) jaki i z odlaczony i zasilaczem. RTC zasilane z baterii VCC i GND z RTC nie podlaczone, jak podlacze tez glupieje ale inaczej.<br />Biblioteke sciagnalem z netu, ale oczywiscie musialem ja nieco pozmieniac i pewnie tu lezy problem, tyle, ze juz nie mam pomyslow co i jak. <br /><br />AVR : Atmega 328P-PU<br />Polaczenia stykowki (wlasnie sprawdzilem 9 raz): <br />MEGA PD4 - RTC CE<br />MEGA PD6 - RTC SCLK<br />MEGA PD7 - RTC IO<br /><br />Mozecie pomoc ? <br />[syntax=c]//#define F_CPU 1000000UL<br />#include &lt;avr/io.h&gt;<br />#include &quot;lcdvtwi.h&quot;<br />#include &quot;atmega328.h&quot;<br />#include &quot;rtc.h&quot;<br /><br />volatile dateTime ds1302;<br /><br />int main(void)<br />{<br />SET_PB1_AS_WRITE; // Dioda LED<br /><br />    lcdvtwi_init();<br />lcdvtwi_led_on();<br />    lcdvtwi_clear();<br /><br />    lcdvtwi_clear();<br />lcdvtwi_set_cursor(0,0);<br />lcdvtwi_write_text(&quot;Przed init&quot;);<br />_delay_ms(500);<br /><br />rtc_init();<br /><br />lcdvtwi_clear();<br />lcdvtwi_set_cursor(0,0);<br />lcdvtwi_write_text(&quot;Po init&quot;);<br />_delay_ms(500);<br /><br />ds1302.second = 3;<br />ds1302.minute = 2;<br />ds1302.hour = 1;<br />ds1302.day = 1;<br />ds1302.month = 2;<br />ds1302.year = 16;<br /><br /><br /><br />//set_date_time(ds1302);<br /><br /><br />while (1) {<br />if (IS_PB1_HIGH) {<br />SET_PB1_TO_LOW;<br />} else {<br />SET_PB1_TO_HIGH;<br />}<br />ds1302 = get_date_time(); //jak to zaremuje to wczesniej ustawione wartosci wystwietlaja sie prawidlowo<br /><br />show_date_date_time(ds1302);<br /><br />_delay_ms(1000);<br />}<br />}<br /><br />void show_date_date_time(dateTime ds1302) {<br />char tekst&#91;17&#93;;<br /><br />lcdvtwi_set_cursor(0, 0);<br />sprintf(tekst, &quot;%02d:%02d:%02d&quot;, ds1302.hour, ds1302.minute, ds1302.second);<br />lcdvtwi_write_text(tekst);<br /><br />lcdvtwi_set_cursor(0,1);<br /><br />sprintf(tekst, &quot;20%02d-%02d-%02d&quot;, ds1302.year, ds1302.month, ds1302.day);<br />lcdvtwi_write_text(tekst);<br />}[/syntax]<br />[syntax=c]/******************************<br /> * file name: rtc.h<br /> ******************************/<br />#ifndef RTC_H<br />#define RTC_H<br /> <br />//Data type to hold calendar/clock data<br />typedef struct<br />{<br />    unsigned char second;<br />    unsigned char minute;<br />    unsigned char hour;<br />    unsigned char date;<br />    unsigned char month;<br />    unsigned char day;<br />    unsigned char year;<br />} dateTime;<br /> <br />/*******************************************************************<br />  Interface function to initialize RTC: 1. Disable Clock Halt<br />                                        2. Set to 24 hour mode<br />                                        3. Disable Write Protection<br />  No Calendar/Clock will be changed<br />********************************************************************/<br />void rtc_init(void);<br /> <br />//Interface function to read Calendar/Clock value<br />dateTime get_date_time(void);<br /> <br />//Interface function to set Calendar/Clock value<br />void set_date_time(dateTime dt);<br /> <br />#endif[/syntax]<br /><br />[syntax=c]/**************************<br /> * file name: rtc.c<br /> **************************/<br />  <br />#include &lt;avr/io.h&gt;<br />#include &lt;stdint.h&gt;<br />#define F_CPU 7372800UL //7.3728MHz<br />#include &lt;util/delay.h&gt;<br />#include &quot;rtc.h&quot;<br /> <br />//Strobe &quot;pin&quot; on &quot;port&quot; high<br />#define IO_PIN_STROBE_HIGH(port, pin)   \<br />        __asm__ __volatile__ (          \<br />        &quot;sbi %0, %1&quot;                    \<br />        : /* no output */               \<br />        : &quot;I&quot; (_SFR_IO_ADDR(port)),     \<br />          &quot;I&quot; (pin))<br /> <br />//Strobe &quot;pin&quot; on &quot;port&quot; low<br />#define IO_PIN_STROBE_LOW(port, pin)    \<br />        __asm__ __volatile__ (          \<br />        &quot;cbi %0, %1&quot;                    \<br />        : /* no output */               \<br />        : &quot;I&quot; (_SFR_IO_ADDR(port)),     \<br />          &quot;I&quot; (pin))<br /> <br />//Timing requirement between data output and clock stobe high<br />#define DATA_TO_CLK_SETUP()     \<br />        __asm__ __volatile__ (  \<br />        &quot;nop\n\t&quot;               \<br />        &quot;nop\n\t&quot;               \<br />        ::)<br /> <br /><br />//Strobe CE pin of DS1302 high and low<br />#define CE_STROBE_HIGH() IO_PIN_STROBE_HIGH(PORTD, 4)<br />#define CE_STROBE_LOW() IO_PIN_STROBE_LOW(PORTD, 4)<br /> <br />//Strobe SCLK pin of DS1302 high and low<br />#define SCLK_STROBE_HIGH() IO_PIN_STROBE_HIGH(PORTD, 6)<br />#define SCLK_STROBE_LOW() IO_PIN_STROBE_LOW(PORTD, 6)<br /> <br />//Strobe IO pin of DS1302 high and low<br />#define IO_STROBE_HIGH() IO_PIN_STROBE_HIGH(PORTD, 7)<br />#define IO_STROBE_LOW() IO_PIN_STROBE_LOW(PORTD, 7)<br /> <br />//Calendar/Clock burst read and write command<br />#define DT_BURST_READ 0xbf<br />#define DT_BURST_WRITE 0xbe<br /> <br />//RTC register seconds byte read and write command<br />#define DT_SECONDS_READ 0x81<br />#define DT_SECONDS_WRITE 0x80<br /> <br />//RTC register hours byte read and write command<br />#define DT_HOURS_READ 0x85<br />#define DT_HOURS_WRITE 0x84<br /> <br />//RTC register WP write<br />#define DT_WP_WRITE 0x8e<br /> <br />//Configure port pin directions for read and write DS1302<br />#define WRITE_MODE() (DDRD |= 0xe0)<br />#define READ_MODE() (DDRD = (DDRD|0xe0)&amp;0xbf)<br /><br />//Disable io pull-up in read mode<br />#define DISABLE_IO_PULLUP() (PORTD &amp;= 0xbf)<br />//Read i/o value from DS1302<br />#define IO_READ() (PIND &amp; 0x40)<br /> <br />//Prepare CE and SCLK for new operation<br />static void reset(void)<br />{<br />    //Pull both CE and SCLK low to start with   <br />    SCLK_STROBE_LOW();<br />    CE_STROBE_LOW();<br /> <br />    //Comms. begin with CE stobe high<br />    CE_STROBE_HIGH();<br />}<br /> <br />//Read one byte of Calendar/Clock data<br />static unsigned char read_byte(void)<br />{<br />    unsigned char byte = 0;<br />    unsigned char i;<br /> <br />    //Port pins in read mode for data read<br />    READ_MODE();<br />    //Disable internal I/O pull-up<br />    DISABLE_IO_PULLUP();<br /> <br />    //Read one byte of Calendar/Clock data<br />    for(i = 0; i != 8; ++i)<br />    {<br />        //Strobe SCLK low to read I/O<br />        SCLK_STROBE_LOW();<br />        _delay_us(1);<br /> <br />        if(IO_READ() != 0)<br />        {<br />            byte |= 1&lt;&lt;i;<br />        }<br />        //Strobe SCLK high for next I/O read<br />        SCLK_STROBE_HIGH();<br />        _delay_us(1);<br />    }<br /> <br />    return byte;<br />}<br /> <br />//Write one byte of control or Calendar/Clock data<br />static void write_byte(unsigned char byte)<br />{<br />    unsigned char i;<br /> <br />    //Port pins in write mode<br />    WRITE_MODE();<br /> <br />    //Write one byte of control or Calendar/Clock data<br />    for(i = 0; i != 8; ++i)<br />    {<br />        //Start clock cycle with SCLK low<br />        SCLK_STROBE_LOW();<br />        _delay_us(1);<br /> <br />        //Write bit value to I/O pin of DS1302          <br />        if(((1&lt;&lt;i)&amp;byte) == 0)<br />        {<br />            IO_STROBE_LOW();<br />        }<br />        else<br />        {<br />            IO_STROBE_HIGH();<br />        }<br /> <br />        DATA_TO_CLK_SETUP(); //Data to clock setup<br /> <br />        //End clock cycle with SCLK high<br />        SCLK_STROBE_HIGH();<br />        _delay_us(1);       <br />    }<br />     <br />}<br /> <br />//Read 7 bytes of Calendar/Clock data<br />static dateTime read_dt_block(void)<br />{<br />    unsigned char dt_byte;<br />    unsigned char byte_pos;<br />    dateTime dt = {0};<br /> <br />    //Always do a reset before a new operation<br />    reset();<br /> <br />    //Write the clock burst read command into DS1302<br />    write_byte(DT_BURST_READ);<br /> <br />    //Read each of the 7 Calendar/Clock bytes from DS1302<br />    for(byte_pos = 0; byte_pos != 7; ++byte_pos)<br />    {<br />        //Read one byte of calendar/clock data<br />        dt_byte = read_byte();<br />         <br />        //Copy the read byte to the right place<br />        switch(byte_pos)<br />        {<br />            case 0:<br />                        dt.second = dt_byte;<br />                        break;<br />            case 1:<br />                        dt.minute = dt_byte;<br />                        break;<br />            case 2:<br />                        dt.hour = dt_byte;<br />                        break;<br />            case 3:<br />                        dt.date = dt_byte;<br />                        break;<br />            case 4:<br />                        dt.month = dt_byte;<br />                        break;<br />            case 5:<br />                        dt.day = dt_byte;<br />                        break;<br />            case 6:<br />                        dt.year = dt_byte;<br />                        break;<br />        }<br />    }<br /> <br />    //Always end an operation with a reset<br />    reset();<br />    return dt;<br />}<br /> <br />//Write 8 bytes of Calendar/Clock data<br />static void write_dt_block(dateTime dt)<br />{<br />    unsigned char dt_byte;<br />    unsigned char byte_pos;<br /> <br />    //Always do a reset before a new operation<br />    reset();<br /> <br />    //Write burst write command byte to DS1302<br />    write_byte(DT_BURST_WRITE);<br /> <br />    //Write each of the 7 Calendar/Clock byte to DS1302<br />    for(byte_pos = 0; byte_pos != 7; ++byte_pos)<br />    {<br />        //Copy the right byte to write<br />        switch(byte_pos)<br />        {<br />            case 0:<br />                        dt_byte = dt.second;<br />                        break;<br />            case 1:<br />                        dt_byte = dt.minute;<br />                        break;<br />            case 2:<br />                        dt_byte = dt.hour;<br />                        break;<br />            case 3:<br />                        dt_byte = dt.date;<br />                        break;<br />            case 4:<br />                        dt_byte = dt.month;<br />                        break;<br />            case 5:<br />                        dt_byte = dt.day;<br />                        break;<br />            case 6:<br />                        dt_byte = dt.year;<br />                        break;<br />        }<br /> <br />        //Write one byte of Calendar/Clock data<br />        write_byte(dt_byte);<br />    }<br /> <br />    //Must write the 8th byte of the Calendar/Clock register<br />    write_byte(0);<br /> <br />    //Always end an operation with a reset<br />    reset();<br />}<br /> <br />/*******************************************************************<br />  Interface function to initialize RTC: 1. Disable Clock Halt<br />                                        2. Set to 24 hour mode<br />                                        3. Disable Write Protection<br />  No Calendar/Clock will be changed<br />********************************************************************/<br />void rtc_init(void)<br />{<br />    unsigned char byte_second;<br />    unsigned char byte_hour;<br /> <br />    //Disable Clock Halt<br />    reset();<br />    write_byte(DT_SECONDS_READ);<br />    byte_second = read_byte();<br />    reset();<br />    write_byte(DT_SECONDS_WRITE);<br />    write_byte(byte_second &amp; 0x7f);<br />    reset();<br /> <br />    //Set to 24 hour mode<br />    write_byte(DT_HOURS_READ);<br />    byte_hour = read_byte();<br />    reset();<br />    write_byte(DT_HOURS_WRITE);<br />    write_byte(byte_hour &amp; 0x7f);<br />    reset();<br /> <br />    //Disable Write Protection<br />    write_byte(DT_WP_WRITE);<br />    write_byte(0);<br />    reset();<br />}<br /> <br />//Interface function to read Calendar/Clock value<br />dateTime get_date_time(void)<br />{<br />    dateTime dt;<br />     <br />    //Read raw calendar/clock block from DS1302<br />    dt = read_dt_block();<br /> <br />    /*************************************************************<br />     Convert from the raw BCD Calendar/Clock data to normal decimal<br />     values. Hour is treated differently in 24 and AM/PM mode.<br />     Also the day of week is left as is.<br />    **************************************************************/<br />    dt.second = (((dt.second&amp;0x70)&gt;&gt;4)*10) + (dt.second&amp;0x0f);<br />    dt.minute = (((dt.minute&amp;0x70)&gt;&gt;4)*10) + (dt.minute&amp;0x0f);<br />    if((dt.hour&amp;0x80) == 0)<br />    {<br />        dt.hour = (((dt.hour&amp;0x30)&gt;&gt;4)*10) + (dt.hour&amp;0x0f);<br />    }<br />    dt.date = (((dt.date&amp;0x30)&gt;&gt;4)*10) + (dt.date&amp;0x0f);<br />    dt.month = (((dt.month&amp;0x10)&gt;&gt;4)*10) + (dt.month&amp;0x0f);<br />    dt.year = (((dt.year&amp;0xf0)&gt;&gt;4)*10) + (dt.year&amp;0x0f);<br /> <br />    return dt;<br />}<br /> <br />//Interface function to set Calendar/Clock value<br />void set_date_time(dateTime dt)<br />{<br />    /**************************************************************<br />     Convert from normal decimal Calendar/Clock value to BCD. Hour<br />     is treated differently in 24 and AM/PM mode. Also the day of<br />     week is left as is.<br />    ***************************************************************/   <br />    dt.second = ((dt.second/10)&lt;&lt;4) | (dt.second%10);<br />    dt.minute = ((dt.minute/10)&lt;&lt;4) | (dt.minute%10);<br />    if((dt.hour&amp;0x80) == 0)<br />    {<br />        dt.hour = ((dt.hour/10)&lt;&lt;4) | (dt.hour%10);<br />    }<br />    dt.date = ((dt.date/10)&lt;&lt;4) | (dt.date%10);<br />    dt.month = ((dt.month/10)&lt;&lt;4) | (dt.month%10);<br />    dt.year = ((dt.year/10)&lt;&lt;4) | (dt.year%10);<br /> <br />    write_dt_block(dt);<br />}[/syntax]<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=14623">wozek</a> — 3 sie 2016, o 20:13</p><hr />
]]></content>
</entry>
</feed>