Microchip
直播中

李秀荣

8年用户 204经验值
私信 关注
[问答]

RTCC未使用MC代码示例运行

您好,我有一个PIC32 MX795F512L在USB启动板运行在MPLABX 3.50与XC32 V1.40编译器。我正在运行一个timeJordDebug代码示例,我在这里找到了http://vi.ECe.CONELL…xAMPLE/PLBILIG/I,将C文件(如下所示)粘贴到MPLABX中。如果我跨过并到达if StimeMeNFF(!)CHECTCRTCCRUNUNIN(3),我猜时钟没有运行,0返回。不知道下一步该怎么做。请让我知道我需要做什么来让时钟运行。谢谢。

以上来自于百度翻译


      以下为原文

    Hello,
I have a PIC32MX795F512L on a USB starter board running in MPLABX 3.50 with the XC32 v1.40 compiler. I'm running a time_date code sample that I found here https://people.ece.cornel...xamples/plib_examples/
I pasted the c file (shown below) into MPLABX. If I step through and get to the if statement
if(!CheckRtccRunning(3)) , I guess the clock is not running and 0 is returned. Not sure what to try next.
Please let me know what I need to do to get the clock running.
Thanks

#include
#ifndef _RTCC
#error "This example needs a PIC32MX processor with RTCC peripheral present. Aborting build!"
#endif // _RTCC
// local function prototypes
int CheckRtccRunning(int secWait);
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
#define SYS_FREQ (80000000L)
int main(void)
{
rtccTime tm, tm1; // time structure
rtccDate dt, dt1; // date structure
SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
RtccInit(); // init the RTCC
while(RtccGetClkStat()!=RTCC_CLK_ON); // wait for the SOSC to be actually running and RTCC to have its clock source
// could wait here at most 32ms
// when using the RtccSetTimeDate() function, the write operation is enabled if needed and then restored to the initial value
// so that we don't have to worry about calling RtccWrEnable()/RtccWrDisable() functions
// let's start setting the current date
{
// one way to do it
tm.l=0;
tm.sec=0x30;
tm.min=0x27;
tm.hour=0x14;
dt.wday=2;
dt.mday=0x26;
dt.mon=0x06;
dt.year=0x18;
RtccSetTimeDate(tm.l, dt.l);
}
// however, much easier to do it should be:
RtccSetTimeDate(0x14273000, 0x18062602); // time is MSb: hour, min, sec, rsvd. date is MSb: year, mon, mday, wday.
tm1.l=RtccGetTime();
dt1.l=RtccGetDate();
// can check that the time and date are the ones we just set
if(tm.hour!=tm1.hour ||tm.min!=tm1.min)
{
return 0;
}
if(dt.l!=dt1.l) // check for proper date
{
return 0;
}
// we can read the time and date in a single operation
RtccGetTimeDate(&tm1, &dt1);
// now that we know the RTCC clock is up and running, it's easier to start from fresh:
RtccOpen(tm.l, dt.l, 0); // set time, date and calibration in a single operation
// check that the RTCC is running
if(!CheckRtccRunning(3))
{
return 0;
}
// another way to see the RTCC is tunning: check the SYNC bit
while(RtccGetSync()); // wait sync to be low
while(!RtccGetSync()); // wait to be high
while(RtccGetSync()); // wait sync to be low again
// other RTCC operations
// adjust the RTCC timing
RtccSetCalibration(200); // value to calibrate with at each minute
// enabling the RTCC output pin
RtccSelectPulseOutput(1); // select the seconds clock pulse as the function of the RTCC output pin
RtccSelectPulseOutput(0); // select the alARM pulse as the function of the RTCC output pin
RtccOutputEnable(1); // enable the Output pin of the RTCC
return 1;
}
 
int CheckRtccRunning(int secWait)
{
#define WAIT_FOR_SEC_TMO 1100 // how many ms to wait for the RTCC seconds count to change
 
rtccTime t0, t1;
int fail;
int secCnt;
unsigned int tStart;
 
 
for(secCnt=0, fail=0; secCnt {
tStart=ReadCoreTimer();
t0.l=RtccGetTime();
do
{
t1.l=RtccGetTime();
}while((t1.sec==t0.sec) && (ReadCoreTimer()-tStart)<(SYS_FREQ/2000)*WAIT_FOR_SEC_TMO); // wait seconds change
 
if(t1.sec==t0.sec)
{
fail=1;
break; // failed
}
}
return !fail;
}
 

回帖(2)

郑雅颖

2018-9-11 15:09:42
你安装了一个32千赫晶体(在Y3上的董事会)?SoSC不能没有它,RTCC需要SOSC。我不会对代码本身进行评论,更不用说在主体()的末尾出现了一个明显的错误:选择报警输出到RTCC PIN,并贬低绝对的ASIT返回语句。底线:首先得到SOSC RU。尊敬的戴夫

以上来自于百度翻译


      以下为原文

   
Have you installed a 32 kHz crystal (at Y3 on the board)?  SOSC can't run without it, and the RTCC requires SOSC.
 
I won't comment on the code itself other than to mention there is a glaring error near the end of main() that selects the alarm output to go to the RTCC pin and to disparage the absolutely asinine return statements.
 
Bottom line: First get SOSC running.
 
Regards,
 
Dave
举报

h1654155275.5998

2018-9-11 15:17:18
嗨,戴夫,没有水晶,谢谢你的帮助。

以上来自于百度翻译


      以下为原文

    Hi Dave,
 
There is no crystal.
 
Thanks for the help.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分