<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29552/output-of-ds1307-to-uart-using-89v51rd2-is-not-correct</link><description> 
i have done the interface between ds1307 and 89v51rd2.the output
to uart after reading time and date from the rtc ic not correct i am
getting like Time=36:32:0D,Date=1F/1C/3F.can any one help me. 
 </description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/145204?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 01:39:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4e491759-40e1-4710-b923-d40ed72845dd</guid><dc:creator>Selim Sefraoui</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;Because the posted code is copy/paste from different sources,
sprinkled with some manual changes?&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Now i&amp;#39;m sure that your software is wrong&lt;/p&gt;

&lt;p&gt;
first as tell rank amateur&lt;br /&gt;
unsigned int DS1307_get(unsigned char addr)&lt;br /&gt;
{ unsigned int ret=0;&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;/* shouldn&amp;#39;t you issue a start bit before the write ?
*/&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;
I2C_write(DS1307_ID); /* Connect to DS1307 */&lt;/p&gt;

&lt;p&gt;
second : try too see with me this&lt;br /&gt;
When you set the time you made&lt;/p&gt;

&lt;pre&gt;
void DS1307_settime(unsigned char hh, unsigned char mm, unsigned char ss)
{
        I2C_start();

        I2C_write(DS1307_ID);   /* connect to DS1307 */
        I2C_write(0x00);                /* Request RAM address at 00H */

        I2C_write(ss);                  /* Write sec on RAM address 00H */
        I2C_write(mm);                  /* Write min on RAM address 01H */
        I2C_write(hh);                  /* Write hour on RAM address 02H */
        //delay_20ms(20);
        I2C_stop();             /* Stop i2c bus */
}
&lt;/pre&gt;

&lt;p&gt;
you write on the adress 0 that means the start of second and you
write on it ss,mm,hh&lt;br /&gt;
when you write on the DS1307 the adress is incremented automatically
0x00,0x01,0x02 the same thing when you read&lt;br /&gt;
but on your read subroutine you are reading just one value from the
specified adress (adr)&lt;br /&gt;
and each time you read the same adress&lt;br /&gt;
where are the value of SEC,MIN,HOUR,DATE,MOTNH,YEAR ?&lt;br /&gt;
i think if you don&amp;#39;t specifie it will be take as &amp;#39;0&amp;#39;&lt;/p&gt;

&lt;pre&gt;


                sec   = (DS1307_get(SEC));
                delay_10ms(10);
                min   = (DS1307_get(MIN));
                delay_10ms(10);
                hour  = (DS1307_get(HOUR));
                delay_10ms(10);
                date  = (DS1307_get(DATE));
                delay_10ms(10);
                month = (DS1307_get(MONTH));
                delay_10ms(10);
                year  = (DS1307_get(YEAR));
                delay_10ms(10);
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/142996?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 01:22:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4af43fd7-1bd1-46ab-9ab8-cf63ced8209c</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;Because the posted code is copy/paste from different sources,
sprinkled with some manual changes?&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Before you can start debugging you do, of course, have to
understand what the system &lt;i&gt;&lt;b&gt;should&lt;/b&gt;&lt;/i&gt; do!&lt;/p&gt;

&lt;p&gt;
So the first step in debugging is to &lt;b&gt;think&lt;/b&gt; about what
&lt;i&gt;&lt;b&gt;should&lt;/b&gt;&lt;/i&gt; be happening. Then you need to &lt;b&gt;think&lt;/b&gt; how
that differs from what &lt;i&gt;actually&lt;/i&gt; happens.&lt;/p&gt;

&lt;p&gt;
But it all still comes down to &lt;b&gt;thinking&lt;/b&gt;: it&amp;#39;s no use
pressing the &amp;#39;run&amp;#39; button and then just saying, &amp;quot;it doesn&amp;#39;t
work&amp;quot;.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/140042?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 01:12:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fc13e8b1-1f5f-4997-8f35-63bd4b407a10</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;why you apply BCD2HEX after this&amp;quot;&lt;/p&gt;

&lt;p&gt;
Because the posted code is copy/paste from different sources,
sprinkled with some manual changes?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/130853?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 01:02:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5a9d71b3-62f5-48f1-a112-8fce0e96da56</guid><dc:creator>Selim Sefraoui</dc:creator><description>&lt;p&gt;&lt;p&gt;
i noticed on the unsigned int DS1307_get(unsigned char addr) that
you return with this:&lt;br /&gt;
ret is on BCD but when you apply return
((((ret&amp;gt;&amp;gt;4)&amp;amp;0x0F)*10)+(ret&amp;amp;0x0F))&lt;br /&gt;
that mean that the returned value is not on BCD why you apply BCD2HEX
after this&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/136600?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 00:59:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:551312ec-eb1b-49bc-b264-aed205dfcce9</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
The most important tool for debugging is the one between your ears
- you need to learn to &lt;b&gt;think&lt;/b&gt; about the problem that you are
seeing, &lt;b&gt;think&lt;/b&gt; about what could possibly cause those problems,
&lt;b&gt;think&lt;/b&gt; about what tests &amp;amp; observations to make to identify
the problems, etc, etc,...&lt;/p&gt;

&lt;p&gt;
Again, here are some tips:&lt;/p&gt;

&lt;p&gt;
&lt;a href="http://www.8052.com/faqs/120313"&gt;www.8052.com/.../120313&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
&lt;a target="_blank" href="http://www.eetimes.com/discussion/break-point/4027526/Developing-a-good-bedside-manner?pageNumber=0"&gt;www.eetimes.com/.../Developing-a-good-bedside-manner&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Debugging&lt;/b&gt; is an essential part of the development
process.&lt;/p&gt;

&lt;p&gt;
Developing software is not just a matter of writing code - you
&lt;i&gt;&lt;b&gt;need&lt;/b&gt;&lt;/i&gt; to be able to debug it.&lt;/p&gt;

&lt;p&gt;
Similarly for hardware development.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/131880?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 00:57:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9f6c9554-278b-478c-8e5a-af64ba9993cc</guid><dc:creator>rank amateur</dc:creator><description>&lt;p&gt;&lt;pre&gt;
unsigned int DS1307_get(unsigned char addr)
{
        unsigned int ret=0;

&lt;b&gt;/* shouldn&amp;#39;t you issue a start bit before the write ? */&lt;/b&gt;

        I2C_write(DS1307_ID);   /* Connect to DS1307 */
        I2C_write(addr);                /* Request RAM address on DS1307 */

        I2C_start();                    /* Start i2c bus */

        I2C_write(DS1307_ID+1); /* Connect to DS1307 for Read */
        ret = I2C_read();               /* Receive data */

        I2C_noack();

        I2C_stop();                             /* Stop i2c bus */

   return ((((ret&amp;gt;&amp;gt;4)&amp;amp;0x0F)*10)+(ret&amp;amp;0x0F));;
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/130852?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 00:52:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cd4e33d4-56dc-463b-b0e6-b382209d49a6</guid><dc:creator>Selim Sefraoui</dc:creator><description>&lt;p&gt;&lt;p&gt;
i&amp;#39;m not familiarize with C just ASM (A51) but i see in your source
that&lt;br /&gt;
you wrote&lt;br /&gt;
for example&lt;br /&gt;
min = (DS1307_get(MIN));&lt;br /&gt;
and in the subroutine DS1307_get(MIN) min means the adress on the
DS1307&lt;br /&gt;
but in the main prog you made MIN=0 it should be 1&lt;br /&gt;
sec=0 ; min = 1 ; hour = 2 ; day = 4 ; month = 5 ; year = 6&lt;/p&gt;

&lt;p&gt;
try to be sure that the voltage in the &amp;quot;pin 3&amp;quot; &amp;lt; 1.25 * Vcc&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/127103?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2011 00:01:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c9100698-eca8-4002-a6af-1fa7916b2626</guid><dc:creator>pradee kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
the ds1307 is working fine.i am getting the 1 HZ square wave in
pin 7 of ds1307.i am getting the data in serial but it is not proper
(time=36:32:00 and date=1F/1C/3F).what is the problem with the
code...i loaded the code as&lt;/p&gt;

&lt;pre&gt;
void main(void)
{
        unsigned int sec, min, hour, date, month, year;
   //uchar sec=0x00, min=0x00, hour=0x00, date=0x00, month=0x00, year=0x00;
        Sys_Init();
        DS1307_init();
        DS1307_settime(0x20,0x20,0x20);         /* Set Time (hh:mm:ss) */
        DS1307_setdate(0x01,0x01,0x01);         /* Set Date (dd/mm/yy) */
        while (1)
        {
                //watch_dog();
                        GLED=0;
                        delay_10ms(10);
                        GLED=1;
                /* Get Date &amp;amp; Time */
                sec   = (DS1307_get(SEC));
                delay_10ms(10);
                min   = (DS1307_get(MIN));
                delay_10ms(10);
                hour  = (DS1307_get(HOUR));
                delay_10ms(10);
                date  = (DS1307_get(DATE));
                delay_10ms(10);
                month = (DS1307_get(MONTH));
                delay_10ms(10);
                year  = (DS1307_get(YEAR));
                delay_10ms(10);




                datas[0] = hextoascii(((BCD2HEX(hour))&amp;gt;&amp;gt;4)&amp;amp;0x0F);
                datas[1] = hextoascii((BCD2HEX(hour))&amp;amp;0x0f);
                datas[2]=&amp;#39;:&amp;#39;;
                datas[3]=hextoascii(((BCD2HEX(min))&amp;gt;&amp;gt;4)&amp;amp;0x0F);
                datas[4]=hextoascii((BCD2HEX(min))&amp;amp;0x0f);
                datas[5]=&amp;#39;:&amp;#39;;
                datas[6]=hextoascii(((BCD2HEX(sec))&amp;gt;&amp;gt;4)&amp;amp;0x0F);
                datas[7]=hextoascii((BCD2HEX(sec))&amp;amp;0x0f);
                datas[8]=&amp;#39; &amp;#39;;
                datas[9]=hextoascii(((BCD2HEX(date))&amp;gt;&amp;gt;4)&amp;amp;0x0F);
                datas[10]=hextoascii((BCD2HEX(date))&amp;amp;0x0f);
                datas[11]=&amp;#39;/&amp;#39;;
                datas[12]=hextoascii(((BCD2HEX(month))&amp;gt;&amp;gt;4)&amp;amp;0x0F);
                datas[13]=hextoascii((BCD2HEX(month))&amp;amp;0x0f);
                datas[14]=&amp;#39;/&amp;#39;;
                datas[15]=hextoascii(((BCD2HEX(year))&amp;gt;&amp;gt;4)&amp;amp;0x0F);
                datas[16]=hextoascii((BCD2HEX(year))&amp;amp;0x0f);
                datas[17]=&amp;#39;\r&amp;#39;;
                com_t_index=0;
                com_t_length=18;
                TX_RX=1;
                watch_dog();
                TI=1;

            delay_50ms(50);
        }
}

void DS1307_init(void)
{
        I2C_start();
        I2C_write(DS1307_ID);
        I2C_write(0x00);
        I2C_write(0x00);
        I2C_stop();
        I2C_start();
        I2C_write(DS1307_ID);
        I2C_write(0x07);
        I2C_write(0x10);
        I2C_stop();
}
unsigned int DS1307_get(unsigned char addr)
{
        unsigned int ret=0;
        I2C_write(DS1307_ID);   /* Connect to DS1307 */
        I2C_write(addr);                /* Request RAM address on DS1307 */

        I2C_start();                    /* Start i2c bus */

        I2C_write(DS1307_ID+1); /* Connect to DS1307 for Read */
        ret = I2C_read();               /* Receive data */

        I2C_noack();

        I2C_stop();                             /* Stop i2c bus */

   return ((((ret&amp;gt;&amp;gt;4)&amp;amp;0x0F)*10)+(ret&amp;amp;0x0F));;
}

void DS1307_settime(unsigned char hh, unsigned char mm, unsigned char ss)
{
        I2C_start();

        I2C_write(DS1307_ID);   /* connect to DS1307 */
        I2C_write(0x00);                /* Request RAM address at 00H */

        I2C_write(ss);                  /* Write sec on RAM address 00H */
        I2C_write(mm);                  /* Write min on RAM address 01H */
        I2C_write(hh);                  /* Write hour on RAM address 02H */
        //delay_20ms(20);
        I2C_stop();             /* Stop i2c bus */
}

void DS1307_setdate(unsigned char dd, unsigned char mm, unsigned char yy)
{
        I2C_start();

        I2C_write(DS1307_ID);   /* connect to DS1307 */
        I2C_write(0x04);                /* Request RAM address at 04H */

        I2C_write(dd);                  /* Write date on RAM address 04H */
        I2C_write(mm);                  /* Write month on RAM address 05H */
        I2C_write(yy);                  /* Write year on RAM address 06H */
        //delay_20ms(20);
        I2C_stop();                             /* Stop i2c bus */
}

void I2C_delay(void)
{
        unsigned char i;

        for(i=0; i&amp;lt;I2C_DELAY; i++);
}

void I2C_clock(void)
{
        I2C_delay();

        SCL_1 = 1;              /* Start clock */

        I2C_delay();

        SCL_1 = 0;              /* Clear SCL */
}

void I2C_start(void)
{
        if(SCL_1)
        SCL_1 = 0;              /* Clear SCL */

        SDA_1 = 1;        /* Set SDA */
        SCL_1 = 1;              /* Set SCL */

        I2C_delay();

        SDA_1 = 0;        /* Clear SDA */

        I2C_delay();

        SCL_1 = 0;        /* Clear SCL */
}

void I2C_stop(void)
{
        if(SCL_1)
        SCL_1 = 0;                      /* Clear SCL */

        SDA_1 = 0;                      /* Clear SDA */
        I2C_delay();

        SCL_1 = 1;                      /* Set SCL */

        I2C_delay();

        SDA_1 = 1;                      /* Set SDA */
}

bit I2C_write(unsigned char dat)
{
        bit data_bit;
        unsigned char i;

        for(i=0;i&amp;lt;8;i++)                             /* For loop 8 time(send data 1 byte) */
        {
                data_bit = dat &amp;amp; 0x80;              /* Filter MSB bit keep to data_bit */
                SDA_1 = data_bit;                               /* Send data_bit to SDA */

                I2C_clock();                            /* Call for send data to i2c bus */

                dat = dat&amp;lt;&amp;lt;1;
        }

        SDA_1 = 1;                      /* Set SDA */

        I2C_delay();

        SCL_1 = 1;                      /* Set SCL */

        I2C_delay();

        data_bit = SDA_1;       /* Check acknowledge */
//      I2C_ack();
/*      datas[0]=hextoascii((data_bit));
         com_t_index=0;
                com_t_length=1;
                TX_RX=1;
                watch_dog();
                TI=1;*/
        SCL_1 = 0;                      /* Clear SCL */

        I2C_delay();

        return data_bit;        /* If send_bit = 0 i2c is valid */

}

unsigned char I2C_read(void)
{
        bit rd_bit;
        unsigned char i,dat;

        for(i=0;i&amp;lt;8;i++)             /* For loop read data 1 byte */
        {
                I2C_delay();

                SCL_1 = 1;                      /* Set SCL */

                I2C_delay();

                rd_bit = SDA_1;         /* Keep for check acknowledge   */
                dat = dat&amp;lt;&amp;lt;1;
                dat = dat | rd_bit;     /* Keep bit data in dat */

                SCL_1 = 0;                      /* Clear SCL */
        }

        return dat;
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/119459?ContentTypeID=1</link><pubDate>Tue, 13 Sep 2011 23:00:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4034a008-567f-4c92-a71a-f840546a4a12</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Do you really think that&amp;#39;s going to be in any way possible
&lt;i&gt;based on the information you&amp;#39;ve provided?&lt;/i&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/105269?ContentTypeID=1</link><pubDate>Tue, 13 Sep 2011 22:10:20 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f9880dc9-beab-446e-93f2-c7fc170a5664</guid><dc:creator>pradee kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
i am getting the output but it is not correct..can u help me&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/79577?ContentTypeID=1</link><pubDate>Tue, 13 Sep 2011 21:54:14 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7c37ec04-c753-49d1-8a1c-ddb3cdd69021</guid><dc:creator>Scripture k</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;a href="http://www.keil.com/forum/19526/"&gt;http://www.keil.com/forum/19526/&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: output of ds1307 to uart using 89v51rd2 is not correct</title><link>https://community.arm.com/thread/59832?ContentTypeID=1</link><pubDate>Tue, 13 Sep 2011 21:35:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1550b94f-53fb-4344-87ed-dd09d6d27d80</guid><dc:creator>pradee kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
i have did the BCD2HEX and HEX2ascii convertion.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>