Features RTC M41T56

M41T56 is a Real Time Clock chip, which is an analogue of the popular DS1307. And although even the pinout of the microcircuit is the same, they have significant differences, which I will try to talk about.

Short description


I will not dwell on the operation of the IIC bus, I note just that both chips have the address 0xd0. To work with time, the microcircuit contains seven account registers and a control register. Account registers contain numbers in binary decimal format, however some bits have special meaning.

Registers
xxx - the value of the bit is not defined.
functionindexbitspossible values
76543210
seconds0x00STtens of secondsunits of seconds0 - 59
minutes0x01xxxtens of minutesunits of minutes0 - 59
clock0x02SebSBdozens of hourshours units0 - 23
day0x03xxxxxxxxxxxxxxxday of the week1 - 7
day of the month0x04xxxxxxdozens of daysunits of the day1 - (28 | 29 | 30 | 31)
month0x05xxxxxxxxxdesunits of the month1 - 12
year0x06tens of yearsunits of the year0 - 99
control register0x07OUTFTScorrection amount-

Bits
x - after switching on, the state of the bit can be any.
bitafter resetdescription
STxWhen writing 1 to this bit, the generator stops
CEBxWhen the CEB (Century Enable Bit) bit is set, then when a new century is reached, the CB (Century Bit) bit will change the value to the opposite.
CBx
OUT1When the OUT (OUTput level) and FT (Frequency Test) bits are equal to zero, the FT / OUT pin is pressed to the ground. With FT = 1, the output FT / OUT is 512 Hz and the OUT bit does not matter.
FT0
SxRTC stroke calibration mark.

The differences begin in the assignment of bits 7, 6 and 5 of the clock register. In the M41T56, bits 7 and 6 are used to indicate the transition to the new century, and bits 5 and 4 are used to count tens of hours. Moreover, hours can be counted only in mode 24, AM / PM mode is not available. In DS1307, bit 7 is not used, a zero in bit 6 indicates that counting mode 24 is used, and in this case bits 5 and 4 contain tens of hours. If bit 6 is one, then bit 5 becomes the AM / PM flag, and bit 4 contains tens of hours.

Significant differences are in the control register, which contains the word correction stroke.

Course correction


M41T56 allows you to compensate for the error of the quartz resonator in the range from -62 to +124 ppm, which gives a deviation of not more than ± 5 seconds per month. For compensation, the six least significant bits of the control register are responsible. Bits 4-0 contain an unsigned integer of the correction value, and bit 5 sets the correction direction. If bit 5 contains zero, then the stroke slows down in increments of 2.034 ppm, otherwise RTC accelerates in increments of 4.068 ppm. This is inconvenient, so I sketched a couple of simple functions for converting from ppm to correction word and vice versa.

/* Маска для получения только значения калибровки без знака. */
#define MASK_CALIBR             ((1 << 4) | (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0))
/* Маска для получения только значения калибровки без знака. */
#define MASK_CALIBR_SIGN        (1 << 5)
/**
 * Получение значения коррекции хода.
 * @param caliber Калибровочное слово из RTC.
 * @return Коррекция хода в ppm.
 */
int8_t caliber_to_ppm(uint8_t caliber)
{
        int8_t result = caliber & MASK_CALIBR;
        result = (uint8_t) result * 2;
        if ((caliber & MASK_CALIBR_SIGN) != 0) {
                result = -result;
        } else {
                result = (uint8_t) result * 2;
        }
        return result;
}
/**
 * Получение калибровочного слова.
 * @param ppm Коррекция хода в ppm.
 * @return Калибровочное слово для RTC.
 */
uint8_t ppm_to_caliber(int8_t ppm)
{
        uint8_t result;
        if (ppm < 0) {
                result = (uint8_t) (-ppm + 1) / 2;
                result |= MASK_CALIBR_SIGN;
        } else {
                result = (uint8_t) (ppm + 2) / 4;
        }
        return result;
}

Fault detection


Neither DS1307, but M41T56 can detect generation errors, but they guarantee that when the power is turned on, some bits will be in a certain state. M41T56 when enabled in the control register will be 10xxxxxx. To track program crashes, you can use the following algorithm. If, when the microcontroller is turned on, the RTC control register contains 10xxxxxx, then there was a power failure and a value must be written into the register whose high bits are not equal to 10. The simplest thing is to write the correction word with bits 7 and 6 equal to zero.

Literature



Also popular now: