1569 views|0 replies

2015

Posts

0

Resources
The OP
 

RS485 communication issues in MSP430F169 [Copy link]

1. General framework: realize the communication between the MCU and the PC.
The PC (USB interface) sends characters, which are converted to RS232 through USB, and then converted to RS485 through RS232, and then received by the MCU (RS485 interface).
2. The program design is as follows: During the step-by-step debugging process, no matter what kind of characters are sent, the RXBUF1 variable is always 0X01. Please guide!!!
/*********************************************** Program function: Receive sensor data through RS485 port, and then transmit the data to the display screen through RS232------------------------------------------------ Test description: First check the data received by RS485, then use the serial port debugging tool to check the sent data, and finally debug whether the content on the display screen displays correctly. Temperature and humidity sensor data command format: 01 03 00 00 00 02 C4 0B; 01 device address, 03 function number, 02 indicates data length, C4 0B indicates CRC check code************************************************/ #include  


#define DRE_out P3DIR |= BIT3 //Connect the DE of 485 chip, and set the IO of RE port to output state#define DE P3OUT |= BIT3 //Set the 485 chip to the sending state, DE is high level, #define RE P3OUT &= ~BIT3 //Set the 485 chip to the receiving state (RE is low level, receiver output is enabled char tmp; void Set_UART1(void); /****************Main function********************/ void main(void) { WDTCTL = WDTPW + WDTHOLD; //Turn off the watchdog P6DIR |= BIT2; P6OUT |= BIT2; //Turn off the level conversion DRE_out; RE; //Set 485 to the receiving state Set_UART1(); while (1) { _EINT(); //Turn on the global interruptwhile(IFG2 & URXIFG1); tmp=RXBUF1; } } /*********************************************** Function name: Set_UART1 Function: Set the register corresponding to UART1 of MCU Parameter: None Return value: None **********************************************/ void Set_UART1(void) { P3SEL |= 0xC0; //Select P3.6, P3.7 as the communication port of UART1 ME2 |= UTXE1 + URXE1; //Enable TXD and RXD of USART1 (enable receive interrupt) P3DIR |= BIT6; //Output P3DIR &=~BIT7; //Input UCTL1 |= CHAR; //Select 8-bit character UTCTL1 |= SSEL0; //Drive clock selection ACLK UBR01 = 0x03; //Baud rate 9600 UBR11 = 0x00; UMCTL1 = 0x4A; //Adjust UCTL1 &= ~SWRST; //Initialize UART state machine IE2 |= URXIE1; // Enable USART1 receive interrupt} //Send string void SendString(void) { unsigned int i; for(i=0;i<=7;i++) { while(!(IFG2 & UTXIFG1)); //Wait for sending to end, UTXIFG1 sends interrupt flag TXBUF1 = send_data_buf; //Send character} } //------------------------------------------------------------------------------ //Delay function void Delay_us(unsigned int n) { unsigned int i; for(i=0;i
RS485 communication issues in MSP430F169


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