RS-485 Master slave communication

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RS-485 Master slave communication

5,483 Views
mohammadfaizan
Contributor III

Hi,

I have a custom board design by using a LPC2388. I have tested it with simple UART code, it's  transmitting and receiving data properly. Now I am looking forward to implement a master slave communication, One master and multiple slave(24), but some restriction, as shown in attach image uart.png.  I need some guidance were to start, how to add our own protocol. It will be more helpful, if I get some library or demo code for rs485 master slave communication(LPC2388).

thanks & regards

Mohammad Faizan

Labels (2)
0 Kudos
Reply
10 Replies

4,365 Views
mohammadfaizan
Contributor III

Thanks Chris,

ok, I will try to  create a 6 slave first, if it works fine, then I will make a duplicate of the working one.

warm regards

Mohammad Faizan

0 Kudos
Reply

4,365 Views
shruti_patel
Contributor I

Hello Mohamamd Faizan,

Did you try with the code for RS485 slave implementation on LPC controller? CAn you please share the same? 

I want to impleement RS485 slave behavior for lpc1857 controller.

Thanks & Regards,

Shruti

0 Kudos
Reply

4,365 Views
mohammadfaizan
Contributor III

Hi Shruti,

RS485 interfacing is just a hardware medium where you can connect a

multiple slaves, along with you need to define a communication protocol in

your source, Master and slave arrangement, where master initiates the

communication. If you have more than one slave on your physical end, you

must assign them a unique address . In my case, I had used the DIP switch.

You refer lpc407x_8x_177x_8x - Uart_Rs485Slave example it will help you a

lot.

On Tue, Feb 26, 2019 at 2:18 PM shruti.patel@in.atlascopco.com <

0 Kudos
Reply

4,365 Views
shruti_patel
Contributor I

Thank you Mahammad Faizan,

Can you please share a link for the mentions " lpc407x_8x_177x_8x -  Uart_Rs485Slave example" ?

It would be helpful....

Also, I have code for lpc1857 master but I want to create a slave on lpc1857 controller which would get the master command from Arduino board. Is there any specific key points which I can refer to change the master implementation in to slave?

Thanks & Regards,

Shruti P

0 Kudos
Reply

4,365 Views
mohammadfaizan
Contributor III

Hi Shruti,

In master/slave implementation, master initiate the communication by

sending the address of slave, (in case if you have a multiple channel and

multiple slaves on each channel)

if((ADDRESS >= 01)&&(ADDRESS <= 06))

{

UART0Tx(ADDRESS);

}

else if// to second channel

This is for master, after that master will transmit the actual data

frame,

Then you need to implement the function Rx at the slave side, all slave

received the address and then data frame but only slave having that address

will respond to a data frame.

Assign a unique address

#define slave_addr xx in your slave code or you can use a DIP Switch.

Refer the UARTRS485Slave example.

Refer this link for the master code,

https://github.com/Protoneer/RS485-Arduino-Library/blob/master/RS485.cpp

On Thu, Feb 28, 2019 at 9:06 PM shruti.patel@in.atlascopco.com <

0 Kudos
Reply

4,365 Views
shruti_patel
Contributor I

Thank you Mohammad Faizan,

When I open the IAR code attached in .rar file i am getting few errors and not able to run the code. Please find attached image for reference and kindly guide.

Thanks with Regards,

Shruti

0 Kudos
Reply

4,365 Views
mohammadfaizan
Contributor III

It's a keil project file. It may not work with IAR Work bench, better you

create new project in IAR and add those file into your IAR project.

On Fri, Mar 1, 2019, 9:44 PM shruti.patel@in.atlascopco.com <

0 Kudos
Reply

4,364 Views
chrispflieger
Contributor IV

The tricky part of RS-485 is knowing when all the data is transmitted out completely so you can turn off the transmitter and turn on the receiver. I'm not familiar with that chip, but some LPC's have TX IDLE bit (with IRQ) and others have a TX complete bit that gets set when the buffer is empty, but it's still transmitting. The latter requires a delay of one byte time before turning off the transmitter.

Also, you might want to consider using nine bit data, and setting the ninth bit on he first byte and using an address for that data byte.

4,364 Views
mohammadfaizan
Contributor III

Thanks Chris,

Now code which I had tested is simple UART, no addressing,  simply sending and receiving a data to and from hyper-terminal. I have to implement it as a half duplex, master will receive only an acknowledgement from slaves, whether the data is received or not.  I don't now how to manage all UART at the same time,  24 slaves and their addressing by a protocol.

It might be more helpful if you share any demo code library for LPC23xx.

thanks & regards

Mohammad Faizan

0 Kudos
Reply

4,364 Views
chrispflieger
Contributor IV

I don't have any demo code, but pretty much any RS-485 communications is going to be the same no matter what processor.

Typically, you enable the transmitter and disable the receiver (you can physically tie those lines together) when transmitting, then quickly turn off the transmitter and enable the receiver to hear the response.

That MCU has an older UART design and I don't have code for those. I do remember it's tricky to figure out when the UART is done transmitting.

Write a module to get it working with one UART, then just create duplicates for each of the UARTs.

Good Luck.

0 Kudos
Reply