Hi,
Im trying to use UCB1 as SPI, however it doesnt work. Therefore I removed my peripheral and connected SI and SO pins together. Unfortunately I only get 0xFF in UCRXBUF.
Any idea what could be wrong? Here is the code:
#include <msp430.h>
unsigned char MST_Data,SLV_Data;
unsigned char temp;
int main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P1OUT |= BIT2; // Set P1.2 for LED
P1DIR |= BIT2; // Set P1.2 to output direction
P4SEL |= BIT2+BIT3; // Initialize SPI pins
P4SEL |= BIT1; //
UCB1CTL1 |= UCSWRST; // **Put state machine in reset**
UCB1CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCB1CTL1 |= UCSSEL_2; // SMCLK
UCB1BR0 = 0x02; // /2
UCB1BR1 = 0; //
//UCB1MCTL = 0; // No modulation
UCB1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCB1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
for(i=50;i>0;i--); // Wait for slave to initialize
MST_Data = 0x01; // Initialize data values
SLV_Data = 0x00; //
while (!(UCB1IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCB1TXBUF = MST_Data; // Transmit first character
__bis_SR_register(LPM0_bits + GIE); // CPU off, enable interrupts
}
#pragma vector=USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void)
{
volatile unsigned int i;
switch(__even_in_range(UCB1IV,4))
{
case 0: break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCB1IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
if (UCB1RXBUF==SLV_Data) // Test for correct character RX'd
P1OUT |= BIT2; // If correct, light LED
else
P1OUT &= ~BIT2; // If incorrect, clear LED
MST_Data++; // Increment data
SLV_Data++;
UCB1TXBUF = MST_Data; // Send next value
for(i = 20; i>0; i--); // Add time between transmissions to
// make sure slave can process information
break;
case 4: break; // Vector 4 - TXIFG
default: break;
}
}