Hello,
It is necessary to initialise the system registers as soon as possible after a reset, because some of these contain write once registers. This is why it is done early in main().
MMG135 wrote:
I noticed that the register assignments for SOPT, SPMSC2, SRTISC, SPMSC1, and IRQSC are being made in MC9S08GB60.h. Should I change these register assignments from that file instead of assigning them in main()?
I think that there is some misunderstanding about the device header file. This file defines the various hardware registers, and their bit usage, and under normal circumstances should never be altered. This file does not assign any value to the contents of a register - it does not genenerate any code.
With respect to the current draw, you might test stop 3 mode, rather than stop 2 mode, to see whether the current is any lower.
As I mentioned previoulsy, stop 2 mode gives partial power down, and so does not maintain the state of the internal hardware registers (but does latch the current GPIO output states). Your code does not address this issue, but neither does it clear the latched state by writing 1 to the PPDACK bit. It may be possible that you have floating inputs after wakeup from the first STOP, but I am not sure. With stop 3 mode, there is no partial power down, so the register states are continuously maintained.
If you wish to persist with stop 2, you will likely need something similar to the following function.
void stop_1sec( void){ RTI_init(); // Initialise RTI for wakeup save_state(); // Save current state of critical MCU I/O registers __asm stop; // Enter stop2 mode GPIO_init(); // Initialise GPIO registers - similar to startup restore_state(); // Restore state of critical MCU I/O registers SPMSC2_PPDACK = 1; // Release latched state}
// Part of main() function for ( ; ; ) { // Main loop __RESET_WATCHDOG(); for (i = 10; i; i--) { stop_1sec(); // Code for execution every second } // Code for execution every 10 seconds }
Regards,
Mac