📜 ⬆️ ⬇️

Features RTC M41T56

M41T56 is a chip of Real Time Clock, which is an analogue of the popular DS1307. And even though the pinout of the microcircuits coincides, they have significant differences, which I will try to tell about.

Short description


I will not stop at the work of the IIC bus, I’ll just note that both chips have the address 0xd0. To work with the time of the chip contain seven registers of the account and the control register. Counting registers contain numbers in binary coded decimal format, however some bits have a special meaning.

Registers
xxx - the value of a bit is undefined.
functionindexbitspossible values
76fivefour32one0
seconds0x00STtens of secondsunits of seconds0 - 59
minutes0x01xxxtens of minutesunits of minutes0 - 59
clock0x02SEBSBtens of hoursunits of hours0 - 23
day0x03xxxxxxxxxxxxxxxday of the week1 - 7
day of the month0x04xxxxxxtens of daysunits of the day1 - (28 | 29 | 30 | 31)
month0x05xxxxxxxxxdessunits of the month1 - 12
year0x06tens of yearsunits of the year0 - 99
control register0x07OutFTScorrection value-

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

Differences begin in the assignment of bits 7, 6 and 5 of the watch register. In M41T56, bits 7 and 6 are used to indicate the transition to the new century, and bits 5 and 4 are used to count dozens of hours. Moreover, the counting hours is possible only in mode 24, AM / PM mode is not available. In DS1307, bit 7 is not used, zero in bit 6 indicates that the count mode is 24, 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 dozens of hours.

Significant differences exist in the control register, which contains the word for stroke correction.
')

Stroke 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 no more than ± 5 seconds per month. For the compensation of the six lower bits of the control register. Bits 4-0 contain an integer without the sign of the correction value, and bit 5 specifies the direction of the correction. If bit 5 contains zero, the course slows down in 2,034 ppm increments; otherwise, the RTC is accelerated in 4,068 ppm increments. This is inconvenient, so I sketched a couple of simple functions to convert from ppm to word correction and back.

/*        . */ #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; } 

Crash Detection


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

Literature


Source: https://habr.com/ru/post/457796/


All Articles