Hi all,
I am interfacing SPI between MSP430G2553 and Arduino Uno R3, MSP430 acts as master and arduino is slave. I am trying to send data of 0xAA to arduino and printing on serial monitor but I see that data received is always 0x00. Below is the MSP430 code. Please let know whats wrong with my code.
#include <msp430.h>
/*
* main.c
*/
/* Function Declarations done here */
void config_pins(void);
void config_SPI();
/* Function Declaration ends here */
/* Global Variables are declared here */
unsigned int rx_data = 0x00;
unsigned int tx_data = 0x5A;
/* Global Variables declaration ends here */
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
unsigned int i=0;
config_pins();
config_SPI();
/* loop Infinitely here */
while(1)
{
P1OUT &= (~BIT5); // Select Device
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = tx_data; // Transmit data
while(!(IFG2 & UCA0RXIFG)); // Wait till the data is received.
rx_data = UCA0RXBUF;
if(rx_data == 0x55)
{
P1OUT |= BIT0;
while(i<65536)
{
i++;
}
i=0;
P1OUT |= (~BIT0);
P1OUT |= BIT5;
}
return 0;
}
void config_pins()
{
/* P1.5 is used as slave select and LED on P1.0 is toggled on receiving
the data.
*/
P1OUT = 0x20 | 0xFF;
P1DIR = 0x20 | 0xFF;
P1DIR = 0x01 | 0xFF;
P1OUT = 0x01 | 0xFF;
P1SEL = 0x16;
P1SEL2 = 0x16;
P1OUT = 0xFE & 0xFF;
}
void config_SPI()
{
/* Configure SPI
* 1. Data Captured on rising edge and sampled at falling edge.
* 2. Polarity - Inactive state is high
* 3. 8 Bit Data Length
* 4. Master Mode
* 5. 3 Pin SPI mode
* 6. Synchronous Mode.
*/
UCA0CTL1 = UCSWRST; //11000001
UCA0CTL0 = 0x69; //01101001
UCA0BR0 = 0x0;
UCA0BR1 = 0x2;
UCA0MCTL = 0x0;
/* Configure SPI
* 1. SPI Listen is set to false.
*/
UCA0STAT = BIT7;
/* Configure SPI
* 1. Enable SPI for operation.
*/
UCA0CTL1 = ~UCSWRST;
}