Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

DS1307 if you do not send complete time or complete date the values are wrong.

2 posters

Go down  Message [Page 1 of 1]

feri



I solved it like this:

Code:


        if( m_addrPtr < 8 ){
            if     ( m_addrPtr < 3 ) updtTime(m_addrPtr);
            else if( m_addrPtr < 7 ) updtDate(m_addrPtr);
            else                     updtCtrl();
        }


void DS1307::updtTime(unsigned char reg)
{
    if (reg == 0) {
       m_time.setHMS( m_time.hour(), m_time.minute(), bcdToDec(m_data[0]/* & 0b01111111*/) );
    }
    else if (reg == 1) {
       m_time.setHMS( m_time.hour(), bcdToDec(m_data[1]), m_time.second() );
    }
    else if (reg == 2) {
       int hour;
       if( m_data[2] >= 0x40 )                          // 12 hour
       {
           hour = bcdToDec( m_data[2] & 0b00011111 );
           if( m_data[2] & (1<<5) ) hour += 12;         // PM
       }
       else hour = bcdToDec( m_data[2] & 0b00111111 );  // 24 hour

       m_time.setHMS( hour, m_time.minute(), m_time.second() );
    }
}

void DS1307::updtDate(unsigned char reg)
{
   if (reg == 4) {
      m_date.setDate( m_date.year(), m_date.month(), bcdToDec(m_data[4]) );
   }
   if (reg == 5) {
      m_date.setDate( m_date.year(), bcdToDec(m_data[5]), m_date.day() );
   }
   if (reg == 6) {
      m_date.setDate( 2000+bcdToDec(m_data[6]), m_date.month(), m_date.day() );
   }
}

Greetings and happy new year.



Last edited by arcachofo on Mon Jan 09, 2023 10:00 am; edited 1 time in total (Reason for editing : Mark as solved (green color))

arcachofo

arcachofo

Seems that you have a different implementation than SimulIDE.
And I don't understand what is exactly the problem, so not sure if this applies to SimulIDE.

I mean: why should be time or date wrong in the data is correct?

arcachofo

arcachofo

arcachofo wrote:I mean: why should be time or date wrong in the data is correct?
Now I see... the data is not correct.

There is also another issue:
After increasing address pointer it should overflow at 64, starting from 0 again:

arcachofo

arcachofo

Solution applied at 1.0.0 Rev 1195 (later versions also).

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum