Hi,
Below is the test code. Please check if you can replicate this behavior. I have a 0.1uF capacitor and a 100k resistor connected in parallel from the IRQ pin to GND. Charging the capacitor and then allowing it to discharge upon entering STOP triggers the IRQ interrupt to wake the MCU at a regular interval.
#include "mc9s08pa16.h"
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
__interrupt VectorNumber_Virq_wdog void IRQ_isr(void) {
IRQ_SC_IRQACK = 1; // clear interrupt flag
}
void main(void) {
SYS_SOPT1 = 0x09; // 00001001 BKGDPE = 1, RSTPE = 0, STOPE = 1; // this register can only be written once, on reset
SYS_SOPT2 = 0xB0; // 10110000 TXDME = 1, RXDFE = 1, RXDCE = 1 // this register can only be written once, on reset
DisableInterrupts;
PMC_SPMSC1 = 0x01; // this is supposed to be written on startup, even if all zero - enable band gap buffer
PMC_SPMSC2 = 0x00; // this is supposed to be written on startup, even if all zero
NVM_FCLKDIV_FDIV = 0x04; // divide 5MHz down to 1MHz, datasheet setting required to read/write NVM
// Disable Watchdog
WDOG_CNT = 0xC520; // write the 1st unlock word
WDOG_CNT = 0xD928; // write the 2nd unlock word
WDOG_TOVAL = 1000; // setting timeout value
WDOG_CS2 = WDOG_CS2_CLK_MASK; // setting 1-kHz clock source
WDOG_CS1 = WDOG_CS1_EN_MASK; // enable counter running
WDOG_CS1_STOP = 0; // disable Watchdog in stop
WDOG_CS1_UPDATE = 1; // allow sw to disable the watchdog
WDOG_CS1_EN = 0; // disable the Watchdog
// Configure System Clock
ICS_C1 = 0x04; // 00000100 - default settings
ICS_C2_BDIV = 2; // divide bus clock by 4 --> 20MHz/4 = 5Mhz
ICS_C3 = 0x4C; // trim internal reference clock here ... using oscilloscope
// configure output ports
PORT_PTCOE_PTCOE7 = 1; // enable port C7 as output - TxD
PORT_PTAOE_PTAOE5 = 1; // enable port A5 as output - RTI
PORT_PTAD_PTAD5 = 1; // output high on A5 to charge - RTI
// configure UART
SCI1_BDH_SBNS = 0; // 1 stop bit
SCI1_C1_LOOPS = 0; // separate RxD and TxD pins
SCI1_C1_M = 0; // 8 data bits
SCI1_C1_PE = 0; // data parity check enable
SCI1_BD = 8; // baud rate is 5000000/(8*16) = 39062.5, use 40000 in Docklight, 38400 in Bootloader
SCI1_C2_TIE = 1; // transmit interrupt when buffer is empty
SCI1_C2_RIE = 1; // receive interrupt when data is received
SCI1_C2_TE = 1; // enable transmitter
SCI1_C2_RE = 1; // enable receiver
SCI1_C2_TIE = 0; // will get turned on by a message
EnableInterrupts;
for(;;) {
PORT_PTAOE_PTAOE5 = 0; // disable port A5 as output - RTI
RTC_SC1_RTIE = 0; // disable RTC interrupt
IRQ_SC = 0x52; // 01010010, disable pullup, falling edge, enable IRQ pin, clear flag, interrupt enable, edges only
_Stop;
IRQ_SC = 0x00; // disable IRQ
PORT_PTAOE_PTAOE5 = 1; // enable port A5 as output - RTI
PORT_PTAD_PTAD5 = 1; // set port high to charge RTI
}
}
Thanks! Jonas