ADS1220/MSP430x552x Demo

[复制链接]
1823|2
 楼主| dirtwillfly 发表于 2017-8-23 20:58 | 显示全部楼层 |阅读模式
main.c
  1. //******************************************************************************
  2. // ADS1220/MSP430x552x Demo - ADS1220 to MSP430 communication via SPI  
  3. //                    
  4. //
  5. // Description: Use of the MSP430 USCI A0 peripheral for setting up and
  6. //    communicating to the ADS1220 24-bit ADC.
  7. //   
  8. //   
  9. //                                                   
  10. //                 MSP430x552x
  11. //             ------------------                        
  12. //         /|\|                  |                       
  13. //          | |                  |                       
  14. //          --|RST           P3.4|<-- MISO (DOUT)           
  15. //            |                  |                                         
  16. //            |              P3.3|--> MOSI (DIN)
  17. //            |                  |  
  18. //            |              P2.7|--> SCLK
  19. //            |                  |
  20. //            |              P2.6|<-- INT (DRDY)
  21. //            |                  |
  22. //            |              P1.2|--> CS
  23. //
  24. //   R. Benjamin
  25. //   Texas Instruments Inc.
  26. //   May 2013
  27. //   
  28. //******************************************************************************
  29. //+-----------------------------------------------------------------------------+
  30. //|  Source: main.c, v1.0 2013/05/28                                           |
  31. //------------------------------------------------------------------------------+   

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

  34. // Function declarations
  35. void Init_StartUp(void);
  36. void SPIinit(void);

  37. // Global variable
  38. int dFlag = 0;

  39. /*----------------------------------------------------------------------------+
  40. | Main Routine                                                                |
  41. +----------------------------------------------------------------------------*/
  42. VOID main(VOID)
  43. {
  44.     signed long tData;
  45.        
  46.         WDTCTL = WDTPW + WDTHOLD;            // Stop watchdog timer
  47.        
  48.     Init_StartUp();                 // Initialize device
  49.         ADS1220Init();                                        // Initializes the SPI port pins as well as control
  50.     ADS1220Config();                                // Set base configuration for ADS1x20 device

  51.     while(1)
  52.     {
  53.         /* Add specifc command for reading and writing ADS1220 here */
  54.                 // dFlag is set in the interrupt service routine when DRDY triggers end
  55.                 //        of conversion
  56.                 if (dflag)                                                // if new data is available
  57.                 {
  58.                         tData = ADS1220ReadData();        // get the data from the ADS1220
  59.                         dFlag=0;
  60.                 }
  61.                
  62.                 // other routines could be added here, such as change the mux setting
  63.                
  64.     }  // while(1)
  65. } //main()

  66. /*----------------------------------------------------------------------------+
  67. | System Initialization Routines                                              |
  68. +----------------------------------------------------------------------------*/

  69. // Initializes the clocks.  Starts the DCO at USB_MCLK_FREQ (the CPU freq set with the Desc
  70. // Tool), using the REFO as the FLL reference.  Configures the high-freq crystal, but
  71. // doesn't start it yet.  Takes some special actions for F563x/663x.  
  72. VOID Init_Clock(VOID)
  73. {
  74.    
  75.     if (USB_PLL_XT == 2)
  76.     {
  77.         // Enable XT2 pins
  78.         P5SEL |= 0x0C;                     
  79.         P5DIR |= BIT4+BIT5;
  80.         UCSCTL1 = DCORSEL_6;
  81.         UCSCTL2 = FLLD_1+1;
  82.         UCSCTL3 = SELREF__XT2CLK;
  83.         UCSCTL6 = XT2DRIVE1;
  84.         
  85.         
  86.         // Start the FLL, which will drive MCLK (not the crystal)
  87.         //Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768);  
  88.         //Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/12000000);
  89.                 UCSCTL4  = SELA_4 + SELS_4 + SELM_4;      // ACLK=TX2  SMCLK=TX2   MCLK=TX2
  90.                 P2SEL |= BIT2;
  91.                 P2DIR |= BIT2;
  92.                 __bis_SR_register(GIE+OSCOFF);
  93.                
  94.     }
  95.     else
  96.     {
  97.         // Enable XT1 pins
  98.         P5SEL |= 0x10;                    
  99.             
  100.         // Use the REFO oscillator as the FLL reference, and also for ACLK
  101.         UCSCTL3 = SELREF__REFOCLK;            
  102.         UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);
  103.         
  104.         // Start the FLL, which will drive MCLK (not the crystal)
  105.         Init_FLL(USB_MCLK_FREQ/1000, USB_MCLK_FREQ/32768); // set FLL (DCOCLK)
  106.     }
  107. }

  108. //----------------------------------------------------------------------------

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

  112.         // set all ports  to low on all pins
  113.         P1OUT         =         0x04;
  114.         P1DIR         =        0xFF;
  115.         P2OUT        =         0x00;
  116.         P2DIR        |=        0x3F;
  117.         P3OUT        =         0x00;
  118.         P3DIR        |=        0x07;
  119.         P4OUT        =        0x00;
  120.         P4DIR        |=        0xFF;
  121.         P5OUT        =        0x00;
  122.         P5DIR        |=        0x33;
  123.         P6OUT        =        0x00;
  124.         P6DIR        =        0xFF;
  125.    
  126. }

  127. //----------------------------------------------------------------------------

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


  137. //----------------------------------------------------------------------------

  138. VOID Init_StartUp(VOID)
  139. {
  140.     __disable_interrupt();               // Disable global interrupts
  141.    
  142.     Init_Ports();                        // Init ports (do first ports because clocks do change ports)
  143.     SetVCore(3);                         // USB core requires the VCore set to 1.8 volt, independ of CPU clock frequency
  144.     Init_Clock();
  145.     SPIinit();
  146.    
  147.    
  148.    

  149.     __enable_interrupt();                // enable global interrupts
  150.    
  151.    
  152. }


  153. #pragma vector = UNMI_VECTOR
  154. __interrupt VOID UNMI_ISR(VOID)
  155. {
  156.     switch (__even_in_range(SYSUNIV, SYSUNIV_BUSIFG))
  157.     {
  158.     case SYSUNIV_NONE:
  159.       __no_operation();
  160.       break;
  161.     case SYSUNIV_NMIIFG:
  162.       __no_operation();
  163.       break;
  164.     case SYSUNIV_OFIFG:
  165.       UCSCTL7 &= ~(DCOFFG+0+0+0); // Clear OSC flaut Flags fault flags
  166.       SFRIFG1 &= ~OFIFG;                                // Clear OFIFG fault flag
  167.       break;
  168.     case SYSUNIV_ACCVIFG:
  169.       __no_operation();
  170.       break;
  171.     case SYSUNIV_BUSIFG:

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




  177. #pragma vector = PORT2_VECTOR
  178. __interrupt void Port_2(void)
  179. {
  180.                
  181.         switch(__even_in_range(P2IV,16))
  182.         {
  183.                 case 0: break;
  184.                 case 14:
  185.                                 dFlag=1;
  186.                                 break;
  187.                 default:break;       
  188.         }       
  189. }



  190. }
  191. /*----------------------------------------------------------------------------+
  192. | End of source file                                                          |
  193. +----------------------------------------------------------------------------*/
  194. /*------------------------ Nothing Below This Line --------------------------*/


 楼主| dirtwillfly 发表于 2017-8-23 20:59 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
tongbu2015 发表于 2017-8-26 13:31 | 显示全部楼层
这个时钟的初始化还是需谨慎的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

1199

主题

35121

帖子

1122

粉丝
快速回复 在线客服 返回列表 返回顶部