hello
I am trying to interface msp430g2553 launchpad board with ADXL345 via SPI. when i run code step by step ,it runs fine, But when i run it continuously it gets stuck on checking UCB0RXIFG flag.
Here is my code
;
#include "msp430G2553.h" ;
#include "COM_MACRO.S43" ;
;
;------------------------ Initialization of the variables -------------------------------;
;----------------------------------------------------------------------------------------;
;
ORG 0200H
ADDRESS DB 00H
DATAA DB 00H
;
;--------------------------------Program Start-------------------------------------------;
;----------------------------------------------------------------------------------------;
ORG 0F800H ; Program Reset ;
;----------------------------------------------------------------------------------------;
RESET mov.w #0280H,SP ; Initialize stackpointer ;
SetupWDT mov.w #WDTPW+WDTHOLD,&WDTCTL
mov.b #0AFh,&P1DIR ; P1.2 output For PWM ;
BIS.B #BIT3,&P1DIR ; P1.3 Red LED Blink for debugging
BIC.B #BIT3,&P1OUT
bis.b #0e0h,&P1SEL ; enabling alternate function for SPI pins
bis.b #0e0h,&P1SEL2
MOV.W #0000H,R10
CS_EN
CALL #DELAY2
CS_dis
;----------------------- Initialising USI / PORTS / 7455 Calibration ----------------------------;
SetupUSI ; Configure the USI module for SPI operation. ;
LED_BLK ; LED indicating Power up ;
;------------------------------------------------------------------------------------------------;
;---------------------------------------------------------------------------------;
MAIN MOV.B #080H,&ADDRESS ; read DEV_ID axis data
CALL #READ_7455
MOV.B #080H,&ADDRESS ; read DEV_ID axis data
CALL #READ_7455
MOV.B #00bH,&DATAA
MOV.B #031H,&ADDRESS ; Configure accelrometer in standby mode.
CALL #WRITE_7455
MOV.B #008H,&DATAA
MOV.B #02dH,&ADDRESS ; Configure accelrometer in standby mode.
CALL #WRITE_7455
MOV.B #080H,&DATAA
MOV.B #02eH,&ADDRESS ; Configure accelrometer in standby mode.
CALL #WRITE_7455
nop
nop
nop
nop
REPEAT MOV.B #0B2H,&ADDRESS ; read x axis data
CALL #READ_7455
BIS.B #BIT0,&P1OUT
call #DELAY2
BIc.B #BIT0,&P1OUT
call #DELAY2
CALL #REPEAT
// MOV.B #0B3H,&ADDRESS ; read x axis data
// CALL #READ_7455
;------------------------------------------------------------------------------------------------;
call #READ_7455
CALL #DELAY2
;===================================================================================
;-------------------------- WRITE TO 7455 --------------------------------------
WRITE_7455 CS_EN ; Enable the chip.
CALL #WRITE_SPI ; Call the write function.
CS_DIS ; Disable the chip.
RET
;------------------------- READ FROM 7455 --------------------------------------
READ_7455 CS_EN ; Enable the chip.
CALL #READ_SPI ; Call the read function.
CS_DIS ; Disable the chip.
RET
;=================================================================================
;------------------------ WRITE THROUGH SPI ------------------------------------
WRITE_SPI
LOOPD BIT.B #UCB0TXIFG , &IFG2
JNC LOOPD
MOV.B &ADDRESS,UCB0TXBUF
LOOPE BIT.B #UCB0TXIFG , &IFG2
JNC LOOPE
MOV.B &DATAA,UCB0TXBUF
LOOPF BIT.B #UCB0TXIFG , &IFG2
JNC LOOPF
RET
;--------------------------- READ THROUGH SPI ---------------------------------
READ_SPI
LOOPA BIT.B #UCB0TXIFG , &IFG2 ;CHECK IF TX BUFFER IS READY
JNC LOOPA
MOV.B &ADDRESS,UCB0TXBUF ;ADDRESS OF REGIETER TO READ
LOOPB BIT.B #UCB0TXIFG , &IFG2
JNC LOOPB
MOV.B #000H,UCB0TXBUF ;DUMMY VALUE TO RETRIVE DATA
LOOPC BIT.B #UCB0RXIFG , &UC0IFG
JNZ LOOPC
MOV.B UCB0RXBUF , R10
RET
;====================================================================================
DELAY2 MOV #0FFFH,R5 ; Delay to R5
L3 DEC.W R5 ; Decrement R5
JNZ L3 ; Delay over?
RET
;-------------------------------------------------------------------------------
; Interrupt Vectors Used
;-------------------------------------------------------------------------------
ORG 0FFFEh ; MSP430 RESET Vector
DW RESET ;
ORG 0FFE4H ; Port1 Interrupt vector
// DW PORT1_ISR
END
;--------------------------------------------------------------------------
COM_MACRO
;-------------------------------------------------------------------------------
LED_BLK MACRO
BIS.B #BIT0,&P1OUT
CALL #DELAY2
BIC.B #BIT0,&P1OUT
ENDM
;-------------------------------------------------------------------------------
CS_EN MACRO
BIC.B #BIT1,&P1OUT ; Enable the accelerometer chip.
ENDM
CS_DIS MACRO
BIS.B #BIT1,&P1OUT ; Disable the acceleromrter chip.
ENDM
;------------ Setup the USI module of the 2013 for SPI communication -----------
SetupUSI MACRO
BIS.B #UCSWRST+UCSSEL_2,&UCB0CTL1 ; Disable USCI
BIS.B #UCCKPL+UCMST+UCMSB+UCSYNC,&UCB0CTL0; Port, SPI master
MOV.B #00H, &UCB0BR0
MOV.B #00H,&UCB0BR1
BIC.B #UCSWRST,&UCB0CTL1 ; Enable USI
ENDM
;------------------------------- Port initialization ---------------------------
Setup_PORT MACRO
BIS.B #0AFH,&P1DIR ;
BIC.B #BIT0,&P1OUT ; Clear the LED indicator.
BIC.B #BIT4,&P1IFG ; Clear the interrupt flag for the corresponding interrupt.
BIC.B #BIT4,&P1IES ; Select the Low to high edge for the interrupt.
BIS.B #BIT1,&P1OUT ; P1.1(CS of ADXL345 IS SET OFF)
ENDM
;-------------------------------------------------------------------------------