Multiple Serial port 8051 - 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
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.
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
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
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.
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); } }
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
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".
ArunArun 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!
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 uarttxd_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!!
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?