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

Baud Rate Issues

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



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

Baud Rate Issues
PostPosted: Mon Jan 15, 2007 5:02 pm     Reply with quote

Newbie with CCS so bare with me....

I'm running a 18F2580 at 20 Mhz. I have two jumpers to set the baud rate via A0 & A1. I'm using

My Program initially sets the bausd rate via Use 232 like this....

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,UART1,errors,stream=COMM_1,enable=Pin_b1)

Then in my Main, before my loop I read the jumper settings...

switch( input_a() & 3 )
{
case 0 : set_uart_speed(9600,COMM_1); break;
case 1 : set_uart_speed(19200,COMM_1); break;
case 2 : set_uart_speed(38400,COMM_1); break;
case 3 : set_uart_speed(57600,COMM_1); break;
}


Everything works for 9600 to 38400 but when I try to set it at 57600 I end up with 9600 again.

Do I need to add the BRGH1OK in the use RS232 parameters?

What am I doing wrong?

In PBPRO, is simply set the registers directly
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 10 ' 115200 Baud @ -1.36%
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 5:14 pm     Reply with quote

Okay, this is weird, but if I set my initial use RS232 to 57,600 then use set_uart_speed afterwards it works at all baud rates 9600 to 57600.

Why is that? Should I use the complete Use RS232 statement instead of just set_uart_speed?

Richard
Ttelmah
Guest







PostPosted: Tue Jan 16, 2007 5:54 am     Reply with quote

BRGH10K, won't help. This is a 'fix' for a fault on some chips, with using the BRGH register bit.
The problem though is tied to this register. The 'set_uart_speed' function, writes a suitable value into the basic baud rate generator register. The problem is that for 'fast' rates, the main setup function, knows to switch to using the higher rate setting, on the BRGH bit, but the set_uart_speed function, does not know to change this bit. By selecting 56K in the original setup, you force this bit to be set.
Now, some time ago on this forum, I think PCM Programmer posted a 'replacement' version of the set_uart_speed function, for older compiler versions that did not have this code. It might be worth finding this, and seeing if his version correctly handles this bit. Otherwise, the answer is to just change this one bit yourself, in the switch statement. Define the bit using #bit, and set it on/off as needed.

Best Wishes
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

PostPosted: Tue Jan 16, 2007 6:18 am     Reply with quote

Thanks for the reply. I kind of figured that was what was happening and when USE RS232 was used at 57600 the routines knew to use the high speed baud generator but not on set uart speed.

I will set it directly as you suggested. Leaving BRGH = 1 should be fine for all the speeds I'm running so I should just be to set that only once right above my switch statement.
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