Question

I'm trying to implement a simple communication between two LPC1765 devices using RS-485. I'm using this example added to my menu system (it's a basic example for LPC17xx):

http://www.codeforge.com/read/155431/rs485.c__html
http://www.codeforge.com/read/155431/rs485.h__html
http://www.codeforge.com/read/155431/rs485test.c__html

So, both devices are properly initialized using RS485Init(). When I send data using RS485Send using a slave address as the first byte, the result is:

(1) if the devices are disconnected, transmitter receives its own communication (the contents of UARTBuffer are updated

(2) if the devices are connected, nothing happens -- transmitted buffer is lost somewhere (UARTBuffer doesn't change)

Now hardware should be properly connected so I'll just list things for reference. There is a U59 SN65HVD1781D driver on RS485_TXD/RXD, there are RS485_OF, RS485_MASTER_PWR and RS485_MASTER_MFAS and a voltage regulator. There is a RS485 slave detect circuit and UP/DOWN connections. Each device is connected with four contacts and they are (I think) RS485_UP, RS485_A+, RS485_B- and RS485_DOWN. There is a 4-pin connector both on top and on the bottom to connect devices in a sequence, where the topmost device would, if everything works, assume the status of a master over all bottom devices.

Was it helpful?

Solution

I got RS485 to work.

Using LPC17xx user manual at http://www.nxp.com/documents/user_manual/UM10360.pdf

In rs485.c in function RS485Init, direction control bits were wrong with PINSEL1 instead of PINSEL4; according to manual page 110, this should be correct (well, you can write 0x800 in many ways, but this is just a quick fix):

if (DIR_CTRL == 1){
  LPC_PINCON->PINSEL4 |= 0x800;         
  LPC_UART1->RS485CTRL |= (RS485_DCTRL|RS485_SEL|RS485_OINV);
}else{
  LPC_PINCON->PINSEL4 |= 0x8000;            
  LPC_UART1->RS485CTRL |= (RS485_DCTRL|RS485_SEL|RS485_OINV);
} 

The second device has received my buffer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top