1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

msp430g2x21 usi 15

4 89 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 7,79 KB

Nội dung

//****************************************************************************** // MSP430G2x21/G2x31 - I2C Slave Receiver / Slave Transmitter, multiple bytes // // Description: I2C Master communicates with I2C Slave using // the USI Master data should increment from 0x55 with each transmitted byte // ACLK = n/a, MCLK = SMCLK = Calibrated 1MHz // // ***THIS IS THE SLAVE CODE*** // // Slave Master // (msp430g2x21_usi_12.c) // MSP430G2x21/G2x31 MSP430G2x21/G2x31 // // /|\| XIN|/|\| XIN|// | | | | | | // |RST XOUT| |RST XOUT|// | | | | // LED LED // | SDA/P1.7| ->|P1.6/SDA | // | SCL/P1.6|< -|P1.7/SCL | // // Note: internal pull-ups are used in this example for SDA & SCL // // D Dang // Texas Instruments Inc // October 2010 // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10 //****************************************************************************** #include #define Number_of_Bytes // **** How many bytes?? **** void Setup_USI_Slave(void); char MST_Data = 0; char SLV_Data = 0x55; char SLV_Addr = 0x90; int I2C_State, Bytecount, transmit = 0; // Variable for received data // Address is 0x486->8 // Tx bytes to Master: State 2->4->10->12->14 //****************************************************************************** #pragma vector = USI_VECTOR interrupt void USI_TXRX (void) { if (USICTL1 & USISTTIFG) // Start entry? { P1OUT |= 0x01; // LED on: sequence start I2C_State = 2; // Enter 1st state on start } switch( even_in_range(I2C_State,14)) { case 0: break; // Idle, should not get here case 2: // RX Address USICNT = (USICNT & 0xE0) + 0x08; // Bit counter = 8, RX address USICTL1 &= ~USISTTIFG; // Clear start flag I2C_State = 4; // Go to next state: check address break; case 4: // Process Address and send (N)Ack if (USISRL & 0x01){ // If master read SLV_Addr = 0x91; // Save R/W bit transmit = 1;} else{transmit = 0; SLV_Addr = 0x90;} USICTL0 |= USIOE; // SDA = output if (USISRL == SLV_Addr) // Address match? { USISRL = 0x00; // Send Ack P1OUT &= ~0x01; // LED off if (transmit == 0){ I2C_State = 6;} // Go to next state: RX data if (transmit == 1){ I2C_State = 10;} // Else go to next state: TX data } else { USISRL = 0xFF; // Send NAck P1OUT |= 0x01; // LED on: error I2C_State = 8; // next state: prep for next Start } USICNT |= 0x01; // Bit counter = 1, send (N)Ack bit break; case 6: // Receive data byte Data_RX(); break; case 8:// Check Data & TX (N)Ack USICTL0 |= USIOE; // SDA = output if (Bytecount

Ngày đăng: 25/12/2017, 12:23

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w