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.

[参考译文] MSP430G2553:SPI 接收

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1370033/msp430g2553-spi-receive

器件型号:MSP430G2553
主题中讨论的其他器件:MSP430G2533

工具与软件:

大家好、我正尝试通过 SPI 将一个十六进制值从 MSP430G2533 (我们称之为 MSP430发送器)发送到另一个 MSP430G2533 (我们称之为 MSP430接收器)。

我能够在调试器视图中发送和查看 MSP430发送器上 TX 缓冲区上的十六进制值。 但是、我的 MSP430接收器无法获得缓冲器。 以下是我的代码


SPI 接收代码:

#include <msp430.h>

void setupSPI_Slave() {
    // Set UCSWRST (USCI Software Reset)
    UCB0CTL1 = UCSWRST;
    // Set USCI_B0 to slave mode, 3-pin SPI, synchronous mode
    UCB0CTL0 = UCSYNC + UCCKPL + UCMSB;
    // Clear UCSWRST to release USCI_B0 for operation
    UCB0CTL1 &= ~UCSWRST;
    // Enable USCI_B0 RX interrupt
    IE2 |= UCB0RXIE;
}

int main(void) {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1SEL |= BIT5 + BIT6 + BIT7; // Set P1.5, P1.6, P1.7 as SPI pins
    P1SEL2 |= BIT5 + BIT6 + BIT7;

    setupSPI_Slave();

    __bis_SR_register(GIE); // Enable global interrupts

    while (1) {
        __bis_SR_register(LPM0_bits + GIE);
    }
}

// USCI_B0 Data ISR
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void) {
    if (IFG2 & UCB0RXIFG) {
        unsigned char receivedData = UCB0RXBUF; // Read received data
        // Do something with the received data
        __bic_SR_register_on_exit(LPM0_bits); // Exit low-power mode
    }
}

SPI 传输代码:

#include <msp430.h>

void setupSPI_Master() {
    // Set UCSWRST (USCI Software Reset)
    UCB0CTL1 = UCSWRST;
    // Set USCI_B0 to master mode, 3-pin SPI, synchronous mode
    UCB0CTL0 = UCMST + UCSYNC + UCCKPL + UCMSB;
    // SMCLK as clock source
    UCB0CTL1 |= UCSSEL_2;
    // Set baud rate (UCB0BR0 and UCB0BR1)
    UCB0BR0 = 0x02;
    UCB0BR1 = 0;
    // Clear UCSWRST to release USCI_B0 for operation
    UCB0CTL1 &= ~UCSWRST;
    // Enable USCI_B0 RX interrupt
    IE2 |= UCB0RXIE;
}

void sendSPI_Master(unsigned char data) {
    while (!(IFG2 & UCB0TXIFG)); // Wait for TX buffer to be ready
    UCB0TXBUF = data;            // Send data
}

int main(void) {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1SEL |= BIT5 + BIT6 + BIT7; // Set P1.5, P1.6, P1.7 as SPI pins
    P1SEL2 |= BIT5 + BIT6 + BIT7;
    P1DIR |= BIT4; // Set P1.4 as output (CS pin)
    P1OUT |= BIT4; // Set P1.4 high (CS idle high)

    setupSPI_Master();

    while (1) {
        P1OUT &= ~BIT4; // Pull CS low to start communication
        sendSPI_Master(0xFF);
        P1OUT |= BIT4; // Set CS high to end communication
        __delay_cycles(1000); // Delay between transmissions
    }
}

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

    您好!

    您是否曾捕获过波形以便成功看到发射数据?

    佐伊

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

    只是看看评论,我看到一个断开. 在发送侧、您置位 CS 信号、但接收侧设置为3引脚模式、因此始终启用。 它需要处于4引脚模式、以便 STE 输入可以处理该 CS 信号。 哦、同时包含1和0的测试值比0xff 好得多。

    另一个需要检查的是两个器件之间的连接。 确保接收引脚(SIMO)确实已连接到发送引脚。 (也称为 SIMO)