MSP430F4250选用A2通道如何配置的问题

2019-07-22 14:22发布

我选用的MSP430F4250的ADC模块是SD16_A型的,其A2通道被分配到了P1.6,P1.7端口,若我想使用A2通道应该怎么配置呢?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
14条回答
dirtwillfly
1楼-- · 2019-07-22 19:15
和其他通道基本上是一样的。你可以参考官方的例程和MSP430x4xx Family User's Guide里相关内容
dirtwillfly
2楼-- · 2019-07-23 00:21
这是一个用通道5的
/* --COPYRIGHT--,BSD_EX
* Copyright (c) 2012, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* *  Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
* *  Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the distribution.
*
* *  Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************
*
*                       MSP430 CODE EXAMPLE DISCLAIMER
*
* MSP430 code examples are self-contained low-level programs that typically
* demonstrate a single peripheral function or device feature in a highly
* concise manner. For this the code may rely on the device's power-on default
* register values and settings such as the clock configuration and care must
* be taken when combining code from several examples to avoid potential side
* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
* for an API functional library-approach to peripheral configuration.
*
* --/COPYRIGHT--*/
//*****************************************************************************
//   MSP430x42x0 Demo - SD16_A, Using the Integrated Battery Sensor
//
//  Description: This example shows how to use the SD16_A module's integrated
//  Battery sensor (connected to input channel 5) to measure VCC.
//  A single conversion is initiated and then the CPU is disabled by entering
//  LPM0. Once the conversion has completed, a SD16_A interrupt occurs and
//  stores the result in variable "ADCresult".  LED lights if batter is low
//  ACLK = LFXT1 = 32768 Hz, MCLK = SMCLK = DCO = 32 x ACLK = 1048576 Hz
//  //* An external watch crystal on XIN XOUT is required for ACLK     *//       
//  //* Minimum Vcc is required for SD16_A module - see datasheet        *//
//  //* 100nF cap btw Vref and AVss is recommended when using 1.2V ref *//
//
//                MSP430F4270
//             -----------------
//         /||              XIN|-
//          | |                 | 32kHz
//          --|RST          XOUT|-
//            |                 |
//            |A5+              | ( A5+, A5- connected internally )
//            |A5-              |
//            |                 |
//            |            VREF |---+
//            |                 |   |
//            |                 |  -+- 100nF
//            |                 |  -+-
//            |                 |   |
//            |            AVss |---+
//            |                 |
//
//  L. Westlund / S. Karthikeyan
//  Texas Instruments Inc.
//  June 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.30A
//*****************************************************************************
#include <msp430.h>

#define LOW_BAT 0xBFFF                      // ~3V

static unsigned int ADCresult;

int main(void)
{
  volatile unsigned int i;                  // Use volatile to prevent removal
                                            // by compiler optimization
  P1DIR |= 0x01;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  FLL_CTL0 |= XCAP14PF;                     // Configure load caps
  for (i = 0; i < 10000; i++);              // Delay for 32 kHz crystal to
                                            // stabilize

  SD16CTL = SD16REFON+SD16SSEL0;            // 1.2V ref, SMCLK
  SD16CCTL0 |= SD16SNGL+SD16IE ;            // Single conv, enable interrupt
  SD16INCTL0 |= SD16INCH_5;                 // Select Channel A5
  for (i = 0; i < 0x3600; i++);             // Delay for 1.2V ref startup

  __enable_interrupt();                     // Enable general interrupts

  while (1)
  {
    SD16CCTL0 |= SD16SC;                    // Set bit to start conversion
    __bis_SR_register(LPM0_bits);           // Enter LPM0
   if( ADCresult < LOW_BAT )
   {
    P1OUT |= 0x01;
   }
   else
   {
     P1OUT &= ~0x01;
   }
    __no_operation();                       //SET BREAKPOINT HERE
  }
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD16_VECTOR))) SD16ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch (SD16IV)
  {
  case 2:                                   // SD16MEM Overflow
    break;
  case 4:                                   // SD16MEM0 IFG
    ADCresult = SD16MEM0;                   // Save results (clears IFG)
    break;
  }

  __bic_SR_register_on_exit(LPM0_bits);     // Exit LPM0
}
尤彼卡
3楼-- · 2019-07-23 01:34
 精彩回答 2  元偷偷看……
vivilzb1985
4楼-- · 2019-07-23 03:03
dirtwillfly 发表于 2016-5-26 20:59
这是一个用通道5的
/* --COPYRIGHT--,BSD_EX
* Copyright (c) 2012, Texas Instruments Incorporated

这个例程很好了的,参考下的,顺便的看下你的硬件端口设置的
51xlf
5楼-- · 2019-07-23 07:59
这个在例程 里面没有吗
51xlf
6楼-- · 2019-07-23 11:57
里面的参考端口都是设置好的。

一周热门 更多>