[资料分享] DAC8571驱动程序--MSP430G2xx3

[复制链接]
787|2
 楼主| xyz549040622 发表于 2019-12-21 11:05 | 显示全部楼层 |阅读模式
本帖最后由 xyz549040622 于 2019-12-21 23:20 编辑
  1. //  MSP430G2xx3 Demo - USCI_B0 I2C Master Interface to DAC8571, Write
  2. //
  3. //  Description: Using UCB0TXIE, a continuous sine wave is output to the
  4. //  external DAC using a 16-point look-up table. Only one start condition
  5. //  is executed. Data is handled by the ISR and the CPU is normally in LPM0.
  6. //  ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1.2MHz
  7. //
  8. //               MSP430G2xx3                       DAC8571
  9. //           ------------------                   ------------
  10. //         -|XIN   P1.7/UCB0SDA|<--------------->|SDA         |
  11. //          |      P1.6/UCB0SCL|---------------->|SCL  I2C    |
  12. //         -|XOUT              |                 |    SLAVE   |
  13. //          |     I2C MASTER   |              GND|A0          |
  14. //
  15. //
  16. //  DAC8571 I2C address = 0x4C (A0 = GND)
  17. //
  18. //  D. Dang
  19. //  Texas Instruments Inc.
  20. //  February 2011
  21. //   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
  22. //******************************************************************************
  23. #include <msp430.h>

  24. const unsigned char Sine_Tab[] =            // 16 Point 16-bit Sine Table
  25. {
  26. 0xFF,                                     // MSB Word 0
  27. 0xFF,                                     // LSB
  28. 0xF6,                                     // MSB Word 1
  29. 0x40,                                     // LSB
  30. 0xDA,                                     // MSB Word 2
  31. 0x81,                                     // LSB
  32. 0xB0,                                     // MSB Word 3
  33. 0xFA,                                     // LSB
  34. 0x7F,                                     // MSB Word 4
  35. 0xFF,                                     // LSB
  36. 0x4F,                                     // MSB Word 5
  37. 0x03,                                     // LSB
  38. 0x25,                                     // MSB Word 6
  39. 0x7C,                                     // LSB
  40. 0x09,                                     // MSB Word 7
  41. 0xBD,                                     // LSB
  42. 0x00,                                     // MSB Word 8
  43. 0x00,                                     // LSB
  44. 0x09,                                     // MSB Word 9
  45. 0xBD,                                     // LSB
  46. 0x25,                                     // MSB Word 10
  47. 0x7C,                                     // LSB
  48. 0x4F,                                     // MSB Word 11
  49. 0x03,                                     // LSB
  50. 0x7F,                                     // MSB Word 12
  51. 0xFE,                                     // LSB
  52. 0xB0,                                     // MSB Word 13
  53. 0xFA,                                     // LSB
  54. 0xDA,                                     // MSB Word 14
  55. 0x81,                                     // LSB
  56. 0xF6,                                     // MSB Word 15
  57. 0x40                                      // LSB
  58. };

  59. int main(void)
  60. {
  61. WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
  62. P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  63. P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  64. UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  65. UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  66. UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  67. UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
  68. UCB0BR1 = 0;
  69. UCB0I2CSA = 0x4c;                         // Set slave address
  70. UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  71. IE2 |= UCB0TXIE;                          // Enable TX ready interrupt
  72. UCB0CTL1 |= UCTR + UCTXSTT;               // I2C TX, start condition
  73. UCB0TXBUF = 0x010;                        // Write DAC control byte
  74. __bis_SR_register(CPUOFF + GIE);          // Enter LPM0 w/ interrupts
  75. }

  76. // USCI_B0 Data ISR
  77. #pragma vector = USCIAB0TX_VECTOR
  78. __interrupt void USCIAB0TX_ISR(void)
  79. {
  80. static unsigned char ByteCtr;

  81. UCB0TXBUF = Sine_Tab[ByteCtr++];          // Transmit data byte
  82. ByteCtr &= 0x1f;                          // Do not exceed table
  83. }


externally 发表于 2019-12-23 19:40 | 显示全部楼层
感谢楼主分享!学习一下
dspmana 发表于 2020-1-9 22:32 | 显示全部楼层
               
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:qq群: 嵌入式系统arm初学者 224636155←← +→→点击-->小 i 精品课全集,21ic公开课~~←←→→点击-->小 i 精品课全集,给你全方位的技能策划~~←←

2841

主题

19330

帖子

110

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