Guest
Public paste!

Untitled

By: a guest | Mar 21st, 2010 | Syntax: C | Size: 2.76 KB | Hits: 103 | Expires: Never
Copy text to clipboard
  1. //******************************************************************************
  2. //  MSP430F22x4 Demo - USCI_B0 I2C Master Interface to DAC8571, Write
  3. //
  4. //  Description: Using UCB0TXIE, a continuous sine wave is output to the
  5. //  external DAC using a 16-point look-up table. Only one start condition
  6. //  is executed. Data is handled by the ISR and the CPU is normally in LPM0.
  7. //  ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1.2MHz
  8. //
  9.  
  10. //               MSP430F22x4                 AD5622
  11. //           --------------               -----------
  12. //          |P3.1/UCB0SDA | P18 <---->  3 | SDA     |
  13. //          |P3.2/UCB0SCL | P15 ----->  2 | SCL     |
  14. //          |        GND  | P1        5/1 | GND     |
  15. //          |         VCC | P2          4 | VDD     |
  16. //          --------------                -----------
  17. //
  18. //
  19. //  AD5622 I2C address = 0x0F (A0 = GND)
  20. //
  21. //  Andreas Dannenberg
  22. //  Texas Instruments Inc.
  23. //  March 2006
  24. //  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A
  25. //******************************************************************************
  26. #include "msp430x22x4.h"
  27. static unsigned char ByteCtr=0;
  28. const unsigned char Sine_Tab[] =            // 16 Point 16-bit Sine Table
  29. {
  30.   0x0F,                                     // MSB Word 0
  31.   0xFF,                                     // LSB
  32.   0x00,                                     // MSB Word 1
  33.   0x00,                                     // LSB
  34. };
  35. void main(void)
  36. {
  37.   WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
  38.   P1DIR |= 0x03;
  39.   P1OUT = 0x02;
  40.   P3SEL |= 0x06;                            // Sets P3.1 to UCB0SDA, 3.2 to UCB0SCL
  41.   UCB0CTL1 |= UCSWRST;                      // Keep USCI in reset pg547
  42.   UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode. pg546
  43.   UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Selects the SMCLK and keeps USCI in reset pg547
  44.   UCB0BR0 = 12;                             // Sets data clock to ~100KHz pg541. SMCLK/11 pg289   //low bit
  45.   UCB0BR1 = 0;                              // Sets data clock to ~100KHz pg541. SMCLK/12 pg289   //high bit
  46.   UCB0I2CSA = 0x0F;                         // Set slave address
  47.   UCB0CTL1 &= ~UCSWRST;                     // Bring USCI out of reset
  48.   IE2 |= UCB0TXIE;                          // Interrupt enabled. pg516
  49.   UCB0CTL1 |= UCTR + UCTXSTT;               // Sets transmit and sends START condition pg547
  50.   while(1){
  51.   __bis_SR_register(CPUOFF + GIE);          // Enter LPM0 w/ interrupts
  52.   }
  53. }
  54.  
  55. // USCI_B0 Data ISR
  56. #pragma vector = USCIAB0TX_VECTOR
  57. __interrupt void USCIAB0TX_ISR(void)
  58. {
  59.   P1OUT |= 0x01;
  60.   UCB0TXBUF = Sine_Tab[ByteCtr++];          // Transmit data byte
  61.   ByteCtr &= 0x01;                          // Do not exceed table
  62.   P1OUT ^= 0x01;
  63. }