📄 msp430x24x_uscib0_i2c_06.s43
字号:
;*******************************************************************************
; MSP430x24x Demo - USCI_B0 I2C Master TX single bytes to MSP430 Slave
;
; Description: This demo connects two MSP430's via the I2C bus. The master
; transmits to the slave. This is the master code. It continuously
; transmits 00h, 01h, ..., 0ffh and demonstrates how to implement an I2C
; master transmitter sending a single byte using the USCI_B0 TX interrupt.
; ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1.045MHz
;
; /|\ /|\
; MSP430F249 10k 10k MSP430F249
; slave | | master
; ----------------- | | -----------------
; -|XIN P3.1/UCB0SDA|<-|---+->|P3.1/UCB0SDA XIN|-
; | | | | | 32kHz
; -|XOUT | | | XOUT|-
; | P3.2/UCB0SCL|<-+----->|P3.2/UCB0SCL |
; | | | P1.0|--> LED
;
; B. Nisarga
; Texas Instruments Inc.
; September 2007
; Built with IAR Embedded Workbench Version: 3.42A
;*******************************************************************************
#include "msp430x24x.h"
;-------------------------------------------------------------------------------
RSEG CSTACK ; Define stack segment
;-------------------------------------------------------------------------------
RSEG CODE ; Assemble to Flash memory
;-------------------------------------------------------------------------------
RESET mov.w #SFE(CSTACK),SP ; Initialize stackpointer
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop WDT
SetupP3 bis.b #06h,&P3SEL ; Assign I2C pins to USCI_B0
SetupUCB0 bis.b #UCSWRST,&UCB0CTL1 ; Enable SW reset
mov.b #UCMST+UCMODE_3+UCSYNC,&UCB0CTL0
; I2C Master, synchronous mode
mov.b #UCSSEL_2+UCSWRST,&UCB0CTL1
; Use SMCLK, keep SW reset
mov.b #12,&UCB0BR0 ; fSCL = SMCLK/12 = ~100kHz
mov.b #00,&UCB0BR1
mov.w #048h,&UCB0I2CSA ; Slave Address is 048h
bic.b #UCSWRST,&UCB0CTL1 ; Clear SW reset, resume operation
bis.b #UCB0TXIE,&IE2 ; Enable TX interrupt
clr.b R5 ; Load TX data into R5
Main mov.w #1,R6 ; Load TX byte counter
Main_1 bit.b #UCTXSTP,&UCB0CTL1 ; Ensure stop condition got sent
jc Main_1
bis.b #UCTR+UCTXSTT,&UCB0CTL1 ; I2C TX, start condition
bis.b #LPM0+GIE,SR ; Enter LPM0, enable interrupts
; Remain in LPM0 until all data
; is TX'd
inc.b R5 ; Increment data byte
jmp Main ; Repeat
;-------------------------------------------------------------------------------
; The USCIAB0TX_ISR is structured such that it can be used to transmit any
; number of bytes by pre-loading R6 with the byte count.
;-------------------------------------------------------------------------------
USCIAB0TX_ISR; USCI_B0 Data ISR
;-------------------------------------------------------------------------------
tst.w R6 ; Check TX byte counter
jz USCIAB0TX_ISR_1 ; Jump if all bytes were TX'd
mov.b R5,&UCB0TXBUF ; Load TX buffer
dec.w R6 ; Decrement TX byte counter
reti
USCIAB0TX_ISR_1
bis.b #UCTXSTP,&UCB0CTL1 ; I2C stop condition
bic.b #UCB0TXIFG,&IFG2 ; Clear USCI_B0 TX int flag
bic.w #LPM0,0(SP) ; Clear LPM0
reti
;-------------------------------------------------------------------------------
COMMON INTVEC ; Interrupt Vectors
;-------------------------------------------------------------------------------
ORG USCIAB0TX_VECTOR ; USCI_B0 I2C Data Int Vector
DW USCIAB0TX_ISR
ORG RESET_VECTOR ; POR, ext. Reset, Watchdog
DW RESET
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -