This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

cc430F5xx USCI SPI Interrupt Vector

Hello,

I try to understand USCI spi for 5xx series. I wrote a code model TI's example codes. This code's aim is only sending always 0x55 from its MOSI pin. There is no data coming to RX pin. But when i debugged the code there is a problem which i couldn't understand.  I realized, after send 0x55 from MOSI (putting 0x55 to UCA0TXBUF register),    UCRXIFG is set and program branchs to interrupt vector with UCA0IV=2. And then every time after putting some value UCATXBUF register, UCRXIF is set and branching to int. vector. How can it can be, because there is no data at MISO pin so there is no receiving data.

The code is below,

#include "msp430.h"

unsigned char MST_Data;

void main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer

  PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs  
  P1MAP5 = PM_UCA0SIMO;                     // Map UCA0SIMO output to P2.0
  P1MAP6 = PM_UCA0SOMI;                     // Map UCA0SOMI output to P2.2
  P1MAP7 = PM_UCA0CLK;                      // Map UCA0CLK output to P2.4
  PMAPPWD = 0;                              // Lock port mapping registers  
   

  P1DIR |= BIT5 + BIT6 + BIT7;                       // ACLK, MCLK, SMCLK set out to pins
  P1SEL |= BIT5 + BIT6 + BIT7;                       // P2.0,2,4 for debugging purposes.

  UCA0CTL1 |= UCSWRST;                              // **Put state machine in reset**
  UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;    // 3-pin, 8-bit SPI master
                                                                                     // Clock polarity high, MSB
  UCA0CTL1 |= UCSSEL_2;                          // SMCLK
  UCA0BR0 = 0x02;                                      // /2
  UCA0BR1 = 0;                                           //
  UCA0MCTL = 0;                                      // No modulation
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

  __delay_cycles(100);                      // Wait for slave to initialize

  MST_Data = 0x01;                          // Initialize data values


  while (!(UCA0IFG&UCTXIFG));                             // USCI_A0 TX buffer ready?
  UCA0TXBUF = 0x55;__delay_cycles(100);               // Transmit first character

  __bis_SR_register(LPM0_bits + GIE);                   // CPU off, enable interrupts
}

#pragma vector=USCI_A0_VECTOR
__interrupt void USCI_A0_ISR(void)
{
  switch(__even_in_range(UCA0IV,4))
  {
    case 0: break;                                        // Vector 0 - no interrupt
    case 2:                                                   // Vector 2 - RXIFG
      while (!(UCA0IFG&UCTXIFG));           // USCI_A0 TX buffer ready?
      UCA0TXBUF = MST_Data;                 // Send next value

      __delay_cycles(40);                             // Add time between transmissions to
                                                                  // make sure slave can process information
      break;
    case 4: break;                                       // Vector 4 - TXIFG
    default: break;
  }
}

  • Snow said:
    And then every time after putting some value UCATXBUF register, UCRXIF is set and branching to int. vector. How can it can be, because there is no data at MISO pin so there is no receiving data.

    That is because in SPI mode receive and transmit operations operate concurrently. From the MSP430x5xx and MSP430x6xx Family User's Guide SLAU208K:

    Figure 35-2 shows the USCI as a master in both 3-pin and 4-pin configurations. The USCI initiates data
    transfer when data is moved to the transmit data buffer UCxTXBUF. The UCxTXBUF data is moved to the
    transmit (TX) shift register when the TX shift register is empty, initiating data transfer on UCxSIMO starting
    with either the MSB or LSB, depending on the UCMSB setting. Data on UCxSOMI is shifted into the
    receive shift register on the opposite clock edge. When the character is received, the receive data is
    moved from the receive (RX) shift register to the received data buffer UCxRXBUF and the receive
    interrupt flag UCRXIFG is set, indicating the RX/TX operation is complete.

    A set transmit interrupt flag, UCTXIFG, indicates that data has moved from UCxTXBUF to the TX shift
    register and UCxTXBUF is ready for new data. It does not indicate RX/TX completion.

    To receive data into the USCI in master mode, data must be written to UCxTXBUF, because receive and
    transmit operations operate concurrently.

     

  • Yes, i have read and noticed you are right. Thx for your interest:)

**Attention** This is a public forum