Discussion in "8051 Discussion Forum" started by    say2paul    Aug 18, 2008.
Mon Aug 18 2008, 02:06 pm
#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, 07:09 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, 08:33 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, 09:21 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, 09:26 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.
Tue Aug 19 2008, 12:36 am
#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, 09:15 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, 10:25 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, 10:28 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.
Wed Aug 20 2008, 12:30 am
#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

Downloads

Comments

Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm