|
|
View previous topic :: View next topic |
Author |
Message |
andy_bot14
Joined: 28 Jan 2006 Posts: 1
|
How to test multiple software uart on only 1 PIC chip |
Posted: Sat Jan 28, 2006 1:35 am |
|
|
Dear all,
I have been trying to use multiple software UART on pic18f458 without success. Using 1 pic chip, I physically wired pin B0 to pin A0. Are there any way to test multiple software UART for 1 pic properly.
I appreciate any help.
Here is my code.
#include <18F458.h>
#device adc=8
#use delay(clock=40000000)
#fuses NOWDT,WDT128,H4, NOPROTECT, NOOSCSEN, BROWNOUT, BORV20, NOPUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOCPB, NOWRTC, NOEBTR, NOEBTRB
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stream=PC)
#use rs232(baud=9600,xmit=pin_a1,rcv=pin_a0,stream=com1)
#use rs232(baud=9600,invert,xmit=pin_b0,rcv=pin_b1,stream=com2)
unsigned char data;
void main()
{
fprintf(PC,"welcome \r\n");
while(1)
{
fprintf(com2,"C"); // try to send data to port A
delay_ms(50);
data = fgetc(com1); //try to get data from port B
fprintf(PC,"value is %c \r\n",data); //send data to pc's serial port
//fputc(ch[0],PC);
delay_ms(300);
}
}
Andy O |
|
|
King Virus
Joined: 02 Mar 2006 Posts: 14 Location: Italy
|
|
Posted: Sun Mar 05, 2006 3:57 am |
|
|
Please post me a schematic of you wiring...
Do you use a MAX232 (Levelshifter) or someting else ?
If you don�t you have to invert the signal with some transistors... _________________ *** A good forum is a forum where people respect eatch other ! *** |
|
|
SteveL Guest
|
|
Posted: Sun Mar 05, 2006 5:29 am |
|
|
You have to understand the limitations of the software serial ports.
These are, as the name suggests, implemented by code that CCS generate for you, so you have to remember that while you're sending something from a software serial port, the PIC is tied up while it drives the output pin high and low with the appropriate timings. Only when it's finished sending does 'your' code continue.
Similarly when receiving, the PIC sits waiting for the character to arrive & samples the input pin with the appropriate timing only when this has fiished does 'your' code continue.
So, what you're doing in your code is transmitting from one software port, and then when this has finished you wait 50mS then start listening.
So the transmitted data has finished way before you start to listen for it.
What you're trying to do can be achieved, but you need to manually, rather than use the CCS code, handle the output pin driving and the input pin changing. This is usually done by setting up a timer interrupt at a fast enough rate for the serial baud rate and putting your software serial port code in the interrupt.
Steve. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|