USCI_B0 in SPI mode

142 views
Skip to first unread message

Kazzz

unread,
Nov 12, 2012, 5:59:23 PM11/12/12
to ti-lau...@googlegroups.com
I am trying to use USCI_B0in SPI mode but when I probe the MOSI line with a scope I do not see anything. I can see that what I am sending is in the TX buffer in the watch window. My code is below, any help would be very welcomed.

Thanks
Kas

int initSPI(void)
{
P1SEL = BIT5 + BIT6 + BIT7; // Configure SPI on USCI0 port B
P1SEL2 = BIT5 + BIT6 + BIT7; // Configure SPI on USCI0 port B
UCB0CTL1 |= UCSWRST; // Disable USCI
UCB0CTL0 |= UCCKPH + UCMSB + UCMST + UCSYNC;   // 3-pin, 8-bit SPI master
UCB0CTL1 |= UCSSEL_2  + UCSWRST;           // SMCLK
UCB0BR0 |= 0x02;                           // /2
UCB0BR1 = 0;                               //
UCA0MCTL = 0;                             // No modulation
UCB0CTL1 &= ~UCSWRST; //LOOK here for issues                     // Initialise USCI state machine
IE2 |= UCB0RXIE;                           // Enable USCI0 RX interrupt
P1DIR |= 0x08; // Set as CS for SPI
P1OUT |= 0x08; // Set high to deselect IC
return 0;
}



void spiWrite(unsigned char wrAddr, unsigned char wrData)
{
P1OUT &= ~0x08; // Set CS;
// Set the TX buffer for each byte, then go to LPM0 while waiting for the TX to complete
UCB0TXBUF = WRITEINST;
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
UCB0TXBUF = wrAddr;
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
UCB0TXBUF = wrData;
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/interrupt
P1OUT |= 0x08; // release CS
return;
}

Тимур Яблоновский

unread,
Jan 20, 2013, 5:21:48 AM1/20/13
to ti-lau...@googlegroups.com
Hi. its wrong code. just use no interrupts:
1) remove
IE2 |= UCB0RXIE;
2) use code like (pooling method):
void spiWrite(unsigned char wrAddr, unsigned char wrData)
{
P1OUT &= ~0x08; // Set CS;
     while (!(IFG2 & UCB0TXIFG) || (UCB0STAT & UCBUSY)); // USCI_B0 TX buffer and SPI B0 ready?
UCB0TXBUF = WRITEINST;
     while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready? 
UCB0TXBUF = wrAddr;
     while (!(IFG2 & UCB0TXIFG));  // USCI_B0 TX buffer ready?
  UCB0TXBUF = wrData;
    // while (UCB0STAT & UCBUSY); // if need
Reply all
Reply to author
Forward
0 new messages