⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interfacing spi adcs to msp430f449.c

📁 TLV2541, TLC2551,TLC3541,TLC4541与MSP430接口的SPI程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, 
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR 
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE. 
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET 
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY 
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR 
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL, 
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY 
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT 
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM. 
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF 
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS 
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF 
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S 
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF 
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS 
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted 
* by Texas Instruments is distributed as "freeware".  You may, 
* only under TI's copyright in the Program, use and modify the 
* Program without any charge or restriction.  You may 
* distribute to third parties, provided that you transfer a 
* copy of this license to the third party and the third party 
* agrees to these terms by its first use of the Program. You 
* must reproduce the copyright notice and any other legend of 
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains 
* copyrighted material, trade secrets and other TI proprietary 
* information and is protected by copyright laws, 
* international copyright treaties, and trade secret laws, as 
* well as other intellectual property laws.  To protect TI's 
* rights in the Program, you agree not to decompile, reverse 
* engineer, disassemble or otherwise translate any object code 
* versions of the Program to a human-readable form.  You agree 
* that in no event will you alter, remove or destroy any 
* copyright notice included in the Program.  TI reserves all 
* rights not specifically granted under this license. Except 
* as specifically provided herein, nothing in this agreement 
* shall be construed as conferring by implication, estoppel, 
* or otherwise, upon you, any license or other right under any 
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
*************************************************************/

/****************************************************************/
/*                            		                        */
/*    DESCRIPTION: This program uses the MSP430F449 to read  	*/
/*    512 samples from either the TLV2541, TLC2551, TLC3541,    */
/*    or TLC4551  depending on the specific device selected     */
/*    using the #define and the #ifdef statements.              */
/*    TLV2541      12-bit 200KSPS ADC.                          */  
/*    TLC2551      12-bit 400KSPS ADC.                          */  
/*    TLC3541      14-bit 200KSPS ADC.                          */ 
/*    TLC4541      16-bit 200KSPS ADC.                          */   
/*    The samples are stored in the buffer adc_data.            */
/*    Refer to the .map file created by the compiler for the    */  
/*    address in memory for adc_data                            */  
/*    AUTHOR: Data Acquisition Products - Dallas, Texas         */
/*                                                              */
/*    CREATED 2004(C) BY TEXAS INSTRUMENTS INCORPORATED.  	*/
/*    VERSION: 1.0 						*/
/****************************************************************/

#include <msp430x44x.h>
#include <in430.h>

/**************** Function prototypes *****************************************/
/*                                                                            */
void init_sys(void);                /* MSP430 Initialisation routine          */
void init_adc(void);                /* adc initialisation routine             */  
void delay(void);                   /* Software delay                         */
void complete(void);                /* Transmit / Receive ready               */
void convert(void);                 /* Do the conversions                     */
void display(void);                 /* Indicate Program complete - blink LED1 */
void setupClock(int);               /* set up clock for 8 MHZ with or         */
                                    /* without Resonator                      */
/*                                                                            */            
/******************************************************************************/

/************************************************************************/
/*                                                                      */
/* Global variable declarations                                         */
/*                                                                      */
/************************************************************************/

unsigned int    adc_data[512];      // Storage for converted data
int   		element;            // pointer to each mem location

/************************************************************************/
/*                                                                      */
/* main() variable declarations                                         */
/*                                                                      */
/************************************************************************/

#define Resonator (0)        // 0 = No resonator installed on HPA449 board
                             // 1 = Resonator installed on HPA449 board
                             
#define tlv2541 (0)          // Use "1" to select only one device to be 
#define tlc2551 (0)          // used with HPA449 board.  All others                             
#define tlc3541 (1)          // should be "0" 
#define tlc4541 (0)                   
                             

#define     CS          0x80     // CS on P3.7 for HPA449 board 
                                 // FS tied high to Vdd

void main(void)
{ 
init_sys();                   	// Initialize the MSP430

#if tlc3541                     // For required reset cycle
                                // for this device    
 init_adc();                    // Initialize the adc

#endif



#if tlc4541                     // For required reset cycle
                                // for this device    
 init_adc();                    // Initialize the adc

#endif
 

                              
      do {
      convert();              	// Do conversions from each channel
      } while (element < 512); 
      
      
#if tlc3541  
  {                            // For devices with required reset cycle      
   if (adc_data[0] != 0x3FC0)  // Check to see if the device 
     {                         // has been reset properly
        while(1)                              
        {
          P3OUT &= ~BIT5;      // If not, set P3.5 for LED1
        }
     }  
   }     
#endif  
      
#if tlc4541  
  {                            // For devices with required reset cycle      
   if (adc_data[0] != 0xFF00)  // Check to see if the device 
     {                         // has been reset properly
       while(1)                              
       {
         P3OUT &= ~BIT5;       // If not, set P3.5 for LED1
       }
     }  
   }     
#endif
      

display();		       // Flash the LED on the MSP430 when all the samples
			       //  have been taken 	
}			      	

/************************************************************/
/* Prototype - init_sys                                     */
/*                                                          */
/* !NA init_sys                                             */
/* !LA ANSI C                                               */
/* !PI *                                                    */
/* !PO *                                                    */
/* !LV *                                                    */
/*  Description                                             */
/*  This prototype initialises the MSP430F449               */
/************************************************************/

void init_sys(void)
{
void setupports(void);  /* Local function prototype           */
void setupSPI(void);    /* Local function prototype           */    

setupClock (Resonator); /* Set up clock depending on if there */       
                        /* is a Resonator installed or not on */ 
                        /* the HPA449 board                   */ 
setupports(); 
setupSPI(); 
}


/*************************************************************/
/* Prototype - setupClock                                    */
/*                                                           */
/*  Description                                              */
/*  This prototype sets-up the clock (DCO or XT2 oscillator) */
/*  depending if there is a resonator present or not.  If    */
/*  there is no resonator it sets up the DCO. If there is a  */
/*  resonator it tests that XT2 has settled before moving on */                    
/*************************************************************/  
    
void setupClock (int RES)
{
    switch (RES)
    {
        case  0:                         // No resonator installed
                                         // on HPA449 
          { WDTCTL = WDTPW + WDTHOLD;
            /* D=2, N=121, no mod */
            SCFQCTL=121;
            // SCFI0 = 0100 0100
            SCFI0=0x44;
            // DCOPLUS=1, XTS_FLL=0
            // XCAPXPF=00
            FLL_CTL0=0x80;
            // SMCLK=0, XT2OFF=1, SELMX=00, SELS=0, FLL_DIVX=10
            // FLL_CTL1= 0010 0010
            FLL_CTL1=0x22;
          }
          break;        
        case  1:                         // Resonator installed 
                                         // on HPA449
          { 
            WDTCTL = WDTPW + WDTHOLD;    // Stop watchdog timer  
            FLL_CTL0&=XT2OFF;            // Switch on the XT2 osc.
            FLL_CTL1|=SELM_XT2+SELS;     // Select XT2 osc. for 
                                         // SMCLK and MCLK
                                         // test the oscillator flag bit
            do {
                IFG1 &= ~OFIFG;          // Clear the OFIFG bit
                } while (OFIFG&IFG1);    
          }

          break;
    }    
} 


/************************************************************/
/* Prototype - setupports                                   */
/*                                                          */
/* !NA setupports                                           */
/* !LA ANSI C                                               */
/* !PI *                                                    */
/* !PO *                                                    */
/* !LV *                                                    */
/*  Description                                             */
/*  This prototype sets-up the GPIO ports as appropriate    */
/************************************************************/ 
     
void setupports (void)
{    

P3DIR |= BIT5;                      // P3.5 set as output for LED1
P3OUT |= BIT5;                      // Set P3.5 HIGH to turn off LED1
P3SEL = BIT3 + BIT2 + BIT1;         // Bits 3, 2 & 1 are assigned as SPI specific pins

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -