2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
RH850 The MCU's RTC (real-time clock) uses the BCD (binary coded decimal) encoding format, supports automatic leap year recognition, and has the carry function for seconds, minutes, hours, days, weeks, months, and years. Among them, seconds and minutes are 60-bit, hours are 12-bit or 24-bit, weeks are 7-bit, days are 28, 29, 30, and 31-bit depending on the month, months are 12-bit, and years are 00 to 99.
Recently, we are using RenesasMCU The RTC of RH850 encountered an abnormal timing carry problem. When printing the time variable through UART, it was found that the carry of seconds and minutes was not the expected 60-digit carry, but was mistakenly displayed as 90-digit carry. This phenomenon attracted our attention.
However, using the emulator to directly monitorRTCWhen checking the internal SEC, MIN and other registers, it is found that they carry normally after reaching 0x59, which indicates that there is no problem with the timing function of the RTC itself.
After careful observation, we found a key rule: when the seconds exceed 09, the displayed value will jump directly to 16 and then continue to increase. This phenomenon shows that the problem may be in the conversion of data format. Because the RTC uses BCD encoding format internally, we treat it as decimal data when outputting it to the serial port debugging assistant through UART, resulting in deviation in the display.
To solve this problem, we modified the UART output processing format accordingly. After the adjustment, the time displayed on the serial port debugging assistant finally returned to normal, verifying that our analysis was correct.
In summary, the RTC internal registers of the RH850 MCU use a unique BCD encoding format, which requires us to pay special attention to format conversion when processing related data. Otherwise, it is easy to cause similar misunderstandings and problems.