?? msp430x24x_uscib0_i2c_11.s43
字號:
;*******************************************************************************
; MSP430x24x Demo - USCI_B0 I2C Slave TX multiple bytes to MSP430 Master
;
; Description: This demo connects two MSP430's via the I2C bus. The slave
; transmits to the master. This is the slave code. The interrupt driven
; data transmission is demonstrated using the USCI_B0 TX interrupt.
; ACLK = n/a, MCLK = SMCLK = 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 #UCMODE_3+UCSYNC,&UCB0CTL0
; I2C Slave, synchronous mode
mov.w #048h,&UCB0I2COA ; Own Address is 048h
bic.b #UCSWRST,&UCB0CTL1 ; Clear SW reset, resume operation
bis.b #UCSTPIE+UCSTTIE,&UCB0I2CIE
; Enable STT and STP interrupt
bis.b #UCB0TXIE,&IE2 ; Enable TX interrupt
Main mov.w #TxData,R5 ; Start of TX buffer
clr.w R6 ; Clear TX byte count
bis.b #LPM0+GIE,SR ; Enter LPM0, enable interrupts
; Remain in LPM0 until master
; finishes RX
nop ; Set breakpoint >>here<< and
; read out the R6 counter
jmp Main ; Repeat
;-------------------------------------------------------------------------------
; The USCI_B0 data ISR is used to move data from MSP430 memory to the
; I2C master. R5 points to the next byte to be transmitted, and R6 keeps
; track of the number of bytes transmitted.
;-------------------------------------------------------------------------------
USCIAB0TX_ISR; USCI_B0 Data ISR
;-------------------------------------------------------------------------------
mov.b @R5+,&UCB0TXBUF ; Transmit data at address R5
inc.w R6 ; Increment TX byte counter
reti
;-------------------------------------------------------------------------------
; The USCI_B0 state ISR is used to wake up the CPU from LPM0 in order to do
; processing in the main program after data has been transmitted. LPM0 is
; only exit in case of a (re-)start or stop condition when actual data
; was transmitted.
;-------------------------------------------------------------------------------
USCIAB0RX_ISR; USCI_B0 State ISR
;-------------------------------------------------------------------------------
bic.b #UCSTPIFG+UCSTTIFG,&UCB0STAT
; Clear interrupt flags
tst.w R6 ; Check TX byte counter
jz USCIAB0RX_ISR_1 ; Jump if nothing was transmitted
bic.w #LPM0,0(SP) ; Clear LPM0
USCIAB0RX_ISR_1
reti
;-------------------------------------------------------------------------------
TxData; Table of data to transmit
;-------------------------------------------------------------------------------
DB 011h ; Table of data to transmit
DB 022h
DB 033h
DB 044h
DB 055h
;-------------------------------------------------------------------------------
COMMON INTVEC ; Interrupt Vectors
;-------------------------------------------------------------------------------
ORG USCIAB0TX_VECTOR ; USCI_B0 I2C Data Int Vector
DW USCIAB0TX_ISR
ORG USCIAB0RX_VECTOR ; USCI_B0 I2C Sate Int Vector
DW USCIAB0RX_ISR
ORG RESET_VECTOR ; POR, ext. Reset, Watchdog
DW RESET
END
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -