Other Parts Discussed in Thread: CC430F5137, CC430F6137
Hi guys!
I saw a few topics about the msp430 + adxl345. I copied some codes and tried to run them using the kit CC430F6137RF900.
The reading byte that I've got was exactly what I sent or simply 0xFF. I think the error is on the clock configuration.
Following is the code I'm using at this moment.
Thank you in advance.
#include "cc430x613x.h"
// FUNCTION PROTOTYPES
void CONFIGURE_SPI(void);
void INITIALIZE_TIMER(void);
void ADXL_On(void);
void GET_DEVICE_ID(void);
// VARIABLE DECLARATION
unsigned char DEVID;
void CONFIGURE_SPI()
{
UCA0CTL1 |= UCSWRST;
// Configuring the IO pins for SPI
PMAPPWD = 0x02D52; // Get write-access to port mapping regs
P2MAP0 = PM_UCA0SIMO; // Map UCA0SIMO output to P2.0
P2MAP2 = PM_UCA0SOMI; // Map UCA0SOMI output to P2.2
P2MAP4 = PM_UCA0CLK; // Map UCA0CLK output to P2.4
PMAPPWD = 0; // Lock port mapping registers
P1OUT |= BIT0; // Set P1.0 for LED
P1OUT |= BIT2; // Set P1.2 for CS
// Set P1.2 for slave reset
P1DIR |= BIT2 + BIT0; // Set P1.0, P1.2 to output direction
P2DIR |= BIT0 + BIT2 + BIT4; // ACLK, MCLK, SMCLK set out to pins
P2SEL |= BIT0 + BIT2 + BIT4; // P2.0,2,4 for debugging purposes.
UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB+UCCKPH+UCMODE_0; // 3-pin, 8-bit SPI master
UCA0CTL0 &= ~UC7BIT;
// Clock polarity high, MSB
UCA0CTL1 = UCSSEL_2;
UCA0BR0 = 10;
UCA0BR1 = 0x00;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
}
void ADXL_On() // Enable the chip select pin of ADXL345
{
// CS low (Enable SPI)
P1OUT &= ~BIT2;
// Delay to wait for 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()
{
ADXL_On();
UCA0IFG &= ~UCRXIFG;
while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0x80; // Transmit 0x80 to get the Device ID
while (UCA0STAT & UCBUSY);
UCA0TXBUF = 0xF4; // Sending dummy variable to enable the reception
while (UCA0STAT & UCBUSY);
// Debug
DEVID = 0xAA;
DEVID = UCA0RXBUF;
// CS high (Disable SPI)
P1OUT |= BIT2 ;
}
// MAIN CLASS
int main()
{
WDTCTL = WDTPW + WDTHOLD; // STOP THE WATCHDOG TIMER
// CS low (Disable SPI)
P1OUT |= BIT2 ;
CONFIGURE_SPI();
INITIALIZE_TIMER();
// Enable SPI
UCA0CTL1 &= ~UCSWRST;
while(1) {
GET_DEVICE_ID();
P1OUT = 0x00;
if(DEVID == 0xE5){
P1OUT = 0x01; // LED is ON when the DEVID matches 0xE5(Device Id of ADXL345)
}
}
return 0;
}


