经过一上午的实验,终于把按键中断部分给调通了。
几个要点如下:
1 如果不配置时钟,默认情况会是MCLK = SMCLK = 1MHz。
2 阻塞延时可以照如下方法给出
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
3 GPIO的配置要遵循以下顺序
a. Initialize Ports: PxDIR, PxREN, PxOUT, and PxIES
b.
Clear LOCKLPM5
c. If not wake-up from LPMx.5: clear all PxIFGs to avoid erroneous port interrupts
d. Enable port interrupts in PxIE
4 对于MSP430FR系列单片机,不用的引脚要配置为输出模式并悬空!
5 执行
__bis_SR_register(LPMx + GIE);//LMP0 LMP1...
这条语句后MCLK已经关闭,不会再往下执行代码。
6 中断响应函数写法如下:
//中断函数
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT1_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(PORT1_VECTOR)))
#endif
void Port1_ISR(void)
{
GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);//清中断标志位
GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);//LED1切换
}
7 实验结果
LED1 做1000ms周期亮灭,LED2由S2触发。结果如下所示:
8 实验代码
9 尚未解决的问题
三个警告如下:
warning #10420-D: For FRAM devices, at start up, the GPO power-on default high-impedance mode needs to be disabled to activate previously configured port settings. This can be done by clearing the LOCKLPM5 bit in PM5CTL0 register.
remark #10372-D: (ULP 4.1) Detected uninitialized Port A in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port B in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
很奇怪,Port A 和 Port B我这板子上根本没看到啊,怎么初始化呀?
PM5CTL0 &= ~LOCKLPM5; 语句替换 PMM_unlockLPM5();之后#10420-D 警告不再显示。奇怪了,难道这两条语句不一样的作用吗?
因为没找到相应的网络资源,还请各位不吝指教。谢谢~