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**** 2387080 points
Other Parts Discussed in Thread: EVM430-FR6047
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1233897/msp430fr6047-spi-communication-not-working

器件型号:MSP430FR6047
主题中讨论的其他器件: EVM430-FR6047

您好!

使用8MHz HFX 振荡器和32.168KHz LFx 振荡器

具有以下引脚且使用 USCI_A2

我正在使用的同一代码是、

#包含

Volatile unsigned char RXData = 0;
Volatile unsigned char TXData;

int main (空)
{
   WDTCTL = WDTPW | WDTHOLD;              //停止看门狗计时器

   //配置 GPIO
   P5SEL1 &=~(BIT2 | BIT0 | BIT1 | BIT3);       // USCI_A2 SCLK、MOSI、MISO、CS 引脚
   P5SEL0 |= BIT2 | BIT0 | BIT1 | BIT3;

   PJSEL0 |= BIT4 | BIT5;                 //表示 XT1

   //禁用 GPIO 上电默认高阻抗模式以激活
   //先前配置的端口设置
   PM5CTL0 &=~μ A LOCKLPM5;

   // XT1设置
   CSCTL0_H = CSKEY_H;                    //解锁 CS 寄存器
   CSCTL1 = DCOFSEL_0;                    //将 DCO 设置为1MHz
   CSCTL1 &=~μ V DCORSEL;
   CSCTL2 = SELM__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
   CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;  //设置所有分频器
   CSCTL4 &=~LFXTOFF;
   正确
   {
       CSCTL5 &=~LFXTOFFG;               //清除 XT1故障标志
       SFRIFG1 &=~OFIFG;
   }while (SFRIFG1和 OFIFG);             //测试振荡器故障标志
   CSCTL0_H = 0;                          //锁定 CS 寄存器

   //针对 SPI 操作配置 USCI_A2
   UCA2CTLW0 = UCSWRST;                   //**将状态机置于复位状态**
                                           // 4引脚8位 SPI 主设备
   UCA2CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB | UCMODE_1 | UCSTEM;
                                           //时钟极性高,MSB
   UCA2CTLW0 |= UCSSEL_ACLK;             // ACLK
   UCA2BRW = 0x02;                        ///2
   UCA2MCTLW = 0;                         //无调制
   UCA2CTLW0 &&~UCSWRST;                 //**初始化 USCI 状态机**
   TXData = 0x1;                          //保存 TX 数据

   while (1)
   {
       UCA2IE |= UCTXIE;
       __ bis_SR_register (LPM0_bits | GIE);//输入 LPM0、启用中断
       __ no_operation ();                  //保持在 LPM0中
       __delay_cycles (2000);              //下一次传输之前的延迟
       TXData++;                          //递增发送数据
   }

在这段代码下、SPI 不传输任何数据。 有人能请热心帮忙解决这个问题吗? 代码是否正确..?

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

    我看不出您将数据放入 TX 缓冲区的位置。 USCI 应该如何知道发送什么?  

    您需要类似的东西:

    UCAxTXBUF = TXData;

    其中 X 是 USCI 的编号。

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

    我也添加了这一行(UCAxTXBUF = TXData;)。

    我的配置是主器件的正确配置吗?

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

    您是否尝试过其中一个示例?

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

    你... 也尝试使用以下示例... 它取自 driverlib... 这里是 USCI_A1,我更改了 USCI_A2

    #包含

    Volatile unsigned char RXData = 0;
    Volatile unsigned char TXData;

    int main (空)
    {
       WDTCTL = WDTPW | WDTHOLD;              //停止看门狗计时器

       //配置 GPIO
       P5SEL1 &=~BIT0 |~BIT1 |~BIT2 |~BIT3;       // USCI_A1 SCLK、MOSI、MISO 引脚
       P5SEL0 |= BIT0 | BIT1 | BIT2 | BIT3;

       PJSEL0 |= BIT4 | BIT5;                 //表示 XT1

       //禁用 GPIO 上电默认高阻抗模式以激活
       //先前配置的端口设置
       PM5CTL0 &=~μ A LOCKLPM5;

       // XT1设置
       CSCTL0_H = CSKEY_H;                    //解锁 CS 寄存器
       CSCTL1 = DCOFSEL_0;                    //将 DCO 设置为1MHz
       CSCTL1 &=~μ V DCORSEL;
       CSCTL2 = SELM__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
       CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;  //设置所有分频器
       CSCTL4 &=~LFXTOFF;
       正确
       {
           CSCTL5 &=~LFXTOFFG;               //清除 XT1故障标志
           SFRIFG1 &=~OFIFG;
       }while (SFRIFG1和 OFIFG);             //测试振荡器故障标志
       CSCTL0_H = 0;                          //锁定 CS 寄存器

       //针对 SPI 操作配置 USCI_A2
       UCA2CTLW0 = UCSWRST;                   //**将状态机置于复位状态**
                                               // 4引脚8位 SPI 主设备
       UCA2CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB | UCMODE_1 | UCSTEM;
                                               //时钟极性高,MSB
       UCA2CTLW0 |= UCSSEL_ACLK;             // ACLK
       UCA2BRW = 0x02;                        ///2
       UCA2MCTLW = 0;                         //无调制
       UCA2CTLW0 &&~UCSWRST;                 //**初始化 USCI 状态机**
       UCA2IE |= UCRXIE;                      //启用 USCI_A2 RX 中断
       TXData = 0x1;                          //保存 TX 数据

       while (1)
       {
           UCA2IE |= UCTXIE;
           __ bis_SR_register (LPM0_bits | GIE);//输入 LPM0、启用中断
           __ no_operation ();                  //保持在 LPM0中
           __delay_cycles (2000);              //下一次传输之前的延迟
           TXData++;                          //递增发送数据
       }


    #if defined (__TI_Compiler_version__)|| defined (__IAR_SYSTEMS_ICC__)
    #pragma vector=EUSCI_A2_vector
    __interrupt void USCI_A2_ISR (void)
    #Elif 已定义(_ GNU _)
    void __attribute__((interrupt (EUSCI_A2_vector)) USCI_A2_ISR (void)
    #else
    #错误编译器不受支持!
    #endif
    {
       switch (__even_in_range (UCA2IV、USCI_SPI_UCTXIFG))
       {
           USCI_NONE:中止;
           案例 USCI_SPI_UCRXIFG:
               RXData = UCA2RXBUF;
               UCA2IFG &=~UCRXIFG;

               //唤醒以设置下一个 TX
               __ bic_SR_register_on_exit (LPM0_bits);
               中断;
           案例 USCI_SPI_UCTXIFG:
               UCA2TXBUF = TXData;            //发送字符
               UCA2IE &=~UCTXIE;
               中断;
           默认值:中断;
       }

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

    这对我来说在 MSP432P401R 非常好、您可能需要修改一些时钟值:

    /*
     * Program to create a basic Arduino "millis" facility as well as serial string capability
     *
     * Ports used:
     * Port J: Pins 2 &3 - Crystal
     * Port 1: Pins 2&3 Back Channel UART
    
     */
    /* DriverLib Includes */
    #include <ti/devices/msp432p4xx/driverlib/driverlib.h>
    
    /* Standard Includes */
    #include <stdint.h>
    #include <stdbool.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <limits.h>
    #include <float.h>
    
    
    /* UART Configuration Parameter. These are the configuration parameters to
     * make the eUSCI A UART module to operate with a 115200 baud rate. These
     * values were calculated using the online calculator that TI provides
     * at:
     * software-dl.ti.com/.../index.html
     */
    
    #define BAUDRATE (9600)
    
    const eUSCI_SPI_MasterConfig spiMasterConfig =
    {
     EUSCI_B_SPI_CLOCKSOURCE_SMCLK,             // SMCLK Clock Source
     24000000,                                   // SMCLK = 24 MHz
     500000,                                    // SPICLK = 500khz
     EUSCI_B_SPI_MSB_FIRST,                     // MSB First
     EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT,    // Phase
     EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH, // High polarity
     EUSCI_B_SPI_3PIN                           // 3Wire SPI Mode
    };
    
    
    const eUSCI_UART_ConfigV1 uartConfig0 =
    {
     EUSCI_A_UART_CLOCKSOURCE_SMCLK,          // SMCLK Clock Source
     156,                                      // BRDIV =
     4,                                       // UCxBRF =
     0,                                      // UCxBRS =
     EUSCI_A_UART_NO_PARITY,                  // No Parity
     EUSCI_A_UART_LSB_FIRST,                  // LSB First
     EUSCI_A_UART_ONE_STOP_BIT,               // One stop bit
     EUSCI_A_UART_MODE,                       // UART mode
     EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION  // Oversampling
    };
    
    
    /* Other Rates
     *  9600
     *  BRDIV: 156
     *  UCXBRF: 4
     *  UCXBRS: 0
     *  Oversample: 1
     *
     *  38400
     *  BRDIV: 39
     *  UCXBRF: 1
     *  UCXBRS: 0
     *  Oversample: 1
     *
     *  115200
     *  BRDIV: 13
     *  UCXBRF: 1
     *  UCXBRS: 37
     *  Oversample: 1
     *
     *  460800
     *  BRDIV: 3
     *  UCXBRF: 4
     *  UCXBRS: 0
     *  Oversample: 1
     *
     */
    
    /* Function Prototypes */
    void Delay(int msec);
    void DelayChars(int chars);
    
    int serialAvailable();
    char getSerialChar();
    void writeSerialChar(char c);
    void writeSerialString(char *s);
    
    volatile unsigned int Millis = 0;
    
    #define SER_RX_BUFSIZE (128)
    #define SER_TX_BUFSIZE (128)
    
    volatile int serTxWriteIdx = 0; // Where to put the byte we want to send
    volatile int serTxReadIdx = 0;  // where to get the byte we want to send
    volatile int serTxChars = 0;
    volatile char TXData[SER_TX_BUFSIZE];
    
    volatile int serRxWriteIdx = 0; // Where to save the received byte
    volatile int serRxReadIdx = 0;  // Where to read the received byte
    volatile int serRxChars = 0;
    volatile char RXData[SER_RX_BUFSIZE];
    
    volatile bool Interrupt_Flag = false;
    char OneCharString[2];
    
    volatile int idelay;
    uint8_t RXData0, RXData1, RXData2, RXData10, RXData11, RXData12, RXData20, RXData21, RXData22;
    
    int main(void)
    {
    
        char CommandBuf[32];
        char buf[32];
        char c;
        size_t len;
    
        /* Halting the Watchdog */
        MAP_WDT_A_holdTimer();
    
        OneCharString[1] = '\0';
    
        // Configure SysTick
        MAP_SysTick_enableModule();
        // 48M = 1 sec, 4.8M = 100ms, 480000 = 10ms...
        MAP_SysTick_setPeriod(48000); // Every 1 msec
        MAP_SysTick_enableInterrupt();
    
        //![Simple CS Config]
        /* Configuring pins for peripheral/crystal usage and LED for output */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_PJ,
                                                        GPIO_PIN3 | GPIO_PIN2, GPIO_PRIMARY_MODULE_FUNCTION);
    
        MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                                                       GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION); // UART0
    
        /* Just in case the user wants to use the getACLK, getMCLK, etc. functions,
         * let's set the clock frequency in the code. 
         */
        CS_setExternalClockSourceFrequency(32000,48000000);
    
        /* Starting HFXT in non-bypass mode without a timeout. Before we start
         * we have to change VCORE to 1 to support the 48MHz frequency */
        MAP_PCM_setCoreVoltageLevel(PCM_VCORE1);
        MAP_FlashCtl_setWaitState(FLASH_BANK0, 1);
        MAP_FlashCtl_setWaitState(FLASH_BANK1, 1);
        CS_startHFXT(false);
    
        /* Initializing MCLK to HFXT (effectively 48MHz) */
        MAP_CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
        // The UART is limited to 24 MHz...
        MAP_CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_2);
    
        // GPIO's
        MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); // Main Red LED
        MAP_GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);
    
        GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN4); // SPI CS
        GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
    
        //![Simple SPI Example]
        /* Selecting P1.5 P1.6 and P1.7 in SPI mode */
        GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
                                                   GPIO_PIN5 | GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    
    
        serTxWriteIdx = 0;
        serTxReadIdx = 0;
    
        serRxWriteIdx = 0;
        serRxReadIdx = 0;
    
        /* Configuring UART Module */
        MAP_UART_initModule(EUSCI_A0_BASE, &uartConfig0);
    
        /* Enable UART module */
        MAP_UART_enableModule(EUSCI_A0_BASE);
    
        /* Enabling interrupts */
        MAP_UART_enableInterrupt(EUSCI_A0_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT|EUSCI_A_UART_TRANSMIT_INTERRUPT);
        MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
    
        /* Configuring SPI in 3wire master mode */
        SPI_initMaster(EUSCI_B0_BASE, &spiMasterConfig);
    
        /* Enable SPI module */
        SPI_enableModule(EUSCI_B0_BASE);
    
        /* Enabling MASTER interrupts */
        MAP_Interrupt_enableMaster();
    
        CommandBuf[0] = '\0';
    
        writeSerialString("\n\rHello, World!\n\r");
    
    
        while (1)
        {
            if (serialAvailable())
            {
                c = getSerialChar();
    
                writeSerialChar(c);
    
                if (c == '\r')
                {
                    writeSerialChar('\n');
    
                    strcpy(buf, "Command: ");
                    strcat(buf, CommandBuf);
                    strcat(buf, "\n\r");
    
                    writeSerialString(buf);
    
                    CommandBuf[0] = '\0';
    
                }
                else
                {
                    len = strlen(CommandBuf);
                    CommandBuf[len] = c;
                    CommandBuf[len+1] = '\0';
    
                }
    
    
            }
    
    
            GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
            /* Transmitting data to slave */
    
            // Get Config
            SPI_transmitData(EUSCI_B0_BASE, 0b00111000);
    
            while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
            while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
            RXData0 = SPI_receiveData(EUSCI_B0_BASE);
    
    		// Toggle CS
            GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
            //__delay_cycles(4);
            GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
    		// Get Config
            SPI_transmitData(EUSCI_B0_BASE, );
    
            while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
            while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
            RXData1 = SPI_receiveData(EUSCI_B0_BASE);
    
            GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
            //__delay_cycles(4);
            GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
            SPI_transmitData(EUSCI_B0_BASE, 0x00);
    
            while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
            while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
            RXData2 = SPI_receiveData(EUSCI_B0_BASE);
    
            GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
    
    
            for (idelay = 0; idelay < 1000; idelay++)
            {
                // delay
            }
    
    		// Get Status 1
    		SPI_transmitData(EUSCI_B0_BASE, 0b00111001);
    
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
    		RXData10 = SPI_receiveData(EUSCI_B0_BASE);
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    		//__delay_cycles(4);
    		GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
    		SPI_transmitData(EUSCI_B0_BASE, 0x00);
    
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
    		RXData11 = SPI_receiveData(EUSCI_B0_BASE);
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
    		//__delay_cycles(4);
    
    		GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
    		SPI_transmitData(EUSCI_B0_BASE, 0x00);
    
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
    		RXData11 = SPI_receiveData(EUSCI_B0_BASE);
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
    
    		// Get Status 2
    		SPI_transmitData(EUSCI_B0_BASE, 0b11010000);
    
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
    		RXData10 = SPI_receiveData(EUSCI_B0_BASE);
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    		//__delay_cycles(4);
    		GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
    		SPI_transmitData(EUSCI_B0_BASE, 0x00);
    
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
    		RXData11 = SPI_receiveData(EUSCI_B0_BASE);
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
    		//__delay_cycles(4);
    
    		GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN4); // Set CS
    
    		SPI_transmitData(EUSCI_B0_BASE, 0x00);
    
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_TRANSMIT_INTERRUPT)));
    		while (!(SPI_getInterruptStatus(EUSCI_B0_BASE, EUSCI_SPI_RECEIVE_INTERRUPT)));
    
    
    		RXData11 = SPI_receiveData(EUSCI_B0_BASE);
    
    		GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN4);
    
    		Delay(1000);
    
        } // while()
    }
    
    
    void SysTick_Handler(void)
    {
        Millis++;
    
        if (Millis%10000 == 0)
        {
            // Every 10 seconds
            MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
    
        }
    }
    
    void Delay(int msec) {
        // Busy wait msec ms
        int starttime = Millis;
    
        while((Millis - starttime) < msec);
    }
    
    void DelayChars(int chars)
    {
        // Delay a certain number of chars, based on the current baud rate, or 1+ ms
        int usPerChar = 1000000 / BAUDRATE;
        int delay_ms;
    
        if ((chars * usPerChar) < 2000 ) {
            delay_ms = 2;
        } else {
            delay_ms = chars * usPerChar/1000;
        }
    
        Delay(delay_ms);
    }
    
    
    void EUSCIA0_IRQHandler(void) {
        uint8_t rx;
    
        uint32_t status = MAP_UART_getEnabledInterruptStatus(EUSCI_A0_BASE);
    
        MAP_UART_clearInterruptFlag(EUSCI_A0_BASE, status);
    
        if (status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG) {
            rx = MAP_UART_receiveData(EUSCI_A0_BASE);
            // Put the data in the ring buffer
            RXData[serRxWriteIdx++] = rx;
            //Safely wrap back around to 0
            serRxWriteIdx = (serRxWriteIdx == SER_RX_BUFSIZE) ? (0) : (serRxWriteIdx);
            serRxChars++;
    
        } else if (status & EUSCI_A_UART_TRANSMIT_INTERRUPT_FLAG) {
    
            // Do we still have chars in the buffer?
            if (serTxChars != 0) {
    
                MAP_UART_transmitData(EUSCI_A0_BASE, TXData[serTxReadIdx++]);
    
                //Safely wrap back around to 0
                serTxReadIdx = (serTxReadIdx == SER_TX_BUFSIZE) ? (0) : (serTxReadIdx);
    
                serTxChars--;
            }
    
            Interrupt_Flag = true;
    
        }
    
    }
    
    
    int serialAvailable(void)
    {
        int res;
    
        MAP_Interrupt_disableInterrupt(INT_EUSCIA0);
    
        res = serRxChars;
    
        MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
    
        return res;
    }
    
    char getSerialChar(void)
    {
        char ret;
    
        MAP_Interrupt_disableInterrupt(INT_EUSCIA0);
    
        if (serRxChars != 0) {
            ret = RXData[serRxReadIdx++];
            serRxReadIdx = (serRxReadIdx == SER_RX_BUFSIZE) ? (0) : (serRxReadIdx);
            serRxChars--;
        } else {
            // since they should have used serialAvailable to check!
            ret = '.';
        }
    
        MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
    
        return ret;
    }
    
    void writeSerialChar(char c) {
    
        // Send a single character.
        // To Avoid duplication fake out a single character string
        OneCharString[0] = c;
        writeSerialString(OneCharString);
    
    }
    
    void writeSerialString(char *str) {
        // Note:
        // We cannot just use multiple writeSerialChar() calls since it tends to catch up and stall
        // the transmit
        // YOU are responsible to make sure str is '\0' terminated!!!!
        // blocks if there is too much string for the buffer
    
        // Note:
        // We cannot just use multiple writeSerialChar() calls since it tends to catch up and stall
        // the transmit
        // YOU are responsible to make sure str is '\0' terminated!!!!
        // blocks if there is too much string for the buffer
    
        int strptr = 0;
        bool startTX = false;
    
        MAP_Interrupt_disableInterrupt(INT_EUSCIA0);
    
        Interrupt_Flag = false;
    
        if (serTxChars == 0) startTX = true;
    
        size_t len = strlen(str);
    
        // Fill the buffer.
        // If there is no room, send characters until there is room...
        for (strptr = 0; strptr < len; strptr++) {
            if (serTxChars < SER_TX_BUFSIZE)
            {
                TXData[serTxWriteIdx++] = str[strptr];
                serTxWriteIdx = (serTxWriteIdx == SER_TX_BUFSIZE) ? (0) : (serTxWriteIdx);
    
                serTxChars++;
            }
    
    
        } // for
    
        // If needed, start the transmit
        if (startTX) {
            // Start the transmit
    
            MAP_UART_transmitData(EUSCI_A0_BASE, TXData[serTxReadIdx++]);
            //Safely wrap back around to 0
            serTxReadIdx = (serTxReadIdx == SER_TX_BUFSIZE) ? (0) : (serTxReadIdx);
    
            serTxChars--;
        }
    
        MAP_Interrupt_enableInterrupt(INT_EUSCIA0);
    
        // If you send only one character, wait until the interrupt fires
        if (len == 1)
        {
            while (Interrupt_Flag == false)
            {
                // Diddle, Diddle, Diddle
    
            }
    
            Interrupt_Flag = false;
        }
    }
    

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

    >  P5SEL1 &=~BIT0 |~BIT1 |~BIT2 |~BIT3;       // USCI_A1 SCLK、MOSI、MISO 引脚
    >  P5SEL0 |= BIT0 | BIT1 | BIT2 | BIT3;

    数据表(SLASEB7C)表6-31声称 UCA2是使用 PSEL=10而不是01进行配置的。 请尝试改用:

    >  P5SEL0 &=~BIT0 |~BIT1 |~BIT2 |~BIT3;       // USCI_A1 SCLK、MOSI、MISO 引脚
    >  P5SEL1 |= BIT0 | BIT1 | BIT2 | BIT3;

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

    我将尝试用它

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

    再看看这个,第一行看起来是错误的(它可能是偶然的工作)。 相反、我建议:

    >  P5SEL0 &=~(BIT0 | BIT1 | BIT2 | BIT3);       // USCI_A2 SCLK、MOSI、MISO 引脚
    >  P5SEL1 |= BIT0 | BIT1 | BIT2 | BIT3;

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

    您好... 感谢您的支持。

    通过此更新、我可能会看到一些无用数据...

    您能否确认时钟配置正确..?

    使用8MHz HFX 振荡器和32.168KHz LFx 振荡器...

    我如何检查、将 ti 配置为主器件并传输数据...

    在 Arduino 接收并通过 UART 将其传输到 PC ...

    #include <msp430.h>
    
    volatile unsigned char RXData = 0;
    unsigned char TXData;
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    
        // Configure GPIO
        P5SEL0 &= ~(BIT0 | BIT1 | BIT2 | BIT3);        // USCI_A1 SCLK, MOSI, MISO pins
        P5SEL1 |= BIT0 | BIT1 | BIT2 | BIT3;
    
        PJSEL0 |= BIT4 | BIT5;                  // For XT1
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // XT1 Setup
        CSCTL0_H = CSKEY_H;                     // Unlock CS registers
        CSCTL1 = DCOFSEL_0;                     // Set DCO to 1MHz
        CSCTL1 &= ~DCORSEL;
        CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
        CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;   // Set all dividers
        CSCTL4 &= ~LFXTOFF;
        do
        {
            CSCTL5 &= ~LFXTOFFG;                // Clear XT1 fault flag
            SFRIFG1 &= ~OFIFG;
        } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
        CSCTL0_H = 0;                           // Lock CS registers
    
        // Configure USCI_A2 for SPI operation
        UCA2CTLW0 = UCSWRST;                    // **Put state machine in reset**
                                                // 4-pin, 8-bit SPI master
        UCA2CTLW0 |= UCMST | UCSYNC | UCCKPL | UCMSB | UCMODE_1 | UCSTEM;
                                                // Clock polarity high, MSB
        UCA2CTLW0 |= UCSSEL__ACLK;              // ACLK
        UCA2BRW = 0x01;                         // /2
        UCA2MCTLW = 0;                          // No modulation
        UCA2CTLW0 &= ~UCSWRST;                  // **Initialize USCI state machine**
        TXData = 0x1;                           // Holds TX data
    
        while(1)
        {
            while (!(UCA2IFG & UCTXIFG)); // USCI_A2 TX buffer ready?
            UCA2TXBUF = TXData;
            __no_operation();                   // Remain in LPM0
            TXData++;                           // Increment transmit data
        }
    }

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

    您是否使用示波器检查了 SPI 输出?

    SPI 具有时钟和数据、因此更易于传输数据。 (理论上!)

    TI 和 Arduino 是否同意"模式"? 如果 MSP 在 Arduino 读取数据的时钟相位转换数据、我相信您将"垃圾"

    输出数据上的脉冲宽度是否与 Arduino 能够接收的脉冲宽度相符?

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

    "垃圾"是什么样子的? 您是在 PC 上观察还是在两者之间观察?

    Arduino SPI 是如何配置的? 似乎您正在使用 CPOL=1/CPHA=1、并且在每个字节周围都有一个高电平有效的片选[有些不寻常]。

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

    我没有范围。

    我怀疑时钟。 我刚刚把 Arduino 配置为从属。

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

    看起来像这个[]..

    从 TI 芯片传输到 Arduino 和 Arduino 传输到 PC。

    由于从器件是控制器、因此我当前没有使用芯片选择。

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

    SPI 具有 Bruce 和我说过的几个"模式"。 您必须确保主设备和从设备同意。

    https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi

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

    您要发送的数据看起来像{0x01、0x02、...} 哪些许多/大多数 PC 终端程序将显示为黑色或点("")。 尝试从 TXData='0'开始;以获得可显示的内容。

    我认为、AVR SPI 从器件没有/SS 就无法运行、/SS 也不能为高电平有效。  如果您在 SPCR 中没有更改任何内容、则会得到 MODE=0 (CPHA=0/CPOL=0)、但您使用的是 MODE=3。 您如何配置 Arduino 端?

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

    我已更新模式0。

    我已经尝试了'0'传输也..

    我将通过 Arduino 端的 UART 获得一组数据和传输? 已将相同配置为 RX 中断。

    真的无法确定问题是什么。。。

    您是否具有 EVM430-FR6047电路板的工作代码? 设计的电路板中存在一些晶体问题。 因此、计划让它在评估板中工作。

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

    Resource Explorer 中应该有一些示例、