CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RS-232 works fine at 9600 and it fails at 19200

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MAC_08
Guest







RS-232 works fine at 9600 and it fails at 19200
PostPosted: Tue Apr 14, 2009 11:45 am     Reply with quote

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








PostPosted: Tue Apr 14, 2009 11:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 14, 2009 11:52 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Tue Apr 14, 2009 12:58 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 15, 2009 2:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 15, 2009 2:49 am     Reply with quote

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)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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