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.

SPI communication by UCA0 with two MSP430F5529

Hello, 

I wrote the following code for master and slave. I try to communicate in 4 pin mode. appearently i can not recieve data from Slave or Slave doesn't recieve data from master because of STE pin fault.  Master's UCA0STAT's UCOE bit sets, gives Overrun Error Flag how can i work this code?

note that i am newbie.

CODE FOR MASTER;

#include <msp430.h>

/*
* main.c
*/

unsigned char master_tx_data;
unsigned char master_rx_data;

tester_m = 0;

int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P2SEL |= BIT7; // P2.7 3.2 3.3 3.4 option select
P3SEL |= BIT2 + BIT3 + BIT4; // set output pins, SOMI,SIMO,STE,SCLK


UCA0CTL1 |= UCSWRST; // SPI enable make settings

UCA0CTL0 |= UCCKPH | UCMSB | UCMST | UCMODE_2 | UCSYNC; // clock phase, most significant bit, master mode, STE LOW, sync mode.
UCA0CTL1 |= UCSSEL_2;


UCA0CTL1 &= ~UCSWRST; // finish settings start to transmit and recieve
UCA0IE |= UCTXIE; // Enable USCI_A0 TX interrupt


master_tx_data = 3;

__bis_SR_register(GIE); // enable interrupts


return 0;
}


#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{

if(UCA0IFG&&UCTXIFG)) {

UCA0TXBUF = master_tx_data;
UCA0IE |= UCRXIE;
UCA0IE &= ~UCTXIE;

tester_m = 1;
}

else if(UCA0IFG&&UCRXIFG) {

UCA0IE &= ~UCRXIE;
master_rx_data = UCA0RXBUF;

tester_m = 2;
}

}

CODE FOR SLAVE;

#include <msp430.h>

/*
* main.c
*/
int tester_s = 0;

unsigned char slave_tx_data;
unsigned char slave_rx_data;

int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

P2SEL |= BIT7; // P2.7 3.2 3.3 3.4 option select
P3SEL |= BIT2 + BIT3 + BIT4; // set output pins, SOMI,SIMO,STE,SCLK


UCA0CTL1 |= UCSWRST; // SPI enable make settings

UCA0CTL0 |= UCCKPH | UCMSB | UCMST | UCMODE_2 | UCSYNC; // clock phase, most significant bit, slave mode, STE LOW, sync mode.
UCA0CTL1 |= UCSSEL_2;


UCA0CTL1 &= ~UCSWRST; // finish settings start to transmit and recieve
UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt


__bis_SR_register(GIE); // enable interrupts


return 0;
}


#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{


if (UCA0IFG && UCTXIFG)

{
slave_tx_data = 2*slave_rx_data;
UCA0TXBUF = slave_tx_data;
UCA0IE &= ~UCTXIE;

tester_s = 1;
}

else if (UCA0IFG && UCRXIFG)
{

slave_rx_data = UCA0RXBUF;
UCA0IE &= ~UCRXIE;
UCA0IE = UCTXIE;

tester_s = 2;
}

}

thanks for help

  • Hi Mehmet!

    Is your code based on the Master-slave example from TI's code examples for the processor? If not, download them and have look at

    • MSP430F55xx_uscia0_spi_09.c       USCI_A0, SPI 3-Wire Master Incremented Data
    • MSP430F55xx_uscia0_spi_10.c       USCI_A0, SPI 3-Wire Slave Data Echo

    You can then add your specific features to the examples. If it is based on it, then I would recommend to again start from the examples and add small portions of functionality. Test each new step after implementing. Often writing a large program without testing modules will make finding the error more difficult.

    Dennis

  • Remove the else. Replace && with &. Learn about C.

**Attention** This is a public forum