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

msp430x20x3 usi 16

7 130 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 7
Dung lượng 39,5 KB

Nội dung

//*********************************************************************** ******* // MSP430F20xx Demo - I2C Master Transmitter / Reciever, Repeated Start // // Description: I2C Master communicates with I2C Slave using // the USI Master data should increment from 0x55 with each transmitted byte // and Master determines the number of bytes transmitted and recieved, set by // the Number_of_TX_Bytes and Number_of_RX_bytes values These values will // determine how many bytes are Txed then RXed with repeated starts inbetween // LED off for address or data Ack; LED on for address or data NAck // ACLK = n/a, MCLK = SMCLK = Calibrated 1MHz // // // ***THIS IS THE MASTER CODE*** // // Slave Master // (msp430x20x3_usi_15.c) // MSP430F20x2/3 MSP430F20x2/3 // // /|\| 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 // // R B Elliott / H Grewal // Texas Instruments Inc // March 2008 // Built with IAR Embedded Workbench Version: 3.42A //*********************************************************************** ******* #include #define number_of_TX_bytes to TX? #define number_of_RX_bytes to RX? void Master_RPT(void); void Master_Transmit(void); void Master_Recieve(void); void Setup_USI_Master_TX(void); // How many bytes you want // How many bytes you want void Setup_USI_Master_RX(void); char MST_Data = 0x55; // Variable for transmitted data char SLV_Addr = 0x90; int I2C_State, Bytecount, Transmit, number_of_bytes, repeated_start = 0; void Data_TX (void); void Data_RX (void); void main(void) { volatile unsigned int i; // Use volatile to prevent removal WDTCTL = WDTPW + WDTHOLD; // Stop watchdog if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) { while(1); // If calibration constants erased // not load, trap CPU!! } BCSCTL1 = CALBC1_1MHZ; // Set DCO DCOCTL = CALDCO_1MHZ; P1OUT = 0xC0; others to P1REN |= 0xC0; P1DIR = 0xFF; P2OUT = 0; P2DIR = 0xFF; // P1.6 & P1.7 Pullups, // P1.6 & P1.7 Pullups // Unused pins as outputs while(1) { Bytecount = 0; Master_RPT(); } } /****************************************************** // USI interrupt service routine // Data Transmit : state -> -> -> 10 -> 12 -> 14 // Data Recieve : state -> -> -> -> -> 14 ******************************************************/ #pragma vector = USI_VECTOR interrupt void USI_TXRX (void) { switch( even_in_range(I2C_State,14)) { case 0: // Generate Start Condition & send address to slave P1OUT |= 0x01; // LED on: sequence start Bytecount = 0; USISRL = 0x00; // Generate Start USICTL0 |= USIGE+USIOE; USICTL0 &= ~USIGE; if (Transmit == 1){ USISRL = 0x90; // Address is 0x48

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

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