近期在学习s5pv210 RTC的模块,遇到一个很古怪的问题:
设置时间day寄存器时,读出来的数据总是不对,经过一番调试后,发现官方手册里面的寄存器需要把星期和日的寄存器地址调换一下,就可以完美解决(不知道是自己手册的版本的问题)。
手册上面显示BCDDAYWEEK寄存器地址为:0xE280007C
BCDDAY寄存器地址为:0xE2800080
实际使用时需要写成:
BCDDAYWEEK寄存器地址为:0xE2800080
BCDDAY寄存器地址为: 0xE280007C
整体寄存器图片:
我使用的手册版本是:
我的代码如下:
(1)、修改前宏定义
#define RTC_BAST 0xE2800000
#define INTP (RTC_BAST + 0x30)
#define RTCCON (RTC_BAST + 0x40)
#define TICCNT (RTC_BAST + 0x44)
#define RTCALM (RTC_BAST + 0x50)
#define ALMSEC (RTC_BAST + 0x54)
#define ALMMIN (RTC_BAST + 0x58)
#define ALMHOUR (RTC_BAST + 0x5C)
#define ALMDAY (RTC_BAST + 0x60)
#define ALMMON (RTC_BAST + 0x64)
#define ALMYEAR (RTC_BAST + 0x68)
#define BCDSEC (RTC_BAST + 0x70)
#define BCDMIN (RTC_BAST + 0x74)
#define BCDHOUR (RTC_BAST + 0x78)
#define BCDDAYWEEK (RTC_BAST +
0x7C)
#define BCDDAY (RTC_BAST +
0x80)
#define BCDMON (RTC_BAST + 0x84)
#define BCDYEAR (RTC_BAST + 0x88)
#define CURTICCNT (RTC_BAST + 0x90)
#define rINTP (*(volatile unsigned int *)INTP)
#define rRTCCON (*(volatile unsigned int *)RTCCON)
#define rTICCNT (*(volatile unsigned int *)TICCNT)
#define rRTCALM (*(volatile unsigned int *)RTCALM)
#define rALMSEC (*(volatile unsigned int *)ALMSEC)
#define rALMMIN (*(volatile unsigned int *)ALMMIN)
#define rALMHOUR (*(volatile unsigned int *)ALMHOUR)
#define rALMDAY (*(volatile unsigned int *)ALMDAY)
#define rALMMON (*(volatile unsigned int *)ALMMON)
#define rALMYEAR (*(volatile unsigned int *)ALMYEAR)
#define rBCDSEC (*(volatile unsigned int *)BCDSEC)
#define rBCDMIN (*(volatile unsigned int *)BCDMIN)
#define rBCDHOUR (*(volatile unsigned int *)BCDHOUR)
#define rBCDDAYWEEK (*(volatile unsigned int *)BCDDAYWEEK)
#define rBCDDAY (*(volatile unsigned int *)BCDDAY)
#define rBCDMON (*(volatile unsigned int *)BCDMON)
#define rBCDYEAR (*(volatile unsigned int *)BCDYEAR)
#define rCURTICCNT (*(volatile unsigned int *)CURTICCNT)
struct rtc_time
{
unsigned int year;
unsigned int month;
unsigned int day;
//几号
unsigned int hour;
unsigned int minute;
unsigned int second;
unsigned int week;
//星期
};
------------------------------------------------------------------------------------------------------
测试写入读出函数:
//RTC修改时间
printf("------RTC------\n");
struct rtc_time tRead;
struct rtc_time tWrite =
{
.year = 2017,
.month = 4,
.day = 11,
.hour = 0,
.minute = 16,
.second = 50,
.week = 2,
};
rtc_set_time(&tWrite);
//delay_x(10000);
rtc_get_time(&tRead);
printf("the rWrite time is: %d:%d:%d:%d:%d:%d:%d\n", tRead.year, tRead.month, tRead.day, tRead.hour, tRead.minute, tRead.second, tRead.week);
------------------------------------------------------------------------------------------------------------------
得到打印结果:
------RTC------
the rWrite time is: 2017:4:1:0:16:50:2
--------------------------------------------------------------------------------------------------------------------
打印结果day不是11变成了。
(2)、将宏定义中BCDDAYWEEK和BCDDAY的地址互换后
#define RTC_BAST 0xE2800000
#define INTP (RTC_BAST + 0x30)
#define RTCCON (RTC_BAST + 0x40)
#define TICCNT (RTC_BAST + 0x44)
#define RTCALM (RTC_BAST + 0x50)
#define ALMSEC (RTC_BAST + 0x54)
#define ALMMIN (RTC_BAST + 0x58)
#define ALMHOUR (RTC_BAST + 0x5C)
#define ALMDAY (RTC_BAST + 0x60)
#define ALMMON (RTC_BAST + 0x64)
#define ALMYEAR (RTC_BAST + 0x68)
#define BCDSEC (RTC_BAST + 0x70)
#define BCDMIN (RTC_BAST + 0x74)
#define BCDHOUR (RTC_BAST + 0x78)
#define BCDDAYWEEK (RTC_BAST +
0x80)
#define BCDDAY (RTC_BAST +
0x7C)
#define BCDMON (RTC_BAST + 0x84)
#define BCDYEAR (RTC_BAST + 0x88)
#define CURTICCNT (RTC_BAST + 0x90)
--------------------------------------------------------------------------------------
打印结果如下:
------RTC------
the rWrite time is: 2017:4:11:0:16:50:2
从打印结果来看,设置day等于11成功了。
总结:参照s5pv210数据手册来设置RTC时,需要注意BCDDAYWEEK和BCDDAY这两个寄存器的地址需要互换。