Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to build master and 2 slaves with ATMEL AT89C52?

Status
Not open for further replies.

ar8051@yahoo.com

Newbie level 2
Joined
Oct 8, 2005
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,331
atmel 485

Hi all,

I am a newbie in microcontroller. Thank goodness I have found this forum.
I want to build a master and 2 slaves network with AT89C52.

What I have in mind is the following:
Master
--------
- I have 1 master with AT89C52 with 4x4 hex keypad attached plus
4 LEDs (first pair is for slave #1 - transmit and receive indicator, second pair
is for slave #2 - transmit and receive indicator)
- This master is connected to 2 slaves through RS-485 (so there
will be 2 RS-485 connectors on the master board)

Slaves
--------
- There will be 2 slaves (#1 and #2)
- Each slave is controlled by AT89C52
- Each slave has a RS-485 connector and 1 LED

What I want is:
- press keypad on master, let's say button #1 for slave #1, button #2 for slave
#2, then this press will send a bit 1/0 (toggle) to turn on/off the LEDs on the
slaves.
- when the master sends an input for a particular slave, the transmit LED will
light up.
- the bit will be sent through RS-485 to the corresponding slave (either #1 or
#2), the slave AT89C52 will receive the bit through RS-485, then the slave's
LED will light up (like saying "hey, I receive your command")
- after that, the corresponding slave will send an acknowledgement that
it has received the bit. It will send the ack via RS-485 back to master and
finally light up the receive indicator on master.

In short, master "talks" to slaves through RS-485 and slaves can "talk" back
to master through RS-485 as well. The LEDs are for indicators that bits are passed
around through RS-485 connectors.

With all the set up in my mind, I have questions:
- how to establish 2 RS-485 connectors on the master? schematic plus
the components please or even tutorial or hyperlinks.
I know that AT89C52 has only 1 UART (serial connection) -> do I need to
make 2?
- how to write the code so the RS-485 on the master can talk to RS-485 on
the slaves?
- do you think what I have in my mind is possible to implement or there might
be a problem?

Please give me some suggestions. I need help for this. Thank you for any
reply.
 

8051 sm2 rs485

- do you think what I have in my mind is possible to implement or there might
be a problem?
Absolutely, and will be a good way for you to learn about micros.


- This master is connected to 2 slaves through RS-485 (so there
will be 2 RS-485 connectors on the master board)
For RS485 you will only need 1 port on the master - you can daisy chain multiple slaves with RS485. However the software will be a bit more complicated because you have to address each slave differently. If you use RS232 you will need 2 ports on the master, but addressing is not required. There are some atmel devices with 2 uarts.

- how to establish 2 RS-485 connectors on the master? schematic plus
the components please or even tutorial or hyperlinks.
Google rs485 + schematic

www.avrfreaks.net is also a good forum
 

atemel master slave

Hi Sir,

thank you so much for the reply.

However, I am still confused with your explanation.
I know that AT89C51/52/55 has only 1 UART. I guess
I want to stay with 1 UART microcontroller.
So the master will have this 1 UART as RS-485.

And then, I need to connect the master to the slaves
with daisy chain? How this can be accomplished?

What I have pictured in my mind is the following:
Master (RS-485) <-> (RS-485) Slave #1 (RS-485) <-> Slave #2 (RS-485).

So it means, the first slave has to have 2 UARTs (one is
for connection to the master, second is for the connection
to slave #2)? But if I just want to have 1 UART per microcontroller
then how this can be accomplished?

I am not familiar with microcontroller networking technique.
So please give some guidance how to accomplish this. A schematic
would be nice. Besides, I need some code how to implement this
network. Anyone can help me for that?

Thank you in advance for any reply.
 

rs485 + slave + atmel

What I have pictured in my mind is the following:
Master (RS-485) <-> (RS-485) Slave #1 (RS-485) <-> Slave #2 (RS-485).
Yes this is ok



So it means, the first slave has to have 2 UARTs (one is
for connection to the master, second is for the connection
to slave #2)
No, you only need 1 uart with 2 connectors.

If you are new to micros then perhaps you should use RS422. RS485 uses the same 2 lines for transmit and receive, which means the RS485 chip has to be switched. RS422 uses 2 lines for transmit and 2 for receive, so it doesn't need switching. You only need 1 uart for RS485 or RS422.
In you application you can get away with RS232 with only 1 uart and 2 MAX232 chips. You will then have to OR the receive signal and join the transmit signals.
In other words, OR the 2 receive signals, so that if either slaves send a signal it will be read. Note that if they both send signals at the same time you will have a collision which wont cause damage but will not be readable. When the master transmits it can transmit to both chips or you can select the correct max232 chip and transmit to only 1 chip.

I assume you know that for RS232, RS422 and RS485 you need special driver chips.

I don't have a schematic or code handy, but maybe someone else does.
 

master atmel and slave

Hi all,
I don't think there's any complication here. You only have to use UART of AT89C in multimicrocontroller communication mode (9 data bits modes with SM2 = 1). In this mode, Master's RxD will be connected to TxD of two Slaves and Master's TxD to RxD of two Slaves respectively. Master will send address first to select one Salve (address byte has 9th bit = 1) and then data transfer will happen between Master and selected Slave. More information you can get in "Msc51 User's Manual" (chapter 3, as i remember), look for "Multimicroprocessor communication":
https://www.intel.com/design/mcs51/manuals/272383.htm
If there something you do not understand, feel free to let me know, guy.
Regards,
Kieennx.
 

kieennx said:
You only have to use UART of AT89C in multimicrocontroller communication mode (9 data bits modes with SM2 = 1). In this mode, Master's RxD will be connected to TxD of two Slaves and Master's TxD to RxD of two Slaves respectively.
This is ok for short distances. RS232 is ok up to about 50m at low baud rates and RS422/RS455 is ok up to 1 km.

Master's RxD will be connected to TxD of two Slaves
I dont like the idea of connecting 2 outputs together, unless they are open collector ?
 

I have constructed some kind of computer network (at least that was how it looked like from the custemer point of view). On the basics the Intel 8051 microcontroller was, an ancient version of the 8052 with this master - slave setup, and RS232. I have used coaxial cable and some line drivers to send signals over coaxial cable with a total length about 100 m. Of course I have used only half-duplex communication, which means only one can send at any time, either the master, or one of the slave (I had 20 slaves). In the master-slave configuration allways the master is who coordinates (that's why it is called the master). That is, the master will allways send a message to a slave, and the slave might send a message back. The addressing is according to kieennx, you should use the multimicrocontroller communication setup. That means, the 8052 slave will generate a serial interrupt only and only if, the received address is equal to its default address. By setting two different addresses for your slaves, you can access separately your slaves having a common RS232 bus. However for longer distances you might need line drivers and terminator resistors at the end of both end to avoid reflections on the line.
In such a configuration you can do anything. For instance in my project, the slaves were equipped with keypad and monitor (video controller with character generator). At regular intervals the master - being placed in a PC computer as an extension card - send a question to the slave. The slave has given different responses, either requesting new question with answers (numbered from 1 to 4) to place on the monitor, or sending the prevoius answer as a number (when the custmer prssed one of the key). As you see a simple protocall was also defined.

If you choose to have the above configuration, you should have in mind who controlls the line in half - duplex mode. Or even in case of full duplex you should be allways carefull that the slave which is not address have its TX driver set in 3-state.
 

I assumed that Kieennx meant connecting the uarts together with no drivers ???
 

I meant the following:
You only have to use UART of AT89C in multimicrocontroller communication mode (9 data bits modes with SM2 = 1). In this mode, Master's RxD will be connected to TxD of two Slaves and Master's TxD to RxD of two Slaves respectively.
Of course, you need here either buffers with 3-state or open-collector (open-drain). I do not remember whether the serial lines RX, TX are open collector or not for the 8052. If not then a buffer need to be inserted between the TX of the master and the RXs of the slaves. But in principle I should say the TX of the master is connected to RXs of the slaves, while the TXs of the slaves are connected together and to the RX of the master. In that case all TXs are in 3-state (high Z) or pulled-up (when open collectors are used). As I emphasized, the MASTER controles the "bus", that is he should talk always first, and ONLY the addressed SLAVE should answer. IN my project was a slitly complicated, because all TXs and RXs were connected together on the coaxial cable. In that manner, the master - after sending its message set its TXs in Z-high, and the ADDRESSED slave responded back after a while. The slave then sets its TX back to Z-high.
 

Belsugului said:
Of course, you need here either buffers with 3-state or open-collector (open-drain). I do not remember whether the serial lines RX, TX are open collector or not for the 8052. If not then a buffer need to be inserted between the TX of the master and the RXs of the slaves. But in principle I should say the TX of the master is connected to RXs of the slaves, while the TXs of the slaves are connected together and to the RX of the master. In that case all TXs are in 3-state (high Z) or pulled-up (when open collectors are used). As I emphasized, the MASTER controles the "bus", that is he should talk always first, and ONLY the addressed SLAVE should answer. IN my project was a slitly complicated, because all TXs and RXs were connected together on the coaxial cable. In that manner, the master - after sending its message set its TXs in Z-high, and the ADDRESSED slave responded back after a while. The slave then sets its TX back to Z-high.

Ok, that is similar to RS422. The difference is that RS422 uses differential voltage and RS232 uses absolute voltages, which means that RS422 works at much greater distances.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top