[求助](续)MC9S12XDP512 STOP MODE
- UID
- 145512
- 性别
- 男
|
[求助](续)MC9S12XDP512 STOP MODE
各位大侠:
Datasheet上说,CCR中的S位控制STOP使能,当S位为0时才能进入STOP MODE.复位后S位为1,如何清零S位呢?
请指教!小弟先谢过了! |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
The system stop modes are entered if the CPU executes the STOP instruction and the XGATE doesn't execute a thread and the XGFACT bit in the XGMCTL register is cleared. Depending on the state of the PSTP bit in the CLKSEL register the MCU goes into pseudo stop mode or full stop mode. Please refer to CRG section. |
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
谢谢版主!
我试过了,执行asm STOP(默认PSTP=0的情况下)是没什么作用的,该语句下面的程序照样执行(没有任何中断唤醒).但如果把 asm STOP; 换成 asm WAI;下面的语句就不会再执行了,进入了WAIT模式.所以我觉得根本就没有进入STOP模式. |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
XGFACT会被清0吧,不过这个我还没做过实验。
已经找到清S位的答案了:asm{ANDCC #0x7F},再执行asm STOP;否则执行asm STOP就相当于执行了asm NOP;但现在又出现一个问题,如果在执行asm STOP之前打开5ms的周期中断(Period Interrupt Timer,而非RTI),MCU会被唤醒。应该不能唤醒才对啊。 |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
打开的是5msPIT,而非RTI。在STOP模式下,PIT是被关断的。所以不应该被唤醒。 |
|
|
|
|
|
- UID
- 341189
- 性别
- 男
|
我按照你的说法在freescale的MC9S12XDP512的demo板上试了一下。没有发现异常。即STOP之后PIT就停了。以下是测试程序,供参考:
void SetPIT(void)
{
PITCFLMT&=0x7F; //disable PIT first
PITMUX = 0x00; //use macro timer 0
while (PITTF) PITTF=0x0F; //clear all exist overflow flag
PITMTLD0 = 0;
PITLD0 = 5000;
PITINTE =0x01; //enable the PIT channel 0 interrupt
PITCE = 0x01; //enable the PIT channel 0
PITCFLMT|=0x80; //enable PIT
}
void StopTest(void)
{
__asm {
ANDCC #$7F;
STOP;
};
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void PIT_Channel0()
{
while (PITTF) PITTF=0x0F; //clear all exist overflow flag
printf("* ");
}
在main()中先调用SetPIT(),再调用StopTest(),则中断程序不会执行。如果不调用StopTest(),则中断程序会执行,不断打印出'*'号。
估计问题不在STOP/PIT,可检查一下其它方面。建议先将XGATE disable再试一下。
祝好运! |
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
谢谢楼上的。
我用你的程序试了一下,还是会执行中断。我建project的时候已经把XGATE disable了,用普通方式来处理中断。真是纳闷儿。 |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
int i,a;
void SetupPITimer (void)
{
/* time-out period = (PITMTLD0 + 1) * (PITLD0 + 1) / Fbus */
PITMUX &= ~( 0x01 | 0x02 | 0x04); /* T0,T1 and T2 count with MT0 time base (0.25 us)*/
PITCE |= (0x01 | 0x02 | 0x04); /* enable PIT channel 0,1,2 */
PITCFLMT |= (0x80); /* PITE=1 (enable PIT) */
}
void Enable5msPITimer (void)
{
PITTF |= 0x01; /* clear PIT interrupt */
PITMTLD0 = 0x01; /* MT0 load value (divides bus clock) */
PITLD0 = 9999; /* T0 load value (5 ms) */
PITCFLMT |= 0x01; /* PFLMT0=1 (reload MT0) */
PITFLT |= 0x01; /* force reload of PIT channel 0 */
PITINTE |= 0x01; /* enable PIT channel 0 interrupt */
}
void IoInit (void)
{
DDRM |= 0x40;
PTM_PTM6 = 0;
}
void STOP_Enable (void)
{
asm
{
ANDCC #0x7F;
}
}
void main(void)
{
/* put your own code here */
IoInit();
SetupPITimer();
//Enable5msPITimer();
STOP_Enable();
EnableInterrupts;
for(;;)
{
//for(i=0;i<5000;i++) { }
Enable5msPITimer();
asm STOP;
}
}
/* interrupt handler for PIT 0 */
interrupt void ISR_PIT0 ()
{
//PITINTE &= not_bit0; /* disable this interrupt for channel 0 */
PITTF |= 0x01; /* clear the interrupt flag */
PTM_PTM6 = ! PTM_PTM6;
}
我用M6口做测试。可以看到方波。说明PIT一直在执行。 |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
最好将整个project打包贴出来。有时可能不只是源程序的问题。 |
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
http://bbs.eccn.com/uploadImages/stop test.rar |
|
|
|
|
|
- UID
- 104380
- 性别
- 男
|
文件名和路径名中间不能有空格,否则无法链接。再上传一次吧! |
|
|
|
|
|
- UID
- 145512
- 性别
- 男
|
http://bbs.eccn.com/uploadImages/sleep.rar |
|
|
|
|
|