We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello! Following problem. I intend to use the RTC of the LPC932 to create a delay function. Since it is a 23 bit counter it can count larger values to push the delay function from 1ms to 840ms using a 10 MHz crystal. The code:
void delay (uint data cnt) { RTCCON &= 0xFE; // clear RTCF RTCCON &= 0x7E; // disable RTC cnt = cnt * 78; // minimum 1msec if (cnt > 255) { // load argument into RTCL and RTCH, both 8 bit RTCL = cnt - (cnt % 256); RTCH = cnt / 256;} else { RTCH = 0; RTCL = cnt;} RTCCON |= 1 ; // enable RTC while (!(RTCCON & 0x80)); // wait for counter to be 0, RTCF flag will tell RTCCON &= 0x7E; // disable RTC counter and clear RTCF flag;} }
RTCL = cnt - (cnt % 256);
RTCL = (cnt % 256)
The code was different before at this particular line:
RTCL = cnt - (cnt / 256)
RTCH = cnt / 256;
OK, so the problem is that whatever you're calculating doesn't end up where you think it should. Another round of experiments next, then: 1) replace the computed values by some manifest constants, e.g. 0x03 and 0x02. Do these get written successfully? 2) Turn on listing of generated assembly code and inspect the *.lst file. Or post the core fragments of it here. 3) Re-read the datasheet of that chip very carefully. Is there even the slightest chance there's some protection protocol to use before you're allowed to overwrite those registers?
The problem is, that I don't know if has to be this way, how the software (uVision2) in connection with the EPM900 reacts while using the different modi. I tried both, Emulator and Simulator. Both didn't work in the end, but both behaved differently. While the Emulator didn't update the values of RTCH/RTCL shown in the RTC window when walking through the code in Step mode, the Simulator did. I could see (with the Simulator) the value of 0x302 to be put into RTCH/RTCL, but either in Go mode or in Step mode, it keeps hanging at the flag detect. Also with the Emulator. No clue of what I did wrong or where the code could be erroneous...
There's always the chance that these registers can't be read out by the Emulator, of course. If the flag never gets reset, that can have a large number of possible reasons. You'll really have to check the assembly output code generated by Keil against the device's datasheet, very carefully, to make sure you're programming that RTC correctly.