Subversion Repositories Code-Repo

Rev

Rev 248 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 248 Rev 251
Line 191... Line 191...
191
 
191
 
192
#elif SPI_SER_INTF == SER_INTF_USCIB0
192
#elif SPI_SER_INTF == SER_INTF_USCIB0
193
 
193
 
194
void halSPISetup(void)
194
void halSPISetup(void)
195
{
195
{
196
    UCB0CTL0 = UCCKPL+UCMSB+UCMST+UCMODE_0;		// 3-pin, 8-bit SPI master
196
    UCB0CTL0 = UCMSB+UCMST+UCMODE_0;			// 3-pin, 8-bit SPI master
-
 
197
    halSPISetPolarityPhase(0, 0);
197
    UCB0CTL1 = UCSSEL_2+UCSWRST;				// SMCLK
198
    UCB0CTL1 = UCSSEL_2+UCSWRST;				// SMCLK
198
    halSPISetSpeedLow();
199
    halSPISetSpeedLow();
199
    //UCB0MCTL = 0;
200
    //UCB0MCTL = 0;
200
    SPI_PxSEL |= SPI_UCLK+SPI_SOMI+SPI_SIMO;
201
    SPI_PxSEL |= SPI_UCLK+SPI_SOMI+SPI_SIMO;
201
    SPI_PxSEL2 |= SPI_UCLK+SPI_SOMI+SPI_SIMO;
202
	SPI_PxSEL2 |= SPI_UCLK+SPI_SOMI+SPI_SIMO;
202
    SPI_PxOUT |= SPI_SIMO + SPI_SOMI + SPI_UCLK;
-
 
203
//    SPI_PxOUT &= ~SPI_UCLK;
-
 
204
    SPI_PxDIR |= SPI_SIMO + SPI_UCLK;
-
 
205
    SPI_PxDIR &= ~SPI_SOMI;
-
 
206
    UCB0CTL1 &= ~UCSWRST;						// **Initialize USCI state machine**
203
    UCB0CTL1 &= ~UCSWRST;						// **Initialize USCI state machine**
207
}
204
}
208
 
205
 
209
void halSPISetSpeedHigh(void) {
206
void halSPISetSpeedHigh(void) {
210
    UCB0BR0 = 4;    // CLK_FREQ = BRCLK / 4
207
    UCB0BR0 = 4;    // CLK_FREQ = BRCLK / 4
Line 214... Line 211...
214
void halSPISetSpeedLow(void) {
211
void halSPISetSpeedLow(void) {
215
    UCB0BR0 = 32;   // CLK_FREQ = BRCLK / 32
212
    UCB0BR0 = 32;   // CLK_FREQ = BRCLK / 32
216
    UCB0BR1 = 0;
213
    UCB0BR1 = 0;
217
}
214
}
218
 
215
 
-
 
216
void halSPISetPolarityPhase(char polarity, char phase) {
-
 
217
	// Polarity 0 = inactive low, Polarity 1 = inactive high
-
 
218
	// Phase 0 = Capture on first edge, change on following edge
-
 
219
	// Phase 1 = Change on first edge, capture on following edge
-
 
220
	// Note: Phase is inverted on MSP430!
-
 
221
	UCB0CTL0 &= ~(UCCKPH + UCCKPL);
-
 
222
	if (polarity == 0 && phase == 0) {
-
 
223
		UCB0CTL0 |= UCCKPH;
-
 
224
	} else if (polarity == 1 && phase == 0) {
-
 
225
		UCB0CTL0 |= UCCKPH + UCCKPL;
-
 
226
	} else if (polarity == 1 && phase == 1) {
-
 
227
		UCB0CTL0 |= UCCKPL;
-
 
228
	}
-
 
229
}
-
 
230
 
219
#elif SPI_SER_INTF == SER_INTF_USCIB1
231
#elif SPI_SER_INTF == SER_INTF_USCIB1
220
 
232
 
221
void halSPISetup(void)
233
void halSPISetup(void)
222
{
234
{
223
    UCB1CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC;     // 3-pin, 8-bit SPI master
235
    UCB1CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC;     // 3-pin, 8-bit SPI master