Hello, I am currently trying to get 4-wire SPI to work on an MSP430G2553 Micro and am having trouble having it communicate properly. The code will execute and work properly a few times then it will randomly get jammed somewhere in the code and do not see where it is getting stuck. What can be done to fix this issue and why is it getting stuck? The code i used is below:
#include "msp430g2553.h"
void SPIInit (void);
#define MST_DAT 0x6D
void main (void)
{
WDTCTL = WDTPW | WDTHOLD;
SPIInit();
while(1)
{
}
}
void SPIInit (void)
{
UCB0CTL1 |= UCSWRST; //enable software reset
UCB0CTL0 |= UCCKPL | UCMODE_2 | UCMSB | UCMST | UCSYNC; //SPI mode, 8-bit, 4-pin mode
UCB0CTL1 |= UCSSEL_2; //select SMCLK as source
UCB0BR0 = 2; //SMCLK/2 (500kHz)
UCB0BR1 = 0;
P1SEL = BIT4 + BIT5 + BIT6 + BIT7;
P1SEL2 = BIT4 + BIT5 + BIT6 + BIT7; //select port 1 bits 1, 2, and 4
P1DIR |= BIT5 + BIT7; //set direction of port 1 bits 2 and 4 output
UCB0CTL1 &= ~UCSWRST; //clear software reset
P2DIR |= BIT0;
P2DIR &= ~BIT0;
IE2 |= UCB0TXIE + UCB0RXIE;
_enable_interrupts();
}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void RXISR (void)
{
char c = UCB0RXBUF;
IFG2 &= ~UCB0RXIFG;
}
#pragma vector = USCIAB0TX_VECTOR
__interrupt void TXISR (void)
{
UCB0TXBUF = MST_DAT;
IFG2 &= ~UCB0TXIFG;
}