//IAR Assembler for MSP430 7.11.1 (7.11.1.983)
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main ; make the main label vissible outside this module
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
RESET MOV #SFE(CSTACK), SP ; set up stack
StopWDT mov.w #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
// Configure SMCLK = 19.61MHz (3.3V)
main: bis.b #RSEL0, &BCSCTL1
bis.b #RSEL1, &BCSCTL1
bis.b #RSEL2, &BCSCTL1
bis.b #RSEL3, &BCSCTL1 ; RSELx = 15 (1111b)
bis.b #DCO0, &DCOCTL
bis.b #DCO1, &DCOCTL
bis.b #DCO2, &DCOCTL ; DCOx = 7 (111b)
bic.b #MOD0, &DCOCTL
bic.b #MOD1, &DCOCTL
bic.b #MOD2, &DCOCTL
bic.b #MOD3, &DCOCTL
bic.b #MOD4, &DCOCTL ; MODx = 0 (00000b)
bis.b #10h,&P1SEL ; P1.4 (pin #6) = SMCLK
// P1.6 (pin #22) = SCL
bic.b #40h, &P1DIR ; Input
bis.b #40h, &P1SEL ; I2C pin SCL = ENABLE
bis.b #40h, &P1SEL2 ; I2C pin SCL = ENABLE
// P1.7 (pin #23) = SDA
bic.b #80h, &P1DIR ; Input
bis.b #80h, &P1SEL ; I2C pin SDA = ENABLE
bis.b #80h, &P1SEL2 ; I2C pin SDA = ENABLE
// Configure USCI_B0 for I2C mode
bis.b #UCSWRST, &UCB0CTL1 ; Enable SW reset
bis.b #UCMST, &UCB0CTL0 ; I2C Master mode
bis.b #UCMODE_3, &UCB0CTL0 ; eUSCI mode = I2C
bis.b #UCSYNC, &UCB0CTL0 ; 1=Synchronous mode
bic.b #UCSLA10, &UCB0CTL0 ; Address slave with 7-bit address
bis.b #UCSSEL_3+UCSWRST,&UCB0CTL1 ; Use SMCLK, keep SW reset
mov.b #00200, &UCB0BR0 ; baudrate = SMCLK / 200
mov.b #00000, &UCB0BR1 ; ~100KHz
bic.b #UCSWRST, &UCB0CTL1 ; Clear SW reset, resume operation
//Transmit
mov.w #0020h, &UCB0I2CSA ; I2C slave address = AD7998-0 (AS=Float)
bis.b #UCTR, &UCB0CTL1 ; UCTR=1 -> I2C=TX
BIS.B #UCTXSTT, &UCB0CTL1 ; Transmit START cond.
nnn: BIT.B #UCB0TXIFG, &IFG2 ; UCB0TXIFG=1?
JNC nnn
mov.b #04h, &UCB0TXBUF ; 04h -> Tx
BIS.B #UCTXSTP, &UCB0CTL1 ; transmit STOP cond
i2c_rdy bit.b #UCBBUSY, &UCB0STAT ; wait until I2C module has finished all operations
JC i2c_rdy
JMP $ ; jump to current location '$'
; (endless loop)
//------------------------------------------------------------------------------
COMMON INTVEC ; Interrupt Vectors
//------------------------------------------------------------------------------
ORG RESET_VECTOR ; Reset Vector
DW RESET
END
RUN: No data was transferred. Address only!!! Why?
RUN STEP-BY-STEP - WORK!!!!
RUN WITH DELAY:
//Transmit
mov.w #0020h, &UCB0I2CSA ; I2C slave address = AD7998-0 (AS=Float)
bis.b #UCTR, &UCB0CTL1 ; UCTR=1 -> I2C=TX
BIS.B #UCTXSTT, &UCB0CTL1 ; Transmit START cond.
nnn: BIT.B #UCB0TXIFG, &IFG2 ; UCB0TXIFG=1?
JNC nnn
Wait mov.w #01000, R15 ; Delay to R15
L1 dec.w R15 ; Decrement R15
jnz L1 ; Delay over?
mov.b #04h, &UCB0TXBUF ; 04h -> Tx
BIS.B #UCTXSTP, &UCB0CTL1 ; transmit STOP cond
i2c_rdy bit.b #UCBBUSY, &UCB0STAT ; wait until I2C module has finished all operations
JC i2c_rdy
JMP $
No data was transferred. Address only!!! Why?