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 setup code causing stack to overflow?

Other Parts Discussed in Thread: MSP430F2003

Hello folks,


I'm programming a MSP430F2003 over SpyBiWire with the standard TI USB emulator and the latest copy of IAR (downloaded from TI)

I'm not the worlds greatest C programmer (I'm an analog guy trying to write some control code), so I've bashed together what I could below based on some code examples and snippets I've seen strewn accross the web.


I'm just trying to get the USI to spit out a string of data, toggle a CS pin (actually 2 of them.. one is connected to an LED for visual feedback)

When I run it, I get some really strange debug messages, including one that tells me that the stack is overflowing.


I'm sure there's a schoolboy error here somewhere. Please let me know if you see something stupid?





#include <msp430x20x3.h>

volatile unsigned int h = 0xFF;            // h is for a temp store

int main(void)
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1DIR |= 0x0C;                        // Set P1.2 and 3 to output direction
  // serial port setup
  USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI Master
  USICTL1 |= USIIE;               // Counter interrupt, flag remains set
  USICKCTL = USIDIV_7 + USISSEL_2;          // /128 SMCLK
  USISRL = h;                            // Set serial port register to 11110000
  USICNT = 8;                               // init-load counter
  USICTL0 &= ~USISWRST;                     // USI released for operation

  _BIS_SR(LPM0_bits + GIE);             // Enter LPM0 w/ interrupt

// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
  volatile unsigned int i;            // volatile to prevent optimization
  volatile unsigned int j;            // i and j are for timers
  P1OUT |= 0x0C ;                      // Toggle CS 1.2 and 1.3 high after data has transmitted
        i = 10000;
        }while (i !=0);

  P1OUT &= ~0x0C;                       // set 1.2 and 1.3 low
  h ^= 0xFF;
  USISRL = h;                            // Toggle the output data.
  USICNT = 8;                           // re-load counter, and restart the datatransmit




One thing is different on my board from the usual - on my spibywire connector, I have a 39Kohm resistor instead of the 47KOhm that's suggested. (i didn't have one to hand and wanted to fire the board up)

Thanks again for any advice you have.





  • Problem solved...


    I replaced my "quick fix" 39K ohm resistor with a proper 47KOhm to make sure the SpyBiWire was up to spec. (this may or may not have made a difference)

    And, I made sure the USIIFG was set to 0 before starting the USI SPI transmit.

    Since then, the part has worked without issue. I have it streaming a string of 0's, latching, then streaming 1's and latching without issue into a 595 Shift register.


    Would that code change be the main thing that stopped the device from going into stack overflow? My stack now sits at 24% used.