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.

4-wire SPI

Other Parts Discussed in Thread: MSP430G2553

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;
}

  • Michael Hatch said:
    then it will randomly get jammed somewhere in the code and do not see where it is getting stuck.

    What do you mean? It stops transmitting MST_DAT?

    Can you add some port pin toggling code in the ISR routines so that you can monitor when the ISRs are firing with an oscilloscope?

  • The program will run when the UCxSTE pin is put into master active state and will stop in the inactive state but after a few transitions then the program will not go back into the ISR's and will just produce a high clock but no clock signal

  • Read through some of the nuances talked about in this post: http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/251036.aspx

  • Thankyou, I see where the error in my code was. I forgot to reset the state after the UCxSTE line went low and after adding the reset code works flawlessly

  • Michael Hatch said:
    UCB0CTL0 |= UCCKPL | UCMODE_2 | UCMSB | UCMST | UCSYNC; //SPI mode, 8-bit, 4-pin mode

    YOu shouldn't use 4-wire SPI mode when you're the only master in the system.

    4-wire mode uses STE as input only. It does nto control the slave (chip select) as every slave needs its own chip select. This is done by palin GPIO by your software.
    STE in master mode switches the USCI into slave mode when another master wants the MSP to listen or shut up.

    What probably happens is that STE switches the USCI into slave mode, and since there is no master and the software doesn't detect this event and acts accordingly, the whole thing stalled.

    Personally, I think the name '4-wire' was an unlucky choice because many people thing '3 wire' means one bi-directional data line, one clock line and a chip select line, while '4 wire' means one input, one output, one clock and one chip select. Like you apparently did.

    Reading the module description in the users guide, or taking a look at the port pin schematics would reveal the mistake, but too often people stop reading when they think they understood. Understandable, but not a good idea.

    BTW: you may still use the pint hat is used for STE as GPIO for slave chip select. Just don't use 4-wire mode and don't set PxSEL or this pin.

    Btw:

    Michael Hatch said:
    P1SEL2 = BIT4 + BIT5 + BIT6 + BIT7; //select port 1 bits 1, 2, and 4

    Your comments should match your code.
    You're obviously neither setting bits on port 1, nor do you set bits 1,2 and 4. But nobody can say whether you want to set bits 1,2 and 4 on P1 and your code is wrong or want to set bits 4,5, 6 and 7 on P2 and the comment is wrong.

**Attention** This is a public forum