Hi TI Community,
I have been trying for the past few weeks to simply communicate my MSP430f2618 with an accelerometer found on Sparkfun (https://www.sparkfun.com/products/10345). I tested the breakout board with an Arduino and the example code where it worked, however using it on the TI chip is proving to be more difficult.
Currently I can see it sending the correct bits on the oscilloscope, but the response I get from the accelerometer is most of the time just 0x00 and if it does respond it doesn't make sense. Code I have been using
unsigned char test;
unsigned int i;
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
BCSCTL1 |= XT2OFF;
// master initialise
initSPI();
for (;;) {
// get accelerometer readings
P3OUT &= ~0x01;
IFG2 &= ~UCB0TXIFG;
UCB0TXBUF = 0xA0; //read bit | non consecutive measure bit | 0x28 = 0xA8
while (!UCB0TXIFG) ;
for(i=0;i<5;i++);
IFG2 &= ~UCB0RXIFG;
UCB0TXBUF = 0x00; //read bit
while (!UCB0RXIFG)
;
test = UCB0RXBUF;
P3OUT |= 0x01;
printf("%x\n", test);
}
}
void initSPI(void) {
P3SEL |= 0x0e;
P3DIR |= 0x01;
UCB0CTL0 |= UCMST + UCSYNC + UCMSB + UCCKPL;
UCB0CTL1 |= UCSSEL_2;
UCB0CTL1 &= ~UCSWRST;
}
The code initialises the SPI ports etc, then sends a byte and should print the one it receives... Is there something major I have missed ? Using CCS Version: 5.2.1.00018.