This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Debugging the LPC932 with EPM900

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;}

}

When running the code in the emulator, it keeps hanging at the while loop. When debugging step by step it keeps also hanging at the while loop and I can see in the peripherals window for RTC that both, RTCH and RTCL, are not set. Even if I step trough the if function, the command RTCH = cnt / (cnt % 256); does not set the SFR, while cnt is 0x302 at this point (memory watch).
-interrupts are disabled, I use only flags


Any clue?
TIA!

  •         RTCL = cnt - (cnt % 256);

    That line is fatally flawed. It should almost certainly read

            RTCL = (cnt % 256)

    instead. Simulate what your code does, using some actual examples, on paper, and you'll see what's wrong. If you're still puzzled, re-read the definition of the % operator in your C textbook...

  • The code was different before at this particular line:

    RTCL = cnt - (cnt / 256)
    only this would calculate wrong. In both cases any value different from 0 should have been put to RTCL. But it wasn't. That's the problem. The next line is correct
    RTCH = cnt / 256;
    and it doesn't work, too.

  • 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.