This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430G2230:ADC 读取问题/引脚设置问题

Guru**** 2380860 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1272849/msp430g2230-adc-reading-issue-pin-setting-issue

器件型号:MSP430G2230

您好!

我正在使用引脚3 /P1.5作为 ADC 输入。 我不知道如何 将引脚配置为 ADC 输入、因为 P1SEL1和 P1SEL0被标记为错误/无法识别、仅允许 P1SEL。 但是、设置 P1SEL |= BIT5;选择第二功能(我想吗?) 而不是 ADC 的第三功能。 如何设置这些引脚、您是否有针对2230的简单读取 ADC 示例?

谢谢

理查德

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您能向我们展示一个小型测试案例吗?

    是否确定键入了"P1SEL-Zero"而不是"P1SEL-OH"?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    对于该器件、您不使用选择寄存器、而是使用 ADC 寄存器:

    查看 Resource Explorer 中的数据表和示例:

    //******************************************************************************
    //  MSP430G2230 Demo - ADC10, Sample A5, AVcc Ref, Set P1.2 if > 0.5*AVcc
    //
    //  Description: A single sample is made on A5 with reference to AVcc.
    //  Software sets ADC10SC to start sample and conversion - ADC10SC
    //  automatically cleared at EOC. ADC10 internal oscillator times sample (16x)
    //  and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC10
    //  conversion complete, ADC10_ISR will force exit from LPM0 in Mainloop on
    //  reti. If A5 > 0.5*AVcc, P1.5 set, else reset.
    //
    //                MSP430G2230
    //             -----------------
    //         /|\|              XIN|-
    //          | |                 |
    //          --|RST          XOUT|-
    //            |                 |
    //        >---|P1.5/A5      P1.2|-->LED
    //
    //  B. Nisarga
    //  Texas Instruments, Inc
    //  December 2011
    //  Built with CCE Version: 5.1 and IAR Embedded Workbench Version: 5.4
    //******************************************************************************
    
    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                 // Stop WDT
      
      /* Initialization Code */
      P1REN = 0x1B;                             // Terminate unavailable Port1 pins (P1.0/1/3/4) properly
                                                // Config as Input with pull-down enabled
      BCSCTL3 |= LFXT1S_2;                      // Select VLO as low freq clock     
      /* End Initialization Code */ 
      
      ADC10CTL0 = ADC10SHT_2 | ADC10ON | ADC10IE; // ADC10ON, interrupt enabled
      ADC10CTL1 = INCH_5;                       // input A5
      ADC10AE0 |= BIT5;                         // PA.5 ADC option select
      P1DIR |= BIT2;                            // Set P1.2 to output direction
    
      for (;;)
      {
        ADC10CTL0 |= ENC | ADC10SC;             // Sampling and conversion start
        __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit
        if (ADC10MEM < 0x1FF)
          P1OUT &= ~BIT2;                       // Clear P1.2 LED off
        else
          P1OUT |= BIT2;                        // Set P1.2 LED on
      }
    }
    
    // ADC10 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
    }