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?
volatile unsigned int h = 0xFF; // h is for a temp store
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
__interrupt void universal_serial_interface(void)
volatile unsigned int i; // volatile to prevent optimization
volatile unsigned int j; // i and j are for timers
USICTL1 ^= USIIE;
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.