4160 views|9 replies

23

Posts

0

Resources
The OP
 

Regarding the UART1 and UART0 transceiver issues of MSP430F149, I really need your help [Copy link]

This post was last edited by q891031520 on 2018-2-2 17:39 I am debugging a program recently. UART0 and UART1 of MSP430F149 are connected to two computers, PC0 and PC1, respectively. When PC1 connected to UART1 sends data, the data returned is not the original data. The data sent is OK, but the data returned to PC1 is the character corresponding to 152 in the ASKII code table. PC0 connected to UART0 also cannot receive any data. P2OUT is connected to 8 LED lights. PC1 can correctly receive the data sent by UART1. In another test, when the receiving interrupt service functions of UART0 and UART1 write TXBUF1=RXBUF0 and TXBUF0=RXBUF1 respectively, they can also send and receive correctly. How can I make UART1 send and receive correctly? #include "msp430x14x.h" #define uint unsigned int #define uchar unsigned char uchar num=0,sum; uchar jud[2]={0,0}; //uchar wd[20],xy[20],xl[20]; uchar stand[2]={0,0}; void Send1Char0(uchar sendchar); void PutString0(uchar *ptr); void Send1Char1(uchar sendchar); void PutString1(uchar *ptr); void com_init();//Serial port initialization void com_init1() { unsigned int i; /*The following six lines of program close all IO ports*/ P1DIR = 0XFF;P1OUT = 0XFF; P2DIR = 0XFF;P2OUT = 0XFF; P3DIR = 0XFF;P3OUT = 0XFF; P4DIR = 0XFF;P4OUT = 0XFF; P5DIR = 0XFF;P5OUT = 0XFF; P6DIR = 0XFF;P6OUT = 0XFF; P3SEL |= BIT6+BIT7; P3DIR |= BIT6; BCSCTL1 &= ~XT2OFF; // XT2on do { IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } while ((IFG1 & OFIFG)); // OSCFault flag still set? BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 ME2 |= UTXE1 + URXE1; // Enable USART1 to send and receive UCTL1 |= CHAR + SWRST; // Select 8-bit character UTCTL1 |= SSEL1; //UCLK = SMCLK UBR01 = 0x45; //Baud rate 115200 UBR11 = 0x00; UMCTL1 = 0x00; UCTL1 &= ~SWRST; //Initialize UART1 IE2 |= URXIE1; //Enable receive interrupt for UART1_EINT(); //Open global interrupt} void com_init() { P3SEL |= 0x30; // Select P3.4 and P3.5 as UART communication ports and P3.6 TXD P3.7 RXD P3DIR |= BIT4; ME1 |= UTXE0 + URXE0; // Enable USART0 to send and receive UCTL0 |= CHAR + SWRST; // Select 8-bit character UTCTL0 |= SSEL1; // UCLK = SMCLK UBR00 = 0x45; //Baud rate 115200 UBR10 = 0x00; // UMCTL0 = 0x00; // Modulation UCTL0 &= ~SWRST; // Initialize UART IE1 |= URXIE0; // Enable receive interrupt of USART0 } /******************************************* // Function name: data_SEND Function: Send AT Parameter: data Return value: None********************************************/ void data_SEND() { while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1='A'; while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1='T'; } /*********************************************** Function name: UART1_RXISR Function: UART1 receive interrupt service function Parameter: None Return value: None********************************************/ #pragma vector = UART1RX_VECTOR __interrupt void UART1_RXISR(void) { stand[0]=1; sum=RXBUF1; while (!(IFG2 & UTXIFG1)); TXBUF1 = sum; while (!(IFG1 & UTXIFG0)); TXBUF0 = sum; // } /******************************************* Function name: UART0_RXISR Function: UART0 receive interrupt service function Parameter: None Return value: None********************************************/ #pragma vector = UART0RX_VECTOR __interrupt void UART0_RXISR(void) { stand[0]=2; } /*********************************************** Function name: Send1Char Function: Send a character to PC Parameter: sendchar--character to be sent Return value: None********************************************/ void Send1Char0(uchar sendchar0) { while (!(IFG1 & UTXIFG0)); //Wait for the send register to be empty TXBUF0 = sendchar0; } void Send1Char1(uchar sendchar1) { while (!(IFG2 & UTXIFG1)); //Wait for the send register to be empty TXBUF1 = sendchar1; } /*********************************************** Function name: PutSting Function: Send a string to the PC Parameter: ptr--pointer to the string to be sent Return value: None **********************************************/ void PutString0(uchar *ptr0) { while(*ptr0 != '\0') { Send1Char0(*ptr0++); // Send data } // while (!(IFG1 & UTXIFG0)); // TXBUF0 = 0x0d; // while (!(IFG1 & UTXIFG0)); // TXBUF0 = 0x0a; //Send a line feed instruction } void PutString1(uchar *ptr1) { while(*ptr1 != '\0') { Send1Char1(*ptr1++); // Send data } P2OUT=0xfe; // while (!(IFG2 & UTXIFG1)); // TXBUF1 = 0x0d; // while (!(IFG2 & UTXIFG1)); // TXBUF1 = 0x0a; //Send line break instruction} /********************Main function************************/ void main(void) { WDTCTL = WDTPW + WDTHOLD; P2DIR=0xff; com_init1(); com_init(); P2OUT=0xf0; PutString1("AT"); while(1) { if(stand[0]==1) P2OUT=0xaa; if(stand[0]==2) { P2OUT=0x3c; while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x41; //A while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x54; //T stand[0]=3; } } }(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x54; //T stand[0]=3; } } }(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x54; //T stand[0]=3; } } }(IFG2 & UTXIFG1)); //Wait for the send register to be empty TXBUF1 = sendchar1; } /******************************************* Function name: PutSting Function: Send a string to the PC Parameter: ptr--pointer to the string to be sent Return value: None **********************************************/ void PutString0(uchar *ptr0) { while(*ptr0 != '\0') { Send1Char0(*ptr0++); // Send data } // while (!(IFG1 & UTXIFG0)); // TXBUF0 = 0x0d; // while (!(IFG1 & UTXIFG0)); // TXBUF0 = 0x0a; //Send a line feed instruction } void PutString1(uchar *ptr1) { while(*ptr1 != '\0') { Send1Char1(*ptr1++); // Send data } P2OUT=0xfe; // while (!(IFG2 & UTXIFG1)); // TXBUF1 = 0x0d; // while (!(IFG2 & UTXIFG1)); // TXBUF1 = 0x0a; //Send line break instruction} /********************Main function************************/ void main(void) { WDTCTL = WDTPW + WDTHOLD; P2DIR=0xff; com_init1(); com_init(); P2OUT=0xf0; PutString1("AT"); while(1) { if(stand[0]==1) P2OUT=0xaa; if(stand[0]==2) { P2OUT=0x3c; while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x41; //A while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x54; //T stand[0]=3; } } }(IFG2 & UTXIFG1)); //Wait for the send register to be empty TXBUF1 = sendchar1; } /******************************************* Function name: PutSting Function: Send a string to the PC Parameter: ptr--pointer to the string to be sent Return value: None **********************************************/ void PutString0(uchar *ptr0) { while(*ptr0 != '\0') { Send1Char0(*ptr0++); // Send data } // while (!(IFG1 & UTXIFG0)); // TXBUF0 = 0x0d; // while (!(IFG1 & UTXIFG0)); // TXBUF0 = 0x0a; //Send a line feed instruction } void PutString1(uchar *ptr1) { while(*ptr1 != '\0') { Send1Char1(*ptr1++); // Send data } P2OUT=0xfe; // while (!(IFG2 & UTXIFG1)); // TXBUF1 = 0x0d; // while (!(IFG2 & UTXIFG1)); // TXBUF1 = 0x0a; //Send line break instruction} /********************Main function************************/ void main(void) { WDTCTL = WDTPW + WDTHOLD; P2DIR=0xff; com_init1(); com_init(); P2OUT=0xf0; PutString1("AT"); while(1) { if(stand[0]==1) P2OUT=0xaa; if(stand[0]==2) { P2OUT=0x3c; while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x41; //A while (!(IFG2 & UTXIFG1)); //Wait for the transmit register to be empty TXBUF1 = 0x54; //T stand[0]=3; } } }
This post is from Microcontroller MCU

Latest reply

Can the OP tell me how to solve this problem? Thank you  Details Published on 2018-5-15 20:54
 

77

Posts

0

Resources
2
 
You can connect serial port 1 to the PC serial port directly after conversion through the max232 chip, and then use the serial port debugging tool to send data to each other to see whether the problem is your receiving problem or the other party's sending problem. Remember to share the ground.
This post is from Microcontroller MCU
 
 

23

Posts

0

Resources
3
 
Wang Guichen posted on 2018-2-2 19:34 You can make serial port 1 directly connected to the PC serial port after conversion through the max232 chip, and then use the serial port debugging tool to send data to each other to see what you are receiving...
Thank you, but I don’t have a max232 chip yet, so I can only rule out the problem. It is correct to use the microcontroller to send data to the PC using UART1. If TXBUF1=RXBUF0 is used, there will be problems with the microcontroller sending the received data back. It should be a reception problem. The receive interrupt function of UART1 may not be entered, but I don’t know how to change it.
This post is from Microcontroller MCU
 
 
 

1

Posts

0

Resources
4
 
Hello, I have not used msp430, but other MCUs generally need to wait for a register bit state to change when receiving data.
This post is from Microcontroller MCU
 
 
 

1059

Posts

1

Resources
5
 
Refer to the official code to adjust serial port 0 and serial port 1
This post is from Microcontroller MCU
 
 
 

23

Posts

0

Resources
6
 
qwerghf posted on 2018-2-3 09:31 Refer to the official code to adjust serial port 0 and serial port 1
Thank you very much, it has been solved
This post is from Microcontroller MCU
 
 
 

23

Posts

0

Resources
7
 
wxg5555 posted on 2018-2-3 07:59 Hi, I have never used msp430, but other mcu generally need to wait for a certain register bit status to change when receiving data
Thank you very much, it has been solved
This post is from Microcontroller MCU
 
 
 

525

Posts

235

Resources
8
 
The original poster can share the solution or the cause of the problem with everyone so that we can learn from each other.
This post is from Microcontroller MCU
 
Personal signature爱电子,爱生活
 
 

1

Posts

0

Resources
9
 
q891031520 posted on 2018-2-3 17:41 Thank you very much, it has been solved
Can the OP tell me how to solve this problem? Thank you
This post is from Microcontroller MCU
 
 
 

23

Posts

0

Resources
10
 
I'm sorry, it's been a long time and I don't remember it. If you have any questions, please raise them and we can make progress together.
This post is from Microcontroller MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list