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.

MSP430FR2433串口配置

Hi TI team:

    在使用FR2433的串口通讯时,出现串口1无法收发数据,改变端口配置为串口0 时,收发正常。手册中未查到串口A0和A1有差异,程序使用样的配置A1却无法正常收发。

//串口都配置9600bps,目前串口0可以与串口工具进行收发数据,但是串口1接收数据进不到中断里

//串口1发送数据,串口工具也无法接收,用示波器观察单片机端口没有数据。

请TI 帮忙看看,谢谢。

  • 楼主你好。从你的描述看,是串口1配置问题的可能居多。
    建议上传下相关代码,大家帮你检查一下
  • 若是可以的话,请上传一下您的代码或者私信您的工程给我,谢谢

  • 以上传请查收帮忙看下,谢谢。

    串口配置--FR2433.txt
    void USART0Initialize(void)    
    {
       P1SEL0 |= BIT4+BIT5;  
      
      UCA0CTLW0 |= UCSWRST;                   // Put eUSCI in reset
      UCA0CTLW0 |= UCSSEL__SMCLK;    
      
      UCA0BR0 = 0x06;                           // 1000000/16/9600
      UCA0BR1 = 0x00;
       UCA0MCTLW =  UCOS16 | UCBRF_8;
      UCA0CTLW0 &= ~UCSWRST;                  // Initialize eUSCI
      UCA0IE |= UCRXIE;                       // Enable USCI_A0 RX interrupt
    }
    
    
    void USART1Initialize1(void)    
    {  
      P2SEL0 |= BIT5+BIT6;  
      
      UCA1CTLW0 |= UCSWRST;                   // Put eUSCI in reset
      UCA1CTLW0 |= UCSSEL__SMCLK;  
       
      UCA1BR0 = 0x06;                           // 1000000/16/9600
      UCA1BR1 = 0x00;
       
      UCA1MCTLW = UCOS16 | UCBRF_8; 
    
      
      UCA1CTLW0 &= ~UCSWRST;                  // Initialize eUSCI
      UCA1IE |= UCRXIE;                       // Enable USCI_A1 RX interrupt
    
    }
    
    
    
    #pragma vector=USCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    {
      
      _DINT();
      _BIC_SR_IRQ(LPM3_bits);  
      fnReDatausart1_rx();    
    }
    
    
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    {
    
      UCA0IFG &= ~UCRXIFG;
    }
    
    
    
    
    //���ڶ�����9600bps,Ŀǰ����0�����봮�ڹ��߽����շ����ݣ����Ǵ���1�������ݽ������ж���
    //����1�������ݣ����ڹ���Ҳ�޷����գ���ʾ�����۲쵥Ƭ���˿�û������
    
    
    
    

  • 请您使用下面的程序,UART1,测试正常

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2014, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   MSP430FR243x Demo - eUSCI_A1 UART echo at 9600 baud using BRCLK = 16MHz
    //
    //  Description: This demo echoes back characters received via a PC serial port.
    //  SMCLK/ DCO is used as a clock source and the device is put in LPM3
    //  The auto-clock enable feature is used by the eUSCI and SMCLK is turned off
    //  when the UART is idle and turned on when a receive edge is detected.
    //  Note that level shifter hardware is needed to shift between RS232 and MSP
    //  voltage levels.
    //
    //  The example code shows proper initialization of registers
    //  and interrupts to receive and transmit data.
    //  To test code in LPM3, disconnect the debugger.
    //
    //  ACLK = REFO = 32768Hz, MCLK = DCODIV = SMCLK = 16MHz.
    //
    //                MSP430FR2433
    //             -----------------
    //         /|\|                 |
    //          | |                 |
    //          --|RST              |
    //            |                 |
    //            |                 |
    //            |     P2.6/UCA1TXD|----> PC (echo)
    //            |     P2.5/UCA1RXD|<---- PC
    //            |                 |
    //
    //   Ling Zhu
    //   Texas Instruments Inc.
    //   Nov 2019
    //   Built with IAR Embedded Workbench v7.10 & Code Composer Studio v7.3
    //******************************************************************************
    
    #include <msp430.h>
    
    void Init_GPIO();
    
    int main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;                // Stop watchdog timer
    
      // Configure GPIO
      Init_GPIO();
      PM5CTL0 &= ~LOCKLPM5;                    // Disable the GPIO power-on default high-impedance mode
                                               // to activate 1previously configured port settings
    
      // Configure one FRAM waitstate as required by the device datasheet for MCLK
      // operation beyond 8MHz _before_ configuring the clock system.
      FRCTL0 = FRCTLPW | NWAITS_1;
    
      __bis_SR_register(SCG0);                           // disable FLL
      CSCTL3 |= SELREF__REFOCLK;                         // Set REFO as FLL reference source
      CSCTL0 = 0;                                        // clear DCO and MOD registers
      CSCTL1 &= ~(DCORSEL_7);                            // Clear DCO frequency select bits first
      CSCTL1 |= DCORSEL_5;                               // Set DCO = 16MHz
      CSCTL2 = FLLD_0 + 487;                             // DCOCLKDIV = 16MHz
      __delay_cycles(3);
      __bic_SR_register(SCG0);                           // enable FLL
      while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1));         // FLL locked
    
      CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK;         // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
                                                         // default DCOCLKDIV as MCLK and SMCLK source
    
      // Configure UART pins
      P2SEL0 |= BIT5 | BIT6;                             // set 2-UART pin as second function
    
      // Configure UART
      UCA1CTLW0 |= UCSWRST;
      UCA1CTLW0 |= UCSSEL__SMCLK;
    
      // Baud Rate calculation
      // 16000000/(16*9600) = 104.167
      // Fractional portion = 0.167
      // User's Guide Table 14-4: UCBRSx = 0x11
      // UCBRFx = int ( (104.167-104)*16) = 2
      UCA1BR0 = 104;                             // 16000000/16/9600
      UCA1BR1 = 0x00;
      UCA1MCTLW = 0x1100 | UCOS16 | UCBRF_2;
    
      UCA1CTLW0 &= ~UCSWRST;                    // Initialize eUSCI
      UCA1IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt
    
      __bis_SR_register(LPM3_bits|GIE);         // Enter LPM3, interrupts enabled
      __no_operation();                         // For debugger
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_A1_VECTOR
    __interrupt void USCI_A1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(UCA1IV,USCI_UART_UCTXCPTIFG))
      {
        case USCI_NONE: break;
        case USCI_UART_UCRXIFG:
          while(!(UCA1IFG&UCTXIFG));
          UCA1TXBUF = UCA1RXBUF;
          __no_operation();
          break;
        case USCI_UART_UCTXIFG: break;
        case USCI_UART_UCSTTIFG: break;
        case USCI_UART_UCTXCPTIFG: break;
        default: break;
      }
    }
    
    void Init_GPIO()
    {
        P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF;
        P1REN = 0xFF; P2REN = 0xFF; P3REN = 0xFF;
        P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00;
    }
    

  • Hi Susan:
         在没有改变任何软硬件的前提下串口1通讯又正常了,怀疑单片机内部震荡不稳定,导致和串口工具通信的时候 电压不匹配,从而不能收发数据。串口工具的电压稳定,如下是单片机的供电部分原理图,前端是4节干电池供电,经过LDO降压给MCU的。有哪些方法可以测试下么?

  • Susan:
    想问下这句代码:PM5CTL0 &= ~LOCKLPM5;
    代码中配置这行代码的话,串口都收发都正常,但是不配置,就是之前的情况,串口0可用,串口1不可用;
    配置过的程序刷过后,串口1可用,这时再刷回没配置过的程序也可用了。
    能否解释下这是什么现在呢,非常感谢。
  • PM5CTL0 &= ~LOCKLPM5; 这句话是对GPIO进行解锁,因为板子默认是锁定的就是说没有办法配置寄存器的相关信息,进行解锁才是有效的。
  • 如上面文件中的定义

    PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
    // to activate 1previously configured port settings

    上电默认是高阻抗模式的,这句话是激活先前配置的端口设置即 Init_GPIO();