确定快速代码片段。 我预计 ADC12在进入计时器 B0中断时会很忙-但事实并非如此;所以我猜是我漏掉了启用的东西。 那有什么明显的东西吗? 本周末我将仔细阅读相关文档。
int main(void) { // Stop WDT HWREGW( WDT_A_BASE | WDTCTL ) = WDTPW|WDTHOLD; // stop interupts whilst we configure __disable_interrupt(); // first disable ADC12 HWREGW( ADC12_A_BASE | ADC12CTL0 )&= ~ADC12ENC; HWREGW( ADC12_A_BASE | ADC12CTL0 )&= ~ADC12ON; // 4 ticks sample and hold. // 0x80 = 1 - sample on SHi signal // 0x40 - 2.5V ADC12_A ref gen volt // 0x20 - Ref on // 0x10 =0 - ADC12_A is off // 0x08 =0 - overflow int disable // 0x04 =0 - conversion time int disable // 0x02 - enable conversion ???? // 0x01 - Start conversiom HWREGW( ADC12_A_BASE | ADC12CTL0 ) = ADC12SHT0_0 | ADC12MSC | ADC12REF2_5V | ADC12REFON ; // ADC12CSTARTADDx = 0 (write starting at ADC12MEM0) // ADC12SHP =0 // ADC12SHSx = 2 - Timer B0 // ADC12ISSH = 0 Not inverted // ADC12DIVx = 0 (divide by 1) // ADC12SSELx = 3 (SMCLK) HWREGW( ADC12_A_BASE | ADC12CTL1 ) = ADC12SHS_2 | ADC12SSEL_3 ; // ADC12PDIV =0 (predivide 1) // ADC12TCOFF =0 (oddly means temp sensor on) // ADC12RES=2 (12bit) // ADC12DF=0 (unsigned) // ADC12SR=0 (200ksps sample rate) // ADC12REFOUT=1 = Ref Output on // ADC12REFBURST=1 only on during sample and convert HWREGW( ADC12_A_BASE | ADC12CTL2 ) = ADC12RES_2 | ADC12REFOUT | ADC12REFBURST; // ADC12SREF2 = 1 Vref- user the external reference // ADC12SFREG01 = 11 or 10 - user Vref+ HWREGB( ADC12_A_BASE | ADC12MCTL0 ) = ADC12SREF_7 | ADC12INCH_0; HWREGB( ADC12_A_BASE | ADC12MCTL1 ) = ADC12SREF_7 | ADC12INCH_10; HWREGB( ADC12_A_BASE | ADC12MCTL2 ) = ADC12EOS; // enable ADC12 HWREGW( ADC12_A_BASE | ADC12CTL0 )|= ADC12ON; HWREGW( ADC12_A_BASE | ADC12CTL0 )|= ADC12ENC; __enable_interrupt(); // now all set for now just loop, with LED flashing while(1) { } } // TIMER B CC __attribute__ ((interrupt(TIMER0_B0_VECTOR))) void TIMER0_B0_ISR (void) { sprintf(print,"%i\0", HWREGW( ADC12_A_BASE | ADC12CTL1 )&ADC12BUSY); }
打印缓冲器由 USCI_A1中断进行处理并发送到 UART。
在 UART 上我只得到"0"输出、这是因为它是 Timer B 断流器例程中的第一条指令、也就是用来触发 ADC12的指令似乎是错误的。
有人有什么想法吗? 我会继续挖掘。