MSP430 5438 串口发送

2019-03-24 13:39发布

/****************************************************************
串口发送字符串函数    
****************************************************************/
void UartTX_Send(unsigned char *Data,int len)
{
  int j;
  for(j=0;j<len;j++)
  {
    while (!(UCA1IFG&UCTXIFG));
    UCA1TXBUF =*Data++;
   
  }
}
根据datesheet上面写的: (UCTXBUFx)   The transmit data buffer is user accessible and holds the data waiting to be moved into the transmit shift  register and transmitted on UCAxTXD. Writing to the transmit data buffer clears UCTXIFG. 执行完UCA1TXBUF =*Data++; 之后UCTXIFG的值不是应该变成0了吗?可是单步调试值没有发生变化,为什么呢? 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
14条回答
tgreen
2019-03-26 04:28
有的哦  就是在串口调试助手上显示不出来 为啥?
#include "msp430x54x.h"
void init_uart(void);
void init_clock(void);
/****************************************************************
串口发送字符串函数
****************************************************************/
void UartTX_Send(unsigned char *Data,int len)
{
int j;
for(j=0;j {
while (!(UCA1IFG&UCTXIFG));
UCA1TXBUF =*Data++;

}
}

void main(void)
{
unsigned char a[10]="hello";

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
init_clock();
init_uart();
// __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled

UartTX_Send(a,5);

__no_operation();
}
void init_clock(void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P11DIR = BIT0+BIT1+BIT2; // P11.1-2 to output direction
P11SEL |= BIT0+BIT1+BIT2; // P11.1-2 to output SMCLK,MCLK
P5SEL |= 0x0C; // Port select XT2
UCSCTL6 &= ~XT2OFF; // Ena××e XT2 even if not used
UCSCTL3 |= SELREF_2; // FLLref = REFO
UCSCTL4 |= SELA__XT2CLK;//辅助系统时钟来源XT2-16M
UCSCTL4 |= SELS_5 + SELM_5; // SMCLK=MCLK=XT2-16M
_NOP();
UCSCTL5 |= DIVM__2 + DIVS__16+DIVA__16; //主系统时钟2分频-8M;子系统时钟16分频-1M;辅助系统时钟16分频1M
/*do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
for(i=0;i<0xFFFF;i++); // Delay for Osc to stabilize
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
*/ 如果不屏掉的话就一直停在这里面 为啥呢?
}
void init_uart(void)
{
P5SEL |= 0xC0; // P5.6,7 = USCI_A1 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL__SMCLK; // SMCLK
UCA1BR0 = 0x08; // 1MHz 115200 (see User's Guide)
UCA1BR1 = 0x00; // 1MHz 115200
UCA1MCTL |= UCBRS_6+UCBRF_0; // Modulation UCBRSx=1, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCTXIE; // Enable USCI_A1 RX interr
UCA1IFG = 0X02; //.........
//_EINT();
}

一周热门 更多>

相关问题

    相关文章