Hi,
I need to interface ADXL345 with MSP430F5438A for my final year project. I have used 4 wire SPI mode of interfacing. I have attached the my initial code which reads the Device Id of ADXL345. I have used USCI_A3 module for spi. The problem is i don't get any response from the msp430. When i checked the UCA3CLK pin10.0 with the CRO there is no clock coming out of it. I have attached my code . Pls check whether my code is correct and whether it needs any modification for proper working.
Thanks in advance :-)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CCS5 - code
#include <stdio.h>
#include "msp430f5438.h"
// FUNCTION PROTOTYPES
void CONFIGURE_SPI(void);
void ENABLE_SPI(void);
void DISABLE_SPI(void);
void INITIALIZE_TIMER(void);
void ENABLE_INTERRUPT(void);
void DISABLE_INTERRUPT(void);
void GET_DEVICE_ID(void);
// VARIABLE DECLARATION
int Data_received[1000][6];
int m,n,temp,i;
unsigned char DEVID;
//static int i=0;
int sign, value;
int x_data[100],y_data[100],z_data[100];
// SPI CONFIGURATION
// Using A3 module for SPI 4 wire Communication (port 10)
// pin10.0 = UCA3CLK
// pin10.4 = MOSI
// pin10.5 = MISO
// pin10.1 ------ BIT1 CHIP SELECT
void CONFIGURE_SPI()
{
DISABLE_SPI();
// Configuring the IO pins for SPI
P10SEL = (BIT0 | BIT4 | BIT5); // Enabling the peripheral module function of those pins
P10DIR = BIT1; // Defining the direction of the bit0,3 and 4 as o/p ..
P10DS = BIT1 ; // Making the Full output drive strength for those bits
// Configuring the control registers for SPI
UCA3CTL0 = (UCCKPH | UCCKPL | UCMSB | UCMST | UCMODE1 | UCSYNC ); // Configure the control register of SPI
UCA3CTL1 |= UCSSEL1; // Configure the control register of SPI
UCA3MCTL = 0x00; // No modulation control is performed
//Bit rate
UCA3BR0 = 02;
UCA3BR1 = 00;
}
void ENABLE_SPI()
{
UCA3CTL1 &= ~UCSWRST;
}
void DISABLE_SPI()
{
UCA3CTL1 |= UCSWRST;
}
void DISABLE_INTERRUPT() // Disable the Chip select pin of ADXL
{
P10OUT |= BIT1 ;
}
void ENABLE_INTERRUPT() // Enable the chip select pin of ADXL345
{
P10OUT &= ~BIT1;
// Delay to stabilise the ADXL
TA0CCR0 = 0x6FFF; // Set the value in TA0CCR0 to start the timer
while(!(TA0CTL & TAIFG)); //TAIFG flag is set when the timer Counts to TA0CCR0
TA0CTL &= ~TAIFG; //Clear the TAIFG flag
TA0CCR0 = 0x0000; //Stop the timer
}
void INITIALIZE_TIMER()
{
TA0CTL = TACLR ;
TA0CTL = (TASSEL_2 | ID_3 | MC_1);
/* TASSEL_2 = Timer A clock source select: 2 - SMCLK
ID_3 = Timer A Input Divider 3 "/8"
MC_1 = Timer A mode control - Up counter */
TA0EX0 = TAIDEX_1; // Further Dividing by 2 ;
}
void GET_DEVICE_ID()
{
ENABLE_INTERRUPT();
while(!(UCA3IFG & UCTXIFG)); //Check if the TXBUF is empty
UCA3TXBUF = 0x80;
while(!(UCA3IFG & UCTXIFG));
UCA3TXBUF = 0x00; // Sending dummy variable to enable the reception
while(UCA3STAT & UCBUSY);
DEVID = UCA3RXBUF;
DISABLE_INTERRUPT();
}
// MAIN CLASS
int main()
{
WDTCTL = WDTPW + WDTHOLD; // STOP THE WATCHDOG TIMER
P1DIR |= 0x01; // Set P1.0 to output direction
P7DIR |= BIT7; // Power Supply to ADXL
P7DS |= BIT7;
P7OUT |= BIT7;
DISABLE_INTERRUPT();
CONFIGURE_SPI();
INITIALIZE_TIMER();
ENABLE_SPI();
GET_DEVICE_ID();
P1OUT = 0x00;
if(DEVID == 0xE5)
{
P1OUT = 0x01; // LED is ON when the DEVID matches 0xE5(Device Id of ADXL345)
}
return 0;
}