The basic principles and usage of RS485 communication are the same as RS232, with the following differences.
RS232 interface can only realize point-to-point communication, but this method cannot realize networking function, so RS485 appeared to solve this problem. RS485 uses differential signal negative logic, +2V~+6V represents "1", -6V~-2V represents "0". For dual-machine communication, only AA and BB connections are needed.
The hardware circuit generally uses RS485 level conversion chips such as SN65176. When connected to the MCU, there are three pins: DE (RE and DE are connected together), DI (receive pin), RO (send pin). When the MCU sends a frame signal, it must first enable DE=1; before receiving the signal, it must first enable DE=0 (ie RE=0).
2. Examples
2.1 Send character 8.N.1.2400
#define DRE_out P3DIR |= BIT3 //Connect the DE and RE ports of the 485 chip to the output state
#define DE P3OUT |= BIT3 //Set the 485 chip to the sending state
void Set_UART1(void)
{
P3SEL |= 0xC0; //Select P3.6 and P3.7 as the communication port of UART1
ME2 |= UTXE1 + URXE1; // Enable TXD and RXD of USART1
UCTL1 |= CHAR; //Select 8-bit character
UTCTL1 |= SSEL0; //Drive clock selection ACLK
UBR01 = 0x0D; //Baud rate 2400
UBR11 = 0x00;
UMCTL1 = 0x6B; //Adjust
UCTL1 &= ~SWRST; //Initialize UART state machine
}
main
{
DRE_out;
DE;
Set_UART1();
TXDATA = 0X30;
TXBUF1 = TXDATA; //Here you can directly assign a value to transmit fixed data
while(!(IFG2 & UTXIFG1)); //Wait for sending to end
…
}
2.2 Interrupt function receives character 8.N.1.2400
void Set_UART1(void)
{
P3SEL |= 0xC0; //Select P3.6 and P3.7 as the communication port of UART1
ME2 |= UTXE1 + URXE1; // Enable TXD and RXD of USART1
UCTL1 |= CHAR; //Select 8-bit character
UTCTL1 |= SSEL0; //Drive clock selection ACLK
UBR01 = 0x0D; //Baud rate 2400
UBR11 = 0x00;
UMCTL1 = 0x6B; //Adjust
UCTL1 &= ~SWRST; //Initialize UART state machine
IE2 |= URXIE1; //Enable UART1 receive interrupt
}
#pragma vector=UART1RX_VECTOR
__interrupt void UART1_RX (void)
{
Disp1Char(pX++,pY,RXBUF1);
if(pX == 16)
{
pX = 0;
pY^= 1;
}
}
Previous article:Research on Model-free Control of Switching Power Supply
Next article:MSP430F149 serial port RS232 interface
Recommended ReadingLatest update time:2024-11-15 17:52
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Application Note Download | Keysight Technologies "Quickly Find and Identify Hidden Signal Errors"
- Ask a Question
- Mobile station development board TI MSP430FR5969LaunchPad is here!
- Can the STM32F103T8U6 use CAN?
- The romance and art of electronic engineers
- 【AT-START-F425 Review】Interpretation of I2C i2c_application.c
- Based on TI Da Vinci series TMS320DM8148 floating-point DSP C674xRGMII Gigabit Ethernet port, HDMI output interface
- Distinguishing the real from the fake: A guide to chip procurement
- Can two RSL10s be connected via Bluetooth?
- [TI recommended course] #In-depth understanding of the principle and control of brushless DC motor (BLDC) #The entire brushless motor drive process is suitable for beginners