This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2553: CCS/MSP430G2553

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP-EXP430G2ET

Tool/software: Code Composer Studio

Hi,

I'm trying to use the SPI interface on the MSP430G2553 chip, but I can't get an answer from the slave device. The slave device is a MPU 6500 module (it has an accelerometer, etc) and I don't know if the problem is in the SPI configuration or in the slave device.

In the code below im just trying to send some words to configurate the chip, but all I receive is a 0xFF on the RXBUFF.. If I disconnect the device, I will receive the same 0xFF on the RXBUFF, so is not the device answering me.

Also I watched the input pin(P1.1) on the MSP430G2553 and is not changing at all.

Is my SPI configuration correct?

Sorry for my bad english. I hope you can understand me.

\\

#include <msp430.h>
#include <RegisterMap6500.h>
#define WRITE (0x00)
#define READ (0x80)
#define SLAVE_CS_OUT P2OUT
#define SLAVE_CS_DIR P2DIR
#define SLAVE_CS_PIN BIT0


static char data0,data1,data2,c1;

void spi_write_slave(char data);
void enviar_dato_slave(char dir,char dato);
void leer_dato_slave(char dir);
char spi_read_slave();
int i;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer


// Configuración del clock

BCSCTL1 = CALBC1_8MHZ; // Datos de calibración para 8MHz
DCOCTL = CALDCO_8MHZ; 

SLAVE_CS_DIR |= SLAVE_CS_PIN;  // nCs Chip select
SLAVE_CS_OUT |= SLAVE_CS_PIN;

/* P1.1 – UCA0SOMI
P1.2 – UCA0SIMO
P1.4 – UCA0CLK
P2.0 - nCS
*/

P1SEL |= BIT1 + BIT2 + BIT4 ; // USCI pin 1.1, 1.2, 1.4
P1SEL2 |= BIT1 + BIT2 + BIT4 ;


/* Inicializacion SPI */

UCA0CTL1 |= UCSWRST;

UCA0CTL0 |= UCCKPL+UCMSB + UCMST + UCSYNC; // MSB , master mode, 8 bits , CLK starts on 1
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 8; // /8
UCA0BR1 = 0;

UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

while(1){


SLAVE_CS_OUT &= ~SLAVE_CS_PIN;    // Chip select goes low

__delay_cycles(100000);                                 // I don't know if this delay is neccesary
while (!(IFG2 & UCA0TXIFG));                       // USCI_A0 TX buffer ready?
UCA0TXBUF = 0xCA;                                     // Dummy write to start SPI 
__delay_cycles(500);
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 RX buffer ready?
data0 = UCA0RXBUF;


c1= WRITE | (PWR_MGMT_1 & 0x7F) ;
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = c1; 
__delay_cycles(500);
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 RX buffer ready?
data0 = UCA0RXBUF;

c1= WRITE | (USER_CTRL & 0x7F) ;
spi_write_slave(c1); 
__delay_cycles(500);
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
data0 = UCA0RXBUF;


c1= READ | (WHOAMI & 0x7F) ;
spi_write_slave(c1);
__delay_cycles(500);
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
data0 = UCA0RXBUF;

while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = 0x00; 
__delay_cycles(500);
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
data0 = UCA0RXBUF;              // I think I have to receive the answer for the data of WHOAMI register for whick I asked before.

SLAVE_CS_OUT |= SLAVE_CS_PIN;   // 

__delay_cycles(1000);

}


return 0;

}

void spi_write_slave(char data){

while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = data;
}

**Attention** This is a public forum