Recently, a product based on the lpc2387 solution needs RS485 communication. After checking datasheet, The uart of the lpc2387 does not have the built-in RS485 function, so it can only adopt level conversion. Finally, the um3085 of maxcompute and is selected. Both chip pins are compatible and can be converted to TTL and RS485.
Because half-duplex communication is used, a gpio port can be used to control both de and RE. A single moment can only be used to receive or send data. Txd1 and rxd1 of lpc2387 are connected to Di and Ro of 485 respectively.
// RS-485 sending and receiving control code, and compared with ordinary serial communication, more than 485 chip sending/receiving enable settings # define rs485_de_re (0x01 <9) // gpio ipv9 controls de, re /************************************** *********************** * ********************/void enable_rs485_tx () {fio0dir | = rs485_de_re; // gpio dir out fio0set = rs485_de_re; // level 9 output, where de is 1, re is 0 }/*********************************** ******************** * ***********************/void enable_rs485_rx () {fio0dir | = rs485_de_re; // gpio dir out fio0clr = rs485_de_re; // when 9 outputs a low level, de is 0, and RE is 1}