#define DAC_SYNC_BIT        0x80


unsigned int SST25VF_ExecuteSPI( unsigned int nArg );


void SST25VF_Init( void )
{
	//*********** USART0 initialization for SPI communications ***********
	ME1 |= USPIE0;					// Enable USART0 SPI mode
	UCTL0 = CHAR+SYNC+MM;			// 8-bit SPI Master **SWRST** see page 13-16 TI slau049b.pdf
	U0TCTL = CKPL+SSEL1+SSEL0+STC;	// SelectSMCLK and 3-pin SPI select??
	UBR00 = 0x04;					// UCLK/2
	UBR10 = 0x00;					// 0
	UMCTL0 = 0x00;                  // no modulation  
										  
	//  IE2 |= URXIE1;              // Enable USART1 RX interrupt

	// Setup P3 for SPI0 operation
	P3SEL |= 0x0E;		// P3.1-3 SPI option select
	P3DIR |= 0x01;		// P3.0 output direction
	P3OUT |= 0x01;		// CS high
}



unsigned int SST25VF_OutDAC( int nValue )
{	unsigned int nResult;

	P2OUT &= ~0x80;		  //SYNC LOW FOR DAC
	SST25VF_ExecuteSPI( nValue>>8 );
	SST25VF_ExecuteSPI( nValue & 0xFF );
	P2OUT |= 0x80;          //SYNC LOW FOR DAC

	return nResult;		
}

unsigned int SST25VF_ExecuteSPI( unsigned int nArg )
{	unsigned int nResult;

	while ((IFG1 & UTXIFG0) == 0);		// USART0 TX buffer ready?

    IFG1 &= ~URXIFG0;					// Clear Rx flag

	// Exchange byte
	TXBUF0 = nArg & 0xFF;
	while ((IFG1 & UTXIFG0) == 0);
	while ((IFG1 & URXIFG0) == 0);
	nResult = RXBUF0;
	
	return nResult;			
}