Discussion in "8051 Discussion Forum" started by    say2paul    Aug 18, 2008.
Mon Aug 18 2008, 08:36 AM
#1
I know AT89C51 has only one serial port for data communication. But I need two serial ports in my project. Somehow I am able to connect two RS232 devices by placing a relay between the RX/TX port of AT89C51.

When I need to send data to Device1 I send a signal to the Relay from the same AT89C51 to activate the link between Device1 & AT89C51. Similarly I do the same in case of device2.

The circuit is working fine till now without any fault/error. But still I know this is not the right method. There must be some proper method of implementing the same.

Can anyone help me on how to implement it properly. Please only in C language
 balvant like this.
Mon Aug 18 2008, 01:39 PM
#2
Hi paul well you can startup with.... my software uart tutorial, you can have any number of uarts (depending on GPIOs available) on a normal 8051
Code is in ASM, but i have given information so as to use the same in C programs. Just go through it.

All you need to do create an asm file copy paste the APIs in it, add the file in your source group, and use the function as explained in tutorial in your c File.
 say2paul like this.
Mon Aug 18 2008, 03:03 PM
#3

Hi Paul, hows your embedded training going ?

there are 3 possible solutions for your problem, i guess.

first: select a Micro that has 2 Serial ports

second: make a software UART/s as ajay already suggested on any of I/O

third (my way of doing it!): connect the Master's Tx to Slave1 and Slave2 's Rx directly,
choose same Baud rate for all the three devices. assign unique code/character to each of the slaves, so that when the Master puts out the Unique Code on the Bus, only the called-upon slave returns acknowledge/required data. this concept is similar to I2C protocol and would be interesting to work with, also with this approach you can have several slave devices and you are not limited only to 2 slaves



All the Best !

Arun
 say2paul like this.
Mon Aug 18 2008, 03:51 PM
#4



Hi Paul, hows your embedded training going ?

there are 3 possible solutions for your problem, i guess.

first: select a Micro that has 2 Serial ports

second: make a software UART/s as ajay already suggested on any of I/O

third (my way of doing it!): connect the Master's Tx to Slave1 and Slave2 's Rx directly,
choose same Baud rate for all the three devices. assign unique code/character to each of the slaves, so that when the Master puts out the Unique Code on the Bus, only the called-upon slave returns acknowledge/required data. this concept is similar to I2C protocol and would be interesting to work with, also with this approach you can have several slave devices and you are not limited only to 2 slaves



All the Best !

Arun

Arun Kumar V




Hi Arun,

Things are going smooth now

Thanks for the three solutions..

I think the second solution i.e.e Ajay's solution is reliable. I will go with him
Mon Aug 18 2008, 03:56 PM
#5


Hi paul well you can startup with.... my software uart tutorial, you can have any number of uarts (depending on GPIOs available) on a normal 8051
Code is in ASM, but i have given information so as to use the same in C programs. Just go through it.

All you need to do create an asm file copy paste the APIs in it, add the file in your source group, and use the function as explained in tutorial in your c File.

Ajay



Hi Ajay,

This really seems to be very interesting.. I am desperate to implement the same in my code.

I'd gone through your tutorial but still unable to understand how to implement..

If possible, can you please upload a zip file including the C source/example in which 2 or more software UART are implemented.
Mon Aug 18 2008, 07:06 PM
#6
paul i am giving you steps, i hope you know how to create a project and add files

create a file softuart.asm and copy paste code from following link into it.
8051 Software Uart code
edit the following lines of code to set pins to use for software uart
txd_pin EQU     P3.1            ;Transmit on this pin
rxd_pin EQU     P3.0            ;Receive on this pin

create a file softuart.h and put the following code into it.

#ifndef __SOFTUART

#define __SOFTUART

void putc(unsigned char);
unsigned char getc(void);

#endif


now lets say your application filename is main.c so you can use software uart as follows:

#include "softuart.h"    //include the header file

//This is an echo program using software uart
void main(){
     unsigned char x;
     while(1){
          x = getc();
          putc(x);
    }
}
 say2paul like this.
Tue Aug 19 2008, 03:45 AM
#7


I think the second solution i.e.e Ajay's solution is reliable.



Hey Paul, ever heard of RS485 ( Successor to RS232 ) which uses simple twisted pair to connect multiprocessors in industries offering 90-100 Kilobaud rate (compared to 9.6 Kilobaud) covering distances of 1200-1400 meters.

Sofware UART doesn't offer Serial Interrupt, micro needs to wait to send or receive data

well, my solution maybe a bit OVERKILL for your application but surely not "unreliable".




Arun



 say2paul like this.
Tue Aug 19 2008, 04:55 AM
#8




I think the second solution i.e.e Ajay's solution is reliable.



Hey Paul, ever heard of RS485 ( Successor to RS232 ) which uses simple twisted pair to connect multiprocessors in industries offering 90-100 Kilobaud rate (compared to 9.6 Kilobaud) covering distances of 1200-1400 meters.

Sofware UART doesn't offer Serial Interrupt, micro needs to wait to send or receive data

well, my solution maybe a bit OVERKILL for your application but surely not "unreliable".




Arun




Arun Kumar V




Definitely Arun, your solution is also reliable.. Actually I was confused when you said I need to connect multiple devices at the same time to a single RX/TX port of 8051 microcontroller.

But now I think I got (a bit) what you want to say.. I am assuming it as following:

1. 8051 RX/TX is connected to GSM Modem.
2. Same 8051 RX/TX is connected to RFID (MIFARE) Card reader.
3. I need to use interrupt signal to activate the required device. Eg: If I need to communicate with GSM modem, I will send interrupt signal to GSM modem and similarly if I need to communicated with RFID reader, I will send interrupt signal to the RFID reader.

I don't know how will I send these interrupt signal. I think I need to interrupt DSR DTR RTS...

Can you please explain a bit!
Tue Aug 19 2008, 04:58 AM
#9


paul i am giving you steps, i hope you know how to create a project and add files

create a file softuart.asm and copy paste code from following link into it.
8051 Software Uart code
edit the following lines of code to set pins to use for software uart

txd_pin EQU     P3.1            ;Transmit on this pin
rxd_pin EQU     P3.0            ;Receive on this pin

create a file softuart.h and put the following code into it.

#ifndef __SOFTUART

#define __SOFTUART

void putc(unsigned char);
unsigned char getc(void);

#endif


now lets say your application filename is main.c so you can use software uart as follows:

#include "softuart.h"    //include the header file

//This is an echo program using software uart
void main(){
     unsigned char x;
     while(1){
          x = getc();
          putc(x);
    }
}

Ajay




Great Ajay.. Its very similar to what we do in C++

I didn't knew that, but thanks buddy. YOU ROCK!!
 balvant like this.
Tue Aug 19 2008, 07:00 PM
#10
Hey Arun...could you plz elaborate a bit on your method.It's interesting.

How exactly does the bus arbitration take place...how can a dumb slave be pre-empted while another is using the bus?Wouldn't this call for a 'smart' slave device?

Get Social

Information

Powered by e107 Forum System

Conversation

Fri Dec 04 2020, 11:19 AM
Smithbvi
only
Fri Dec 04 2020, 01:41 AM
Mindy
You stated it exceptionally well! essay writing services essay writing services
Thu Dec 03 2020, 10:09 PM
Errol
You made your stand very clearly!. essay writer service essay writer service
Thu Dec 03 2020, 09:30 PM
Thad
Wow a good deal of very good data! essay writer service essay writers
Thu Jun 11 2020, 06:27 AM
anudee
sir could please send the code for I2C and wifi interfacing with 8051

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 79, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123