|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Using software UART with 19200 baud rate |
Posted: Thu Feb 27, 2014 12:56 am |
|
|
Hi,
I have managed to setup a software uart port on the 18F2620 that uses the b0 pin as receive and b1 as transmit. The pic can receive data very well at 9600 baud, but at 19200 it does not work properly.
Can the software UART work on 19200 baud ?? or is it best suited for 9600 baud.
My code to test the system is as follows.
Code: | #include <18F2620.h>
#use delay(clock=8000000)
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOMCLR,NOCPD,BROWNOUT,NOLVP,NOPBADEN,NOIESO,NOFCMEN
#use rs232(baud=9600,xmit=pin_b1, rcv=pin_b0,parity=n,bits=8,errors,stream=ANYBUS)
#zero_ram
void initialise(){
setup_oscillator(OSC_INTRC|OSC_8MHZ);
setup_adc(ADC_OFF);
set_tris_a(0b11111111);
set_tris_b(0b11111001);
set_tris_c(0b10111011);
set_tris_e(0b1111);
}
void main(){
initialise();
do
{
fputc(fgetc(ANYBUS)+1,ANYBUS);
}while(TRUE);
} |
Please help..
thanks
a |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9236 Location: Greensville,Ontario
|
|
Posted: Thu Feb 27, 2014 7:28 am |
|
|
I'd use the PLL and get the PIC running faster ! A software UART needs a lot of CPU cycles to execute.
Right now your PIC is running at 8MHz, you can get 32MHz by using the PLL, effectively you'll have 4X the CPU cycles.
Also the internal oscillator may not be 'bang on' calibrated. It's always best to use an external crystal/cap as the primary oscillator.Cost 50 cents more BUT far more accurate.
If you need 2 'fast' UARTS I suggest using a PIC with 2 hardware UARTs.There's probably a drop in 'pin for pin' replacement.I've used the 46k22 for 2-3 years, 2 UARTs at 115k200, no data loss problems.
recode,test, try, report back with what happens
hth
jay |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Feb 27, 2014 8:48 am |
|
|
Code: | fputc(fgetc(ANYBUS)+1,ANYBUS); | You will have problems no matter what baudrate or clock frequency you choose.
The Software UART can not receive data while it is transmitting, and same the other way around. It takes just as long to send a character as it takes to receive one. So, unless you are receive just 1 character at a time, you will loose data. That's why hardware UARTs have a buffer for multiple characters. |
|
|
mars79
Joined: 19 Jun 2013 Posts: 6 Location: Bulgaria, Plovdiv
|
|
Posted: Thu Feb 27, 2014 8:54 am |
|
|
Try to use an external oscillator. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Thu Feb 27, 2014 10:14 am |
|
|
Something else to keep in mind with a software uart - anything that interrupts the uart code will cause problems. In your test, you are not using interrupts, but if you are planning on using them in your project recognize that interrupts will scramble both transmitting and receiving if they go off during a character time.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
re |
Posted: Thu Feb 27, 2014 10:51 am |
|
|
thanks everyone for the help,
I think the dual uart mcu should be the best solution, but will using an ext interrupt on the receive pin improve matters?
@temtronic
i will try out the external crystal and pll first as you suggested...
thanks
a |
|
|
|
|
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
|