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.

MSP430FR5739 SPI的问题

UCTXIFG is automatically
reset if a character is written to UCxTXBUF.

就是说向发送寄存器送字节后,UCXIFG会自动清零.

为什么我第一次写入后,没有自动清零呢?还是1.

用的LAUNCHPAD仿真看到的...

UCA0CTLW0 |= UCSWRST;                     // **Put state machine in reset**
  UCA0CTLW0 |= UCMST+UCSYNC+UCCKPL+UCMSB+UCSSEL_3;   // 3-pin, 8-bit SPI master Clock polarity high, MSB , SMCLK=DCO
  UCA0BR0 = 0x02;                           // /2  baud
  UCA0BR1 = 0;                              //
  UCA0MCTLW = 0;                            // No modulation
  UCA0STATW|=UCLISTEN;                         //Receive the transmitted;
  UCA0CTLW0 &= ~UCSWRST;                    // **Initialize USCI state machine**
  //UCA0IE |= UCTXIE;                         // Enable USCI_A0 TX interrupt   We will use  no interruption.

 P1SEL1 |= BIT5;
  P2SEL1 |= BIT0 + BIT1;

void spiw(unsigned char word)
{
  while((UCA0IFG&UCTXIFG)==0);
  UCA0TXBUF=word;
};

执行到这,写入第一个...但UCTIFG没有自动请0..

  • UCB0CTLW0 |= UCSWRST; // **Put state machine in reset**
    UCB0CTLW0 &= ~UCCKPH;
    UCB0CTLW0 |= UCMST+UCSYNC+UCMSB; // 3-pin, 8-bit SPI master // Clock polarity high, MSB
    UCB0CTLW0 |= UCSSEL_2; // SMCLK
    UCB0BR0 = 0x08; // /2
    UCB0BR1 = 0; //
    UCB0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**

    UCB0IFG &= ~(UCRXIFG+UCTXIFG);
    for(i=0;i<ucByteCnt;i++)
    {
    UCB0TXBUF =ucData[i];
    while (!(UCB0IFG&UCTXIFG)); // USCI_B0 TX buffer ready?

    while (!(UCB0IFG&UCRXIFG)); // USCI_B0 TX buffer ready?
    ucData[i]=UCB0RXBUF;
    }

    请参考已经能够使用的代码

  • 33.3.8.1 SPI Transmit Interrupt Operation

    The UCTXIFG interrupt flag is set by the transmitter to indicate that UCxTXBUF is ready to accept another character. An interrupt request is generated if UCTXIE and GIE are also set. UCTXIFG is automatically reset if a character is written to UCxTXBUF.

    UCTXIFG is set after a PUC or when UCSWRST = 1. UCTXIE is reset after a PUC or when UCSWRST = 1.

    所以要记得清零操作,也就是UCB0IFG &= ~(UCRXIFG+UCTXIFG);

  • 还是不可以啊...BUF寄存器根本没移位...,

  • 可是说明书上说一个字节被写入后,标志可以自动被清零啊..