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

📄 fet140_i2c_mstr_multiplebytes.c

📁 msp430f14x 系列片内外设的实例代码
💻 C
字号:
//************************************************************************************
//   MSP-FET430P140 Demo - MSP430 Master writes multiple bytes to MSP430 Slave via I2C.
//
//   Description: This demo connects two MSP430's via the I2C bus. The master 
//   writes 3 bytes to the slave. This is the master code. The slave code is called
//   fet140_i2c_slav_RX.c. The TX data is incremented each time it is sent.
// 
//   
//                                 /|\  /|\
//                  MSP430F169     10k  10k     MSP430F169           
//              -----------------|  |    |  ----------------- 
//             |             P3.1|<-|---+->|P3.1             |
//             |                 |  |      |                 |
//             |                 |  |      |                 |
//             |             P3.3|<-+----->|P3.3             |
//             |                 |         |                 |
//
//
//  H.Grewal
//  Texas Instruments, Inc
//  September 2004
//************************************************************************************

#include  "msp430x16x.h"
void delay (void);
char TXData = 0;

void main (void)
{
  WDTCTL = WDTPW+WDTHOLD;               // Stop WDT
  P3SEL |= 0x0A;                        // Select I2C pins
  U0CTL |= I2C+SYNC;                    // Recommended init procedure
  U0CTL &= ~I2CEN;                      // Recommended init procedure
  I2CTCTL |= I2CSSEL1+I2CTRX;           // SMCLK, transmit
  I2CNDAT = 0x03;                       // Write Three bytes
  I2CSA = 0x0048;                       // Slave Address is 048h
  U0CTL |= I2CEN;                       // Enable I2C

  U0CTL |= MST;                         // Master mode
  I2CTCTL |= I2CSTT+I2CSTP;             // Initiate transfer
  while ((I2CIFG & TXRDYIFG) == 0);     // Wait for transmitter to be ready
  I2CDRB = TXData;                      // Load  I2CDRB
  while ((I2CIFG & TXRDYIFG) == 0);     // Wait for transmitter to be ready
  TXData++;                             // Increment TX data
  I2CDRB = TXData;                      // Load  I2CDRB
  while ((I2CIFG & TXRDYIFG) == 0);     // Wait for transmitter to be ready
  TXData++;                             // Increment TX data
  I2CDRB = TXData;                      // Load  I2CDRB
    
  while(1);

}

⌨️ 快捷键说明

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