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