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.

[参考译文] MSP430FR6047:SPI 配置

Guru**** 2502205 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1559160/msp430fr6047-spi-configuration

器件型号:MSP430FR6047


工具/软件:

您好!  

我正在努力为 UCA3 端口的引脚 79 到 82 配置 SPI 端口:

这是用于数据初始化和传输的代码。 我还没有看到任何数据通过 SPI 线路传递、这是使用 o 示波器测得的。 如果我是否正确配置、正在查找上的输入。   

#define SPI_MOSI_PIN  BIT3      // SPI transmit pin, P8.3
#define SPI_MISO_PIN  BIT2      // SPI receive pin,  P8.2
#define SPI_CLK_PIN   BIT1      // SPI CLK pin, P8.1
#define SPI_CS_PIN    BIT0        // P8.0

/**
 * Initialize SPI communication
 */
void spi_init(void) {
    
    // Initialize hardware UART pins
    P8SEL0 |= SPI_MISO_PIN | SPI_MOSI_PIN | SPI_CLK_PIN;      // Select SPI function
    P8SEL1 &= ~SPI_MOSI_PIN & ~SPI_MISO_PIN & ~SPI_CLK_PIN;  // Correct Port 2
 
    // Configure USCI_A0 for UART mode, 8-bit data, 1 stop bit
    UCA3CTLW0 = UCSWRST;                    // Put eUSCI in reset
    UCA3CTLW0 |= UCMST | UCSYNC | UCCKPH | UCMSB;  // Master, synchronous, 3-pin SPI, MSB first
    UCA3CTLW0 |= UCSSEL__SMCLK;             // CLK = SMCLK

     // Configure eUSCI_A SPI module
    UCA3CTLW0 = UCSWRST | UCSSEL__ACLK | UCMST | UCSYNC;  // Reset eUSCI
                                                           // Set SMCLK as BRCLK source
                                                           // Select master mode
                                                           // Enable Synchronous mode

    UCA3BRW = 0x0002;               // Bit rate clock = SMCLK/2 = 8 MHz

    // // Enable SPI TX interrupt
    UCA3IE |= UCTXIE;               // Enable TX interrupt
    //enable_interrupts();
}

uint8_t spi_transfer(uint8_t data) {
    // Wait for TX buffer to be ready
    UART_transmitString("INSIDE INSIDE 1\r\n");
    while (!(UCA3IFG & UCTXIFG));
    UART_transmitString("INSIDE INSIDE 2\r\n");
    UCA3TXBUF = data;               // Send data
    
    // Wait for transfer to complete (RX buffer full)
    while (!(UCA3IFG & UCRXIFG));
    UART_transmitString("INSIDE INSIDE 3\r\n");
    return UCA3RXBUF;               // Return received data
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    1) 这一行:

    > UCA3CTLW0 = UCSWRST | UCSSEL_ACLK | UCMST | UCSYNC;//重置 eUSCI

    覆盖您在上一序列中执行的操作。 我建议删除这一行(其他位看起来更好)。

    2) 您似乎不会使 eUSCI 退出复位。 (这可能是您看到症状的原因。) 加法:

    UCA3CTLW0 &=~ UCSWRST; //退出复位

    3) 这一行:

    > UCA3IE |= UCTXIE;//启用 TX 中断

    启用 TXIFG、但不会使用它。 由于没有(可见)ISR、因此程序将跳转到全面 ISR。 您应该删除这一行。