Other Parts Discussed in Thread: MSP430F2132
工具/软件:Code Composer Studio
您好!
控制器 :MSP430F2132
晶体振荡器 :16MHz
问题 :启用 UART 串行通信时 GPIO 不工作。
GPIO 在启用 UART 代码或将 UART 代码添加到项目之前运行良好、并经过良好测试。 还注意到 XOUT 引脚上的16MHz 波形。 在项目中添加 UART 代码后、我记下了 UCA0TXD 引脚(引脚编号15)上的波形/脉冲。 但未通过任何终端软件验证。
但是,当我在同一固件中尝试 GPIO 功能时,GPIO 功能不像以前一样工作。
我在哪里犯了错误? 请帮助解决问题。
下面是我的代码。
#include
#define _Input1 (P2IN 和0x10)//P2.4
#define _INPUT2 (P2IN 和0x20)//P2.5
#define _INPUT3 (P3IN 和0x01)//P3.0
#define _INPUT4 (P3IN 和0x02)//P3.1
#define _INPUT5 (P2IN 和0x01)//P2.0
#define _INPUT6 (P2IN 和0x02)//P2.1
#define _INPUT7 (P2IN 和0x04)//P2.2
#define _INPUT8 (P2IN 和0x08)//P2.3
#define _Output1_ON P1OUT = P1OUT | 0x01 //P1.0
#define _output2_on P1OUT = P1OUT | 0x02 //P1.1
#define _OUTPUT3_ON P1OUT = P1OUT | 0x04 //P1.2
#define _OUTPUT4_ON P1OUT = P1OUT | 0x08 //P1.3
#define _OUTPUT5_ON P1OUT = P1OUT | 0x10 //P1.4
#define _OUTPUT6_ON P1OUT = P1OUT | 0x20 //P1.5
#define _OUTPUT7_ON P1OUT = P1OUT | 0x40 //P1.6
#define _OUTPUT8_ON P1OUT = P1OUT | 0x80 //P1.6
#define _Output1_off P1OUT = P1OUT & 0xFE // P1.0
#define _output2_off P1OUT = P1OUT & 0xFD //P1.1
#define _OUTPUT3_OFF P1OUT = P1OUT & 0xFB // P1.2
#define _OUTPUT4_OFF P1OUT = P1OUT & 0xF7 // P1.3
#define _OUTPUT5_OFF P1OUT = P1OUT & 0xEF // P1.4
#define _OUTPUT6_OFF P1OUT = P1OUT & 0xDF // P1.5
#define _OUTPUT7_OFF P1OUT = P1OUT & 0xBF //P1.6
#define _OUTPUT8_OFF P1OUT = P1OUT & 0x7F //P1.6
#define _all_output_off P1OUT = 0x00;
#define _RS485_TX_EN P3OUT = P3OUT | 0x40 //P3.6 =高电平
#define _RS485_Tx_DIS P3OUT = P3OUT & 0xBF //P3.6 =低电平
#define _RS485_RX_EN P3OUT = P3OUT & 0x7F //P3.7 =低电平
#define _RS485_Rx_DIS P3OUT = P3OUT | 0x80 //P3.7 =高电平
#define _RS485_TX_TOGGLE P3OUT = P3OUT ^ 0x10 //P3.1 =高电平
unsigned char buffer[10]={0};
unsigned char i=0;
/**
* main.c
*
int main (空)
{
WDTCTL = WDTPW | WDTHOLD;//停止看门狗计时器
BCSCTL1 |= XTS | DIV_0;/* LFXTCLK 0:低频率 / 1:高频率 *
//ACLK 分频器= 0
BCSCTL2 |= DIVS_1 | SELS |DIVM_1|SELM1;//MCLK = LFXT1CLK、DIVs=1、DIVm=1、SMCLK=LFXT1CLK
BCSCTL3 |= LFXT1S1;针对 LFXT1 (XTS = 0)的//模式1
P1DIR |= 0xFF;//将 P1.0设置为输出方向
P2SEL = 0xC0;
P2DIR |= 0x00;//设置 P2所有输入
P3SEL |= 0x30;//对 USCI_A0使用 P3.4/P3.5
// P3SEL |= 0x00;//对 USCI_A0使用 P3.4/P3.5
P3DIR |= 0xDC;//将 P3.0、P3.1和 P3.5设置为输入
_all_output_off;//重置所有输出
UCA0CTL0 = 0x00;//8、N、1、LSB、UART、异步
UCA0CTL1 |= UCSSEL_1;// CLK = ACLK
UCA0BR0 = 65;// 8MHz/9600 = 833
UCA0BR1=0x03;
UCA0MCTL = UCBRS2;//调制 UCBRSx = 3
UCA0CTL1 &=~UCSWRST;//**初始化 USCI 状态机**
IE2 |= UCA0RXIE + UCA0TXIE;//启用 USCI_A0 TX/RX 中断
_bis_SR_register (LPM3_bits + GIE);//启用中断后进入 LPM3
//UCA0TXBUF ='A';
//缓冲区[5]= 0xAA;
_RS485_TX_EN;
RS485_RX_EN;
while (1)
{
// UCA0TXBUF ='A';
//_RS485_TX_TOGGLE;
//_delay_cycles (30000);
//_DELAY_CYCLES (100000);
//Blink Output1.
/*_Output1_on;
_delay_cycles (80000);
_Output1_off;
_delay_cycles (80000);
*
if (!(_Input1))||(!(_INPUT2))||(!(_INPUT3))||(!(_INPUT4)||(!(_INPUT5))||(!(_INPUT6))||(!(_INPUT7))||(!INPUT8)
if (!(_Input1)){
_Output1_on;
}
if (!(_INPUT2)){
_output2_on;
}
if (!(_INPUT3)){
_OUTPUT3_ON;
}
if (!(_INPUT4)){
_OUTPUT4_ON;
}
if (!(_INPUT5)){
_OUTPUT5_ON;
}
if (!(_INPUT6)){
_OUTPUT6_ON;
}
if (!(_INPUT7)){
_OUTPUT7_ON;
}
if (!(_INPUT8)){
_OUTPUT8_ON;
}
}否则{
_all_output_off;
}
}
//返回0;
}
// USCI A0/B0发送 ISR
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=USCIAB0TX_vector
_interrupt void USCI0TX_ISR (void)
#Elif defined (_GNU_)
void __attribute__((中断(USCIAB0TX_vector)) USCI0TX_ISR (void)
其他
错误编译器不受支持!
#endif
{
UCA0TXBUF =缓冲区[5];//读取、对齐和发送
}
// USCI A0/B0接收 ISR
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=USCIAB0RX_vector
_interrupt void USCI0RX_ISR (void)
#Elif defined (_GNU_)
void __attribute__((中断(USCIAB0RX_vector)) USCI0RX_ISR (void)
其他
错误编译器不受支持!
#endif
{
Buffer[0]= UCA0RXBUF;//显示 RX'ed 字符
}