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.

Master/slave 8051 network through serial port

Status
Not open for further replies.

sunish

Advanced Member level 4
Joined
Sep 4, 2005
Messages
117
Helped
10
Reputation
20
Reaction score
2
Trophy points
1,298
Activity points
2,360
hai all
i would like to connect 8 nos of 8051's to the computer
all of these are located at a distance of 100 meters
i would like to make a network of them
all of these controllers are connected to other devices through serial port
i want the data out of these devices to be shown on the hyperterminal of the computer
i thought i will use rs 485
but the one com port i am having with my controllers are used by the devices connected to it.what is the possible solution for this?


sun
 

Re: master/slave 8051

You can implement a second uart on the 8051 by "bit banging" some digital i/o's. You will need to write a program to simulate these uart pins using digital i/o's:
* Tx
* Rx
* TxEnable
* RxEnable (optional)
 


Re: master/slave 8051

hai
that means i can make the 8051 processor with two serial ports.
which 8051 processor i can use?
de anybody has any sample codes which will receive data on one port and send it through another?
can i use rs485 to one of the serial port?

thanking you


sun
 

Re: master/slave 8051

You can program/make any 8051-derivative to have at least two serial ports: one, standard, based on the hardware UART and another one, software based, which will use INT0 or INT1 as RX and any PX.X as TX ..
Try to combine codes from both examples - that one from previous post and the following ..https://www.pjrc.com/tech/8051/uartintr.html ..

Any AT89S51/52/53 or 87C52 etc. etc. should work fine ..

Regards,
IanP
 

Re: master/slave 8051

hai
that means i can make the 8051 processor with two serial ports.
which 8051 processor i can use?
de anybody has any sample codes which will receive data on one port and send it through another?
can i use rs485 to one of the serial port?

You need only one Serial Port for each 8051.

Configure you network as a MULTIPOINT Application, refer to National Semiconductor AP-759 : **broken link removed**
 

Re: master/slave 8051

sunish mail me :
i need a hardware design and some sample codes in 485 communication

RS485 bus Multipoint serial communication system diagram:

21_1162697116.gif


RS485 bus is a bidirectional bus (half duplex), use P1.7 to control bus direction, P1.7=0 ->75176 receive data, P1.7=1 ->75176 transmit data.
At stand by condition, set Master ready to transmit data (P1.7=1) and set all slave hearing the bus (P1.7=0).

I'll write driver routine soon
 
Re: master/slave 8051

I sent sample program for previous posted message, one for Master Device and one for Slave Device.

It is written for Keil C51.

Master
Code:
#include <reg51.h>

sbit Direction = P1^7;

void initialize(void) {
     SCON = 0xF0;  // 9 bit multipoint mode UART 
     TMOD = 0x30;  // Timer 1 = baudrate generator
     TH1  = 0xFD;  // 9600 baud
     TR1  = 1;     // start baudrate generator
}

void SerialOut(char c){
     while (!TI) ; // wait until ready to sent char
	 TI   = 0;     // reset flag
	 SBUF = c;     // get a char
}

char SerialIn(void){
unsigned int wait;
     wait = 0xFFFF;               // waiting loop constant
     while (!RI && wait) wait--;  // wait until char arrive or time out
	 RI = 0;                      // reset flag
	 return ( wait ? SBUF : 0 );  // if time out return 0
}

void main(void){
char c,i,j;
char answer[11];
     initialize();
     TB8 = 1;                 // 9th bit = 1

     // scanning port 0 .. 7
     i   = 0;
   	 while (1){
           Direction = 1;     // transmit
           SerialOut(i);      // invoke slave #i
           i = i++ & 0x07;    // 0 .. 7
           Direction = 0;     // receiver

           j = 0;
           do {
             c = SerialIn();
			 answer[j++] = c;
  		   } while (!c);
           
		   if (answer[0]==0) {
		   // slave #i not installed or
		   // slave #i does not response
		   }
		   else {
		   // do some thing
		   };
	 };
}


Slave
Code:
#include <reg51.h>

sbit Direction = P1^7;

void initialize(void) {
   Direction = 0; // receiver
   SCON = 0xF0;   // 9 bit multipoint mode UART  
   TMOD = 0x30;   // Timer 1 = baudrate generator
   TH1  = 0xFD;   // 9600 baud
   TR1  = 1;      // start baudrate generator
   ES   = 1;      // enable UART interrupt
   EA   = 1;      // enable interrupt system 
}

void SerialOut(char c){
     while (!TI) ; // wait until ready to sent char
	 TI   = 0;     // reset flag
	 SBUF = c;     // sent character
}

void uart_isr(void) interrupt 4 {  // 4 = serial interrupt
char *slave = "Slave #";
   if (TI) TI=0;      // fail safe
   else {
         RI = 0;                            // reset receiver flag 
         if (SBUF==(P1 & 0x07)) {
             ES = 0;                        // disable UART interrupt
             Direction = 1;                 // transmitter
             while (*slave) 
			       SerialOut(*slave++);
             SerialOut(0x30 + (P1 & 0x07)); // sent slave#
             SerialOut(0x00);               // sent null char
             Direction = 0;                 // receiver
             ES = 1;                        // enable UART interrupt
            }
         }
}

void main(void){
     initialize();
	 while (1){
	 // do nothing
	 // but report slave # when called by master
	 };
}

Added after 47 minutes:

sunish mail me:
i think i have to cofigure the software uart to receive the data from the external device and will use the hardware uart for rs 485 tx/rx.
this is because we only have to receive with the second uart so that we will use the software uart for this application.
and the rs 485 transmission is the main.

I don't think so, you can connect you system to PC without SoftUART, like this:
58_1162722552.gif
 

    sunish

    Points: 2
    Helpful Answer Positive Rating
Re: master/slave 8051

dear budhy
thank you for the post.
here the main problem is that master does not have any hold on the data send to the computer.how many slaves i can connect like this?


thanking you


sun
 

Re: master/slave 8051

here the main problem is that master does not have any hold on the data send to the computer.
I am not really understand what do you mean.

with little modification as below, PC can hear the datas send from slaves.

Master
Code:
void main(void){
char c,i,j;
char answer[11];
     initialize();
     TB8 = 1;                 // 9th bit = 1

     // scanning port 0 .. 7
     i   = 0;
   	 while (1){
           Direction = 1;     // transmit
           SerialOut(i);      // invoke slave #i
           i = i++ & 0x07;    // 0 .. 7
           Direction = 0;     // receiver
          [b] SCON = 0x53;       // 8 bit normal UART  [/b]

           j = 0;
           do {
             c = SerialIn();
			 answer[j++] = c;
  		   } while (!c);
           [b]SCON = 0xF0;   // 9 bit multipoint mode UART  [/b]
           
		   if (answer[0]==0) {
		   // slave #i not installed or
		   // slave #i does not response
		   }
		   else {
		   // do some thing
		   };
	 };
}

Slave
Code:
void uart_isr(void) interrupt 4 {  // 4 = serial interrupt
char *slave = "Slave #";
   if (TI) TI=0;      // fail safe
   else {
         RI = 0;                            // reset receiver flag 
         if (SBUF==(P1 & 0x07)) {
             ES = 0;                        // disable UART interrupt
             Direction = 1;                 // transmitter
             [b]SCON = 0x53;                   // 8 bit normal UART  [/b]
             while (*slave) 
			       SerialOut(*slave++);
             SerialOut(0x30 + (P1 & 0x07)); // sent slave#
             SerialOut(0x00);               // sent null char
             [b]SCON = 0xF0;                   // 9 bit multipoint mode UART  [/b]
             Direction = 0;                 // receiver
             ES = 1;                        // enable UART interrupt
            }
         }
}

how many slaves i can connect like this?
depend on the RS485 chip, at least you can connect 32 node
 

Re: master/slave 8051

y can conect up to xxx notes. If you using a repeter( because rs485 permit maximum 32 note.It depend on Rt resistor tranmit line and reflection of signal.)
 

Re: master/slave 8051

pronab mail me:
i'm using ur given code in c language for connecting 8051 micro controller in one master and one slave basis, but I'm not getting any response, hard ware is ok,as far i think.please help
pls help,i can't understand what is the problem is going on.My project has been struck condition.

Would you like to attach your schematic file and your whole source code you used?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top