Part Number:MSP430FR5969
Tool/software: Code Composer Studio
hiii..this is hariirkishna ..i am having a trouble when i reading the register values in adxl345 accelerometer...this is the code that wrote to access the values..and from the first time it reads correct value but atfer again restarting the program then i getting the 0x00 value as 0..and i write the correct stop condition also...please once check and let me know the problem where in my code....
#include <msp430.h>
volatile unsigned char RXData;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD;
// Configure GPIO
P1OUT &= ~BIT0; // Clear P1.0 output latch
P1DIR |= BIT0; // For LED
P1SEL1 |= BIT6 | BIT7;
PM5CTL0 &= ~LOCKLPM5;
__bis_SR_register( GIE);
UCB0CTLW0 |= UCSWRST; // Software reset enabled
UCB0CTLW0 |= UCMODE_3 | UCMST | UCSYNC; // I2C mode, Master mode, sync
UCB0CTLW1 |= UCASTP_2; // Automatic stop generated
UCB0BRW = 0x0008; // baudrate = SMCLK / 8
UCB0I2CSA = 0x53; // Slave address
UCB0CTL1 &= ~UCSWRST;
while (1)
{
//UCB0CTLW0 &= ~UCTXSTP;
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCTXSTT+UCTR;
P1OUT|=BIT0;
UCB0TXBUF=0xA6;//slave address in wite mode
while(UCB0STATW&UCBUSY);
UCB0TXBUF=0x00;//register adddress that i want to read in adxl345
while(UCB0STATW&UCBUSY);
UCB0CTL1 &= ~UCTR; // I2C read operation
UCB0CTL1 |= UCTXSTT;
UCB0TXBUF=0xA7;//slave address in read mode
UCB0IE&=~UCTXIE;
while(UCB0STATW&UCBUSY);
UCB0IE|=UCRXIE;
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
{
case USCI_NONE: break; // Vector 0: No interrupts
case USCI_I2C_UCALIFG: break; // Vector 2: ALIFG
case USCI_I2C_UCNACKIFG: // Vector 4: NACKIFG
UCB0CTL1 |= UCTXSTT;
break;
case USCI_I2C_UCSTTIFG: break; // Vector 6: STTIFG
case USCI_I2C_UCSTPIFG: break; // Vector 8: STPIFG
case USCI_I2C_UCRXIFG3: break; // Vector 10: RXIFG3
case USCI_I2C_UCTXIFG3: break; // Vector 12: TXIFG3
case USCI_I2C_UCRXIFG2: break; // Vector 14: RXIFG2
case USCI_I2C_UCTXIFG2: break; // Vector 16: TXIFG2
case USCI_I2C_UCRXIFG1: break; // Vector 18: RXIFG1
case USCI_I2C_UCTXIFG1: break; // Vector 20: TXIFG1
case USCI_I2C_UCRXIFG0: // Vector 22: RXIFG0
RXData = UCB0RXBUF;//after reading seeting atop condotion
while (UCB0CTL1 & UCTXSTT);
UCB0CTLW0&=~UCTXSTP;
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
break;
case USCI_I2C_UCTXIFG0: break; // Vector 24: TXIFG0
case USCI_I2C_UCBCNTIFG: // Vector 26: BCNTIFG
P1OUT ^= BIT0; // Toggle LED on P1.0
break;
case USCI_I2C_UCCLTOIFG: break; // Vector 28: clock low timeout
case USCI_I2C_UCBIT9IFG: break; // Vector 30: 9th bit
default: break;
}
}(Please visit the site to view this file)(Please visit the site to view this file)