I have commented out all my code in main.c and
put blinking code from technical support,then I found something like this:
as long as I put "STOP" line in the code , the qg8 doesn't work alone.
in debugging mode, the MCU stops there (at "stop line")until an
interrupt signal at PTA5 to wake it up;then I see the flickering at
pin6;
while in stand-alone mode, I can't see the flickering after the
interrupt signal has been generated like what I did in debugging mode.
if I remove the "stop" line(entering stop), everything works,I don't know what I did
wrong in the code or misunderstanding the stop mode??
please see the simplified code below,
void init_sysopt (byte COP_Option) {
switch (COP_Option){
case 0: SOPT1 = 0x62;break; //62-debug mode;60 normal /* COP disabled */
case 1: SOPT1 = 0xE2;break; /* COP enabled */
default:break;
}
SOPT2 = 0X01;
SPMSC1 = 0x65;
}
void InitRTI() {
// SRTISC = 0b01110001;
SRTISC = 0b01110000; //disable RTI while debugging
/* ||||||||
|||||+++-- RTIS = RTI delay select: 001=8 msec
||||+----- unimplemented
|||+------ RTIE = RTI int enable: 1=enabled
||+------- RTICLKS = RTI clock select: 1=external src
|+-------- RTIACK = RTI flag acknowledge
+--------- RTIF = RTI flag
*/
}
void init_portpullup (void) {
PTAPE = 0xff;
PTBPE = 0xff-PTBPE_PTBPE6_MASK;
PTASE = 0x00;
PTADS = 0x00;
}
void incs_init (byte c1,byte c2){
byte i;
if (NVICSTRM != 0xff){
ICSTRM = NVICSTRM;
}
ICSC1 =c1;
for (i=0;i<=0x10;i++){
__RESET_WATCHDOG ();
}
ICSC2 = c2;
/*ICSC2_BDIV = 3;*/
while (ICSC1_CLKS != ICSSC_CLKST){
}
}
/* MTIM initialization */
void mtim_init (void) {
MTIMCLK = 0x08;
MTIMMOD = 0xff;
MTIMSC = 0x60;
}
/* STOP initialization */
void stop_init (byte mode) { /* to choose which stop mode to enter */
switch (mode) {
case 1: SPMSC2 = 0X02 ; break;
case 2: SPMSC2 = 0X03 ; break;
case 3: IRQSC =0x17; break;
}
}
/* STOP entering */
void stop_enterring (void){
asm ("stop");
}
/* IRQ initialization */
void init_IRQ (void) {
IRQSC = 0b00010010; /* enable interrupt;*/
}
/* MCU ports initialization */
void mcu_init (void){
GreenLed =0; //PTBD_PTBD7 = 0;
PTBDD_PTBDD7 = 1;
RedLed = 0; //PTBD_PTBD6 = 0;
PTBDD_PTBDD6 = 1;
charger_control = charger_off; //PTBD_PTBD5 = 1;
PTBDD_PTBDD5 = 1;
Xfer =0; // PTBD_PTBD4 = 0;
PTBDD_PTBDD4 = 1;
PTBDD_PTBDD3 = 0;
PTBDD_PTBDD2 = 0;
PTBDD_PTBDD1 = 0;
PTBDD_PTBDD0 = 0;
PTADD_PTADD0 = 0;
PTADD_PTADD2 = 0;
BuzzerControl = 0; //PTAD_PTAD3 = 0;
PTADD_PTADD3 = 1;
/*PTADD_PTADD4 = 1;*/
/* KBIPE_KBIPE2 = 1;
KBISC_KBIE = 1;
KBISC_KBACK = 1; */
/*PTAPE_PTAPE2 = 1;*/ /*if enabling this one,could get rid of extern resitor */
SPMSC1_BGBE = 1; /* bandgap enabling */
}
void AllInOneINI(void){
init_sysopt(COP_Disabled); //start with COP disablbed
/*ICSC2_BDIV = 3;*/
incs_init (0x05,0xc0); /* FLL output as Clock source,divided by 8:1M bus frequency */
mcu_init ();
init_portpullup ();
adc_ini();
init_IRQ ();
stop_init(1);
}
void main(void) {
AllInOneINI(); ///start with COP disabled, shut down output for safety
/// everything else has to start after INI//
stop_enterring(); //need a calendar here and first test be done 12 hours after installation
EnableInterrupts; /* enable interrupts */
PTBDD_PTBDD6 = 1; //set data direction to out
for(; {
PTBD_PTBD6 = 0;
PTBD_PTBD6 = 1;
__RESET_WATCHDOG(); /* feeds the dog */
}
}