2848 views|1 replies

6

Posts

0

Resources
The OP

About MSP430 serial port sending data [Copy link]

//**************************************************************************** // Serial port 1 sends data function//************************************************************************ void Send_Byte(uchar data) { RS485_CTR1; while(!(IFG2&UTXIFG1)); //Send data when the send register is empty U1TXBUF=data; } //************************************************************ // Command judgment//******************************************************** void judge_data(void) { if (sys_tem[1]==0x52) //Command start{ Send_Byte(0x24); Send_Byte(0x52); Send_Byte(0x0D); } else if(sys_tem[1]==0x57)//Write program{ if(sys_tem[2]==0x43)//Write channel number{ Send_Byte(0x24); Send_Byte(0x57); Send_Byte(0x43); Send_Byte(0x30); Send_Byte(0x56); Send_Byte(0x4e); Send_Byte(0x0d); } else if (sys_tem[2]==0x42) //Write baud rate { Send_Byte(0x24); Send_Byte(0x57); Send_Byte(0x42); Send_Byte(0x44); Send_Byte(0x0d); } } } //************************************************************************ // Handle the receive interrupt from serial port 1//**************************************************************************** #pragma vector=UART1RX_VECTOR __interrupt void UART1_RX_ISR(void) { //Disable interrupt uint i; for(i=0;i<6;i++) { sys_tem[i]=U1RXBUF; } IE1 &=~URXIE1; judge_data(); delay_ms(5); //There is a small delay before switching RS485_CTR0; //Switch to the receiving state } sys_tem[]; defines an array to store the received commands The function you want to achieve is to receive a string of commands from the serial port (for example: 24, 57, 43, 30, 30, 0d), and then send this string of data out. How should the program be modified?

This post is from Microcontroller MCU

Latest reply

I think your for(i=0;i  Details Published on 2014-3-19 21:16

18

Posts

1

Resources
2
I think your for(i=0;i<6;i++) {sys_tem[i]=U1RXBUF; } is unlikely to work, because each interrupt routine can only accept a char
This post is from Microcontroller MCU

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

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