|
|
View previous topic :: View next topic |
Author |
Message |
MAC_08 Guest
|
RS-232 works fine at 9600 and it fails at 19200 |
Posted: Tue Apr 14, 2009 11:45 am |
|
|
Hello and thank you in advance for your help.
I'm using a 16F818 @ 4MHz to transmit some bytes to a PC. I'm using the instruction #use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B3) and I'm receiving all the bytes correctly in the PC. However, if I change the speed to 19200 I get some errors and some bytes are not transmitted. The line driver is a MAX232 with four 1uF capacitors.
The only interrupt is the Timer2 which is activated every 20ms to increase a counter.
Do you know what can be the problem? |
|
|
Guest
|
|
Posted: Tue Apr 14, 2009 11:49 am |
|
|
Hi,
Standard questions:
1. Compiler version??
2. Which PIC are you using??
3. What are your fuses??
4. Crystal, resonator, other??
5. Do you have a SMALL, complete program that demonstrates the problem??
Jeff |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 14, 2009 11:52 am |
|
|
The 16F818 does not have a hardware UART, so you are using a software
UART. If a software UART is interrupted during transmission or reception,
the bit timing will be disrupted. This is likely to be the cause of your
problem. To prevent this, add the parameter shown in bold below.
Quote: | #use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B3, DISABLE_INTS) |
This will cause your Timer interrupt to sometimes be delayed up to the
length of one character (10 bits) at 19200 baud, which is about 520 us. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Apr 14, 2009 12:58 pm |
|
|
This is HONESTLY not a snarky comment.
I learned fast about when the software UART is OK
If I don't care about RS-232 RECEIVE functions ( just gonna be a TALKER)
- I will use ANY pic and the software UART is fine. At pretty much any baud so long as INTS are OFF when sending.
BUT
If I need to RECEIVE characters - I just choose a pic with a HARDWARE USART.
At other than low bauds you are at risk of exactly what has happened. |
|
|
Marc
Joined: 11 Feb 2008 Posts: 5
|
|
Posted: Wed Apr 15, 2009 2:42 am |
|
|
Thank you all for the replies.
Here is more information:
PIC16F818 @ 4MHz
CCS Compiler 3.187 (IDE 3.42)
FUSES: XT WDT PROTECT PUT NOBROWNOUT MCLR NOLVP CPD NOWRT NODEBUG
The PIC only sends some bytes (7 or 5) depending on the key you press on the keyboard. The bytes are sent as simple bytes (%c) and not as Integers (%d) or strings...
Code Example:
Code: | switch(command)
{
case 'G':
printf("%c%c%c%c%c%c%c", ACK, command, make8(val_adc, 1), make8(val_adc, 0), NUL, NUL, EOT);
break;
case 'V':
printf("%c%c%c%c%c", ACK, command, VERSION[0], VERSION[1], EOT);
break;
} |
|
|
|
Marc
Joined: 11 Feb 2008 Posts: 5
|
|
Posted: Wed Apr 15, 2009 2:49 am |
|
|
I think that I have solved the issue!! Thanks PCM Programmer!!
This is what I have modified:
Code: |
#use rs232(baud=19200, xmit=PIN_B6, rcv=PIN_B7, BITS=8, PARITY=N, DISABLE_INTS)
|
|
|
|
|
|
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
|