在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            MSP430F5529 I2C 程序

            作者: 時(shí)間:2016-11-13 來(lái)源:網(wǎng)絡(luò) 收藏
            MSP430板子到了好久,一直沒(méi)有時(shí)間來(lái)寫(xiě)程序,前兩天終于有空了,把I2C調(diào)試了下,參照TI給的例程,把發(fā)送和接收整合到一起。期間中斷屏蔽處理的不好,經(jīng)常進(jìn)不了中斷。網(wǎng)上也沒(méi)有可參照的例程。只有仔細(xì)讀了MSP430F55xx的用戶(hù)手冊(cè),才調(diào)通。用戶(hù)手冊(cè)才是王道呀!

            #include <msp430.h>
            #include "i2c.h"
            extern unsigned char RXData,TXData,TXByteCtr,ATXData[2];

            void I2C_Init(uint8_t SlaveAddress)
            {
            P3SEL |= 0x03; // Assign I2C pins to USCI_B0
            UCB0CTL1 |= UCSWRST; // Enable SW reset
            UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
            UCB0CTL1 = UCSSEL_2 + UCSWRST+UCTR; // Use SMCLK
            UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
            UCB0BR1 = 0;
            UCB0I2CSA = SlaveAddress; // Slave Address is 048h
            UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
            UCB0IE |= UCTXIE+UCRXIE+UCSTPIE;
            }
            void I2C_WriteReg(unsigned char RegAddr, unsigned char Data) //////////涓婁笅灞侫PI闇?瑕佺敤鍒?
            {

            TXByteCtr = 2; // Load TX byte counter
            ATXData[0]=RegAddr;
            ATXData[1]=Data;

            while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
            UCB0IE |= UCTXIE;
            UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
            __bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
            __no_operation();
            }


            uint8_t I2C_ReadByte() //////////涓婁笅灞侫PI闇?瑕佺敤鍒?
            {

            while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
            UCB0CTL1 &= ~UCTR;
            UCB0IE &=~ UCTXIE;
            UCB0CTL1 |= UCTXSTT; // I2C start condition

            while(UCB0CTL1 & UCTXSTT); // Start condition sent?
            UCB0CTL1 |= UCTXSTP;
            return RXData;

            }


            #pragma vector = USCI_B0_VECTOR
            __interrupt void USCI_B0_ISR(void)
            {
            switch(__even_in_range(UCB0IV,12))
            {
            case 0: break; // Vector 0: No interrupts
            case 2: break; // Vector 2: ALIFG
            case 4: break; // Vector 4: NACKIFG
            case 6: break; // Vector 6: STTIFG
            case 8:
            UCB0IFG &= ~UCSTPIFG; // Clear stop condition int flag
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0 if data was transmitted
            break; // Vector 8: STPIFG
            case 10:
            RXData=UCB0RXBUF;
            // UCB0CTL1 |= UCTXNACK+UCTXSTP;
            UCB0IFG &= ~UCRXIFG;

            __bic_SR_register_on_exit(LPM0_bits);
            break; // Vector 10: RXIFG
            case 12: // Vector 12: TXIFG
            if (TXByteCtr) // Check TX byte counter
            {
            UCB0TXBUF = ATXData[2-TXByteCtr]; // Load TX buffer
            TXByteCtr--; // Decrement TX byte counter
            }
            else
            {
            UCB0CTL1 |= UCTXSTP; // I2C stop condition
            UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
            __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
            }
            break;
            default: break;
            }
            }

            本文引用地址:http://www.biyoush.com/article/201611/316475.htm


            關(guān)鍵詞: MSP430F5529I2

            評(píng)論


            技術(shù)專(zhuān)區(qū)

            關(guān)閉