打印

ADS1220/MSP430x552x Demo

[复制链接]
1124|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dirtwillfly|  楼主 | 2017-8-23 20:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
main.c
//******************************************************************************
// ADS1220/MSP430x552x Demo - ADS1220 to MSP430 communication via SPI  
//                    
//
// Description: Use of the MSP430 USCI A0 peripheral for setting up and
//    communicating to the ADS1220 24-bit ADC.
//   
//   
//                                                   
//                 MSP430x552x
//             ------------------                        
//         /|\|                  |                       
//          | |                  |                       
//          --|RST           P3.4|<-- MISO (DOUT)           
//            |                  |                                         
//            |              P3.3|--> MOSI (DIN)
//            |                  |  
//            |              P2.7|--> SCLK
//            |                  |
//            |              P2.6|<-- INT (DRDY)
//            |                  |
//            |              P1.2|--> CS
//
//   R. Benjamin
//   Texas Instruments Inc.
//   May 2013
//   
//******************************************************************************
//+-----------------------------------------------------------------------------+
//|  Source: main.c, v1.0 2013/05/28                                           |
//------------------------------------------------------------------------------+   

#include <msp430f5528.h>
#include "ADS1220.h"

// Function declarations
void Init_StartUp(void);
void SPIinit(void);

// Global variable
int dFlag = 0;

/*----------------------------------------------------------------------------+
| Main Routine                                                                |
+----------------------------------------------------------------------------*/
VOID main(VOID)
{
    signed long tData;
       
        WDTCTL = WDTPW + WDTHOLD;            // Stop watchdog timer
       
    Init_StartUp();                 // Initialize device
        ADS1220Init();                                        // Initializes the SPI port pins as well as control
    ADS1220Config();                                // Set base configuration for ADS1x20 device

    while(1)
    {
        /* Add specifc command for reading and writing ADS1220 here */
                // dFlag is set in the interrupt service routine when DRDY triggers end
                //        of conversion
                if (dflag)                                                // if new data is available
                {
                        tData = ADS1220ReadData();        // get the data from the ADS1220
                        dFlag=0;
                }
               
                // other routines could be added here, such as change the mux setting
               
    }  // while(1)
} //main()

/*----------------------------------------------------------------------------+
| System Initialization Routines                                              |
+----------------------------------------------------------------------------*/

// Initializes the clocks.  Starts the DCO at USB_MCLK_FREQ (the CPU freq set with the Desc
// Tool), using the REFO as the FLL reference.  Configures the high-freq crystal, but
// doesn't start it yet.  Takes some special actions for F563x/663x.  
VOID Init_Clock(VOID)
{
   
    if (USB_PLL_XT == 2)
    {
        // Enable XT2 pins
        P5SEL |= 0x0C;                     
        P5DIR |= BIT4+BIT5;
        UCSCTL1 = DCORSEL_6;
        UCSCTL2 = FLLD_1+1;
        UCSCTL3 = SELREF__XT2CLK;
        UCSCTL6 = XT2DRIVE1;
        
        
        // Start the FLL, which will drive MCLK (not the crystal)
        //Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768);  
        //Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/12000000);
                UCSCTL4  = SELA_4 + SELS_4 + SELM_4;      // ACLK=TX2  SMCLK=TX2   MCLK=TX2
                P2SEL |= BIT2;
                P2DIR |= BIT2;
                __bis_SR_register(GIE+OSCOFF);
               
    }
    else
    {
        // Enable XT1 pins
        P5SEL |= 0x10;                    
            
        // Use the REFO oscillator as the FLL reference, and also for ACLK
        UCSCTL3 = SELREF__REFOCLK;            
        UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);
        
        // Start the FLL, which will drive MCLK (not the crystal)
        Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768); // set FLL (DCOCLK)
    }
}

//----------------------------------------------------------------------------

VOID Init_Ports(VOID)
{
        // Initialization of ports all unused pins as outputs with low-level

        // set all ports  to low on all pins
        P1OUT         =         0x04;
        P1DIR         =        0xFF;
        P2OUT        =         0x00;
        P2DIR        |=        0x3F;
        P3OUT        =         0x00;
        P3DIR        |=        0x07;
        P4OUT        =        0x00;
        P4DIR        |=        0xFF;
        P5OUT        =        0x00;
        P5DIR        |=        0x33;
        P6OUT        =        0x00;
        P6DIR        =        0xFF;
   
}

//----------------------------------------------------------------------------

// Sets the USCI SPI peripheral to use A0
void SPIinit(void)
{
        UCA0CTL1 |= UCSWRST;                                                // Hold peripheral in reset
        UCA0CTL0 = UCMST + UCSYNC + UCMSB;                        // SPI master, synchronous
        UCA0CTL1 = UCSSEL_2 + UCSWRST;                                // Use SMCLK for bit rate clock and keep in reset
        UCA0BR0 = 12;                                                                // SMCLK/12 = SCLK (2MHz)
        UCA0CTL1 &= ~UCSWRST;                                                 // Release peripheral for use
}


//----------------------------------------------------------------------------

VOID Init_StartUp(VOID)
{
    __disable_interrupt();               // Disable global interrupts
   
    Init_Ports();                        // Init ports (do first ports because clocks do change ports)
    SetVCore(3);                         // USB core requires the VCore set to 1.8 volt, independ of CPU clock frequency
    Init_Clock();
    SPIinit();
   
   
   

    __enable_interrupt();                // enable global interrupts
   
   
}


#pragma vector = UNMI_VECTOR
__interrupt VOID UNMI_ISR(VOID)
{
    switch (__even_in_range(SYSUNIV, SYSUNIV_BUSIFG))
    {
    case SYSUNIV_NONE:
      __no_operation();
      break;
    case SYSUNIV_NMIIFG:
      __no_operation();
      break;
    case SYSUNIV_OFIFG:
      UCSCTL7 &= ~(DCOFFG+0+0+0); // Clear OSC flaut Flags fault flags
      SFRIFG1 &= ~OFIFG;                                // Clear OFIFG fault flag
      break;
    case SYSUNIV_ACCVIFG:
      __no_operation();
      break;
    case SYSUNIV_BUSIFG:

      // If bus error occured - the cleaning of flag and re-initializing of USB is required.
      SYSBERRIV = 0;            // clear bus error flag
      
    }
}




#pragma vector = PORT2_VECTOR
__interrupt void Port_2(void)
{
               
        switch(__even_in_range(P2IV,16))
        {
                case 0: break;
                case 14:
                                dFlag=1;
                                break;
                default:break;       
        }       
}



}
/*----------------------------------------------------------------------------+
| End of source file                                                          |
+----------------------------------------------------------------------------*/
/*------------------------ Nothing Below This Line --------------------------*/


相关帖子

沙发
dirtwillfly|  楼主 | 2017-8-23 20:59 | 只看该作者
ADS1220源码.zip (9.07 KB)

使用特权

评论回复
板凳
tongbu2015| | 2017-8-26 13:31 | 只看该作者
这个时钟的初始化还是需谨慎的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:欢迎进入TI MCU论坛      21ic TI技术交流1群:61549143(已满),  21ic TI技术交流2群:311421422 我的博客:http://blog.timcu.com/

1180

主题

34753

帖子

1116

粉丝