whuctx 发表于 2018-4-19 09:08:14

求教:MSP430FR5969单片机串口编程问题请教!

事情是这样的,我有个表妹在澳大利亚留学,学的是生物医药,没有接触过单片机,但是这学期他们都是给安排了单片机课程,用的是MSP430FR5969,还安排了作业,采用的是TI官方开发板 MSP430FR5969,编写串口发送功能,因此想我请教,而我本人没有接触过这个单片机,手上也没有开发板,参考资料写了一个程序,表妹反馈程序下载指示灯正常,串口无数据,因此向各位大神请教一下代码是否有问题:
//******************************************************************************
#include "msp430.h"
//void uart_putc(unsigned char byte);
//static void uart_putst(char string);
#define RX_BUFFER_LENGTH 100
static volatile int RXbuffer;
static volatile int RXbufferIDX;
static volatile int RXbuffer_temp;
volatile unsigned int tx_flag;
//--------------------------------------------------------------
//UART Definition
//--------------------------------------------------------------
//USCI_A1
#define UART_TX_READY      (UCA1IFG & UCTXIFG)
#define UART_TX_DONE          (UCA1IFG & UCTXCPTIFG)
#define UART_RESET_TX_DONE    (UCA1IFG &= ~UCTXCPTIFG)

//--------------------------------------------------------------
//Functions for USCI_A0
//--------------------------------------------------------------


static void uart_putc(char c)
{

//EUSCI_A_UART_transmitData(EUSCI_A1_BASE, c);
while(!UART_TX_READY);
UCA1TXBUF =c;
while (!UART_TX_DONE)
    UART_RESET_TX_DONE;

}

void Delay(int num)
{
    int a,b;
    for(a = 0;a< num;a++)
    {
      for(b = 0;b<1000;b++)
      {}
   }

}

static void uart_putst(char *str)
{
    while(*str)
    {
      uart_putc(*str);
    str++;

    }
}


void initi_UART_A1(void)
{


      // Disable the GPIO power-on default high-impedance mode to activate
      // previously configured port settings
      // PM5CTL0 &= ~LOCKLPM5;
      // Configure USCI_A1 for UART mode
      UCA1CTLW0 = UCSWRST;       // Put eUSCI in reset
      UCA1CTLW0 |= UCSSEL__SMCLK;               // CLK = SMCLK
      // Baud Rate calculation=9600

      UCA1BR0 = 52;                           // 8000000/16/9600

      UCA1MCTLW |=UCOS16 | UCBRF_5;
      UCA1BR1 = 0;
      UCA1CTLW0 &= ~UCSWRST;// Initialize eUSCI
      UCA1IE |= UCTXIE;                         // Enable USCI_A1 TX interrupt
       // UCA1IE |= UCRXIE;                         // Enable USCI_A1 TX interrupt

tx_flag =0;//unused



}

void initial_Clock(void)
{

    // Startup clock system with max DCO setting ~8MHz
      CSCTL0_H = CSKEY >> 8;                  // Unlock clock registers
      //CSCTL1 = DCOFSEL_6;// Set DCO to 8MHz    20180417
      //CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK;
      CSCTL1 = DCOFSEL_3 | DCORSEL;             // Set DCO to 8MHz
      CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;
      CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;   // Set all dividers

      do
      {
          CSCTL5 &= ~LFXTOFFG;
          SFRIFG1 &= ~OFIFG;
      }while(SFRIFG1&OFIFG);

   CSCTL0_H = 0;                           // Lock CS registers

}


//Transmit Interrupt

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR (void)
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_A1_VECTOR)))void USCI_A1_ISR(void)
#else
#error Compiler not supported!
#endif
{

UCA1IFG &= ~UCTXIFG;
UCA0IFG &= ~UCRXIFG;
UCA1RXBUF = UCA0TXBUF;


}


void Initial_GPIO(void)
{

    P1OUT = 0;
    P1DIR =0xFF;
    P3OUT = 0;
    P3DIR =0xFF;
    P4OUT = 0;
    P4DIR =0xFF;
    PJOUT =0;
    PJDIR=0xFFFF;
    P2SEL1 |= BIT5 | BIT6;                  // USCI_A1 UART operation
    P2SEL0 &= ~(BIT5 | BIT6);
    //P2SEL1 |= BIT0 | BIT1;                     // 20180417
    //P2SEL0 &= ~(BIT0 | BIT1);
    PJSEL0 |=BIT4|BIT5;

}
//--------------------------------------------------------------
//Main Function
//--------------------------------------------------------------


int main(void)
{
    volatile unsigned j;
    WDTCTL = WDTPW | WDTHOLD;               // Stop Watchdog

    // Configure GPIO
    //P1OUT &=~BIT0;
    //P1DIR =BIT1;

    Initial_GPIO();
    PM5CTL0 &= ~LOCKLPM5;
    initial_Clock();
   initi_UART_A1();
    _EINT();//enable interrupt

    //_bis_SR_register(LPM0_bits);   // Enter LPM3, interrupts enabled

    P1OUT &=~BIT0;
    P4OUT &=~BIT6;
    while (1)
    {
      P1OUT |= BIT0;
      P4OUT |= BIT6;

       uart_putst((char *)"HELLO");
       uart_putc(0x0D);
       uart_putc(0x0A);//new line
       __delay_cycles(2000000);
      
       P1OUT &=~BIT0;
      P4OUT &=~BIT6;

      __delay_cycles(2000000);

   }
}
PS:按照规矩先上照片,但确实手机没有存,也没有拍过,有机会奉上,先帮忙解决问题,谢谢!
页: [1]
查看完整版本: 求教:MSP430FR5969单片机串口编程问题请教!