This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

output of ds1307 to uart using 89v51rd2 is not correct

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.

Parents
  • "Because the posted code is copy/paste from different sources, sprinkled with some manual changes?"

    Now i'm sure that your software is wrong

    first as tell rank amateur
    unsigned int DS1307_get(unsigned char addr)
    { unsigned int ret=0;

    /* shouldn't you issue a start bit before the write ? */

    I2C_write(DS1307_ID); /* Connect to DS1307 */

    second : try too see with me this
    When you set the time you made

    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 */
    }
    

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

    
    
                    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);
    

Reply
  • "Because the posted code is copy/paste from different sources, sprinkled with some manual changes?"

    Now i'm sure that your software is wrong

    first as tell rank amateur
    unsigned int DS1307_get(unsigned char addr)
    { unsigned int ret=0;

    /* shouldn't you issue a start bit before the write ? */

    I2C_write(DS1307_ID); /* Connect to DS1307 */

    second : try too see with me this
    When you set the time you made

    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 */
    }
    

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

    
    
                    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);
    

Children
No data